diff --git a/noir/.rebuild_patterns b/noir/.rebuild_patterns index a793d8c4242b..741481ec0f2b 100644 --- a/noir/.rebuild_patterns +++ b/noir/.rebuild_patterns @@ -3,3 +3,5 @@ ^noir/scripts/bootstrap_packages.sh ^noir/scripts/test_js_packages.sh ^noir/scripts/test_native.sh +^noir/noir-repo-ref +^noir/noir-repo.patch diff --git a/noir/bootstrap.sh b/noir/bootstrap.sh index 12817257ba44..da1b8a070f15 100755 --- a/noir/bootstrap.sh +++ b/noir/bootstrap.sh @@ -31,19 +31,37 @@ function noir_sync { # Calculate the content hash for caching, taking into account that `noir-repo` # is not part of the `aztec-packages` repo itself, so the `git ls-tree` used # by `cache_content_hash` would not take those files into account. +function noir_repo_content_hash { + echo $(REPO_PATH=./noir-repo AZTEC_CACHE_COMMIT=HEAD cache_content_hash $@) +} + +# Get the cache content hash. It should only be based on files committed to `aztec-packages` +# in order to be able to support using `AZTEC_CACHE_COMMIT` for historical queries. function noir_content_hash { - function noir_repo_content_hash { - echo $(REPO_PATH=./noir-repo cache_content_hash $@) - } - with_tests=${1:-0} + # Currently we don't make a distinction between test and non-test hash + tests=${1:-0} + + # If there are changes in the noir-repo which aren't just due to the patch applied to it, + # then just disable the cache, unless the noir-repo is in an evolving feature branch. noir_hash=$(cache_content_hash .rebuild_patterns) - noir_repo_hash=$(noir_repo_content_hash .noir-repo.rebuild_patterns) - if [ "$with_tests" == "1" ]; then - noir_repo_hash_tests=$(noir_repo_content_hash .noir-repo.rebuild_patterns_tests) + + if [ "${AZTEC_CACHE_COMMIT:-HEAD}" != "HEAD" ]; then + # Ignore the current content of noir-repo, it doesn't support history anyway. + echo $noir_hash else - noir_repo_hash_tests="" + cache_mode=$(scripts/sync.sh cache-mode) + case "$cache_mode" in + "noir") + echo $noir_hash + ;; + "noir-repo") + echo $(hash_str $noir_hash $(noir_repo_content_hash .noir-repo.rebuild_patterns .noir-repo.rebuild_patterns_tests)) + ;; + *) + echo $cache_mode + ;; + esac fi - echo $(hash_str $noir_hash $noir_repo_hash $noir_repo_hash_tests) } # Builds nargo, acvm and profiler binaries. diff --git a/noir/scripts/sync.sh b/noir/scripts/sync.sh index 00b265290634..c6117e706c45 100755 --- a/noir/scripts/sync.sh +++ b/noir/scripts/sync.sh @@ -340,6 +340,26 @@ function make_patch { fi } +# Decide what kind of caching we should do. +function cache_mode { + if has_uncommitted_changes; then + # Same magic word as the ci3 scripts like `cache_content_hash` use. + echo "disabled-cache" + elif is_on_branch; then + # If we're on a branch (not a tag or a commit) then we can only cache + # based on the evolving content of the noir-repo itself. + echo "noir-repo" + elif is_last_commit_patch; then + # If we're on a detached head and the last commit is the patch, + # then we can use the noir-repo-ref and the patch file as cache key. + echo "noir" + else + # Otherwise we're on a tag and added some extra commits which are + # not part of a patch yet, so we can't use the cache. + echo "disabled-cache" + fi +} + # Show debug information function info { function pad { @@ -368,6 +388,7 @@ function info { echo_info "Has fixup and patch" $(yesno has_fixup_and_patch) echo_info "Has uncommitted changes" $(yesno has_uncommitted_changes) echo_info "Latest nightly" $(latest_nightly) + echo_info "Cache mode" $(cache_mode) } cmd=${1:-} @@ -386,6 +407,9 @@ case "$cmd" in "needs-patch") [ -d noir-repo ] && [ -d noir-repo/.git ] && needs_patch && exit 0 || exit 1 ;; + "cache-mode") + echo $(cache_mode) + ;; "latest-nightly") echo $(latest_nightly) ;;