Skip to content

Commit 29a1322

Browse files
committed
Add patch cache to github-apply-patch
1 parent 5f832a7 commit 29a1322

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ __pycache__/
55
build*.log
66
*.pb
77
*.zip
8+
9+
patch_cache/

ML-Frameworks/pytorch-aarch64/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Note: if the environment variable `GITHUB_TOKEN` is set then the build will
5858
attemmpt to use `GITHUB_TOKEN` for authenticated access when downloading WIP patches.
5959
This can avoid issues with rate-limiting on annonymous access.
6060

61+
Note: GitHub patches are cached in `utils/patch_cache` to save network
62+
traffic. This also allows you to use local patches that are not yet upstream by
63+
adding your patch to `utils/patch_cache` with the name
64+
`<your commit hash>.patch`. Then use `github-apply-patch` as usual in
65+
`get-source.sh`.
66+
6167
### Flags useful for development
6268
- `--use-existing-sources` skips `get-source.sh` and just builds
6369
- `--force` overwrites sources

ML-Frameworks/tensorflow-aarch64/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Note: if the environment variable `GITHUB_TOKEN` is set then the build will
5858
attemmpt to use `GITHUB_TOKEN` for authenticated access when downloading WIP patches.
5959
This can avoid issues with rate-limiting on annonymous access.
6060

61+
Note: GitHub patches are cached in `utils/patch_cache` to save network
62+
traffic. This also allows you to use local patches that are not yet upstream by
63+
adding your patch to `utils/patch_cache` with the name
64+
`<your commit hash>.patch`. Then use `github-apply-patch` as usual in
65+
`get-source.sh`.
66+
6167
## Motivation
6268
TensorFlow + oneDNN + ComputeLibrary is a deep stack. The purpose of
6369
`tensorflow-aarch64` is to let us see the future of that stack, so that we can:

ML-Frameworks/utils/git-utils.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
# limitations under the License.
1818
# *******************************************************************************
1919

20+
# Define patch cache directory as global variable, set to be in this directory,
21+
# shared by this Tool-Solutions. Collisions are almost impossible, even between
22+
# projects
23+
patch_cache_dir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/patch_cache"
24+
mkdir -p $patch_cache_dir
25+
export patch_cache_dir
26+
2027
function git-shallow-clone {
2128
(
2229
local repo_name=$(basename "$1" .git)
@@ -40,20 +47,21 @@ function apply-github-patch {
4047
# To use an API token, which may avoid rate limits, set the environment variable GITHUB_TOKEN
4148

4249
set -u
50+
patch_file="$patch_cache_dir/$2.patch"
51+
if [ ! -f "$patch_file" ]; then
52+
local github_api_url='https://api.github.com/repos'
53+
local github_url='https://github.com'
4354

44-
local github_api_url='https://api.github.com/repos'
45-
local github_url='https://github.com'
46-
47-
# Download the .patch file.
48-
if [[ "${GITHUB_TOKEN+x}" ]]; then
49-
curl --silent -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.patch" -L $github_api_url/$1/commits/$2 -o $2.patch
50-
else
51-
curl --silent -L $github_url/$1/commit/$2.patch -o $2.patch
55+
# Download the .patch file.
56+
if [[ "${GITHUB_TOKEN+x}" ]]; then
57+
curl --silent -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.patch" -L $github_api_url/$1/commits/$2 -o "$patch_file"
58+
else
59+
curl --silent -L $github_url/$1/commit/$2.patch -o "$patch_file"
60+
fi
5261
fi
5362

54-
# Apply the patch and tidy up.
55-
patch -p1 < $2.patch
56-
rm $2.patch
63+
# Apply the patch
64+
patch -p1 < "$patch_file"
5765
return 0
5866
}
5967

0 commit comments

Comments
 (0)