From 5c5f9bc87c0a57472ed9db8d2a1c0c637181a4ee Mon Sep 17 00:00:00 2001 From: Christoph Siedentop Date: Thu, 11 Oct 2018 17:20:44 -0400 Subject: [PATCH 01/20] Git_repository: WIP: cache git repositories using 'git worktree' Inspired by the following pull request and done in collaboration with @aehlig (Klaus Aehlig) at the Bazel Hackathon 2018. https://github.com/bazelbuild/bazel/pull/5928 Lots of open issues remaining: * Unit tests needs to be adapted to the fact that there is now a cache. * Klaus would like it to be optional only (I agree). * 'git worktree add ...' does not work on second run. --> tests failing because of that. --- tools/build_defs/repo/git.bzl | 50 ++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index c83141af345e50..5347c2f8de69b8 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -15,21 +15,37 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "workspace_and_buildfile") +def _hash(ctx, value): + """Hash a value... TODO needs implementation""" + bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" + key = ctx.execute([ + bash_exe, + "-c", + "(echo '{value}' | shasum)".format(value=value), + ]).stdout + key = key.split(sep=' ')[0] + return key + def _clone_or_update(ctx): if ((not ctx.attr.tag and not ctx.attr.commit and not ctx.attr.branch) or (ctx.attr.tag and ctx.attr.commit) or (ctx.attr.tag and ctx.attr.branch) or (ctx.attr.commit and ctx.attr.branch)): fail("Exactly one of commit, tag, or branch must be provided") + remote_name = _hash(ctx, ctx.attr.remote) shallow = "" if ctx.attr.commit: ref = ctx.attr.commit + #local_ref needs to be unique among _all_ repos in the git-cache. + local_ref = ref elif ctx.attr.tag: ref = "tags/" + ctx.attr.tag - shallow = "--depth=1" + local_ref = remote_name + "_" + ctx.attr.tag + shallow = "--depth=1" else: ref = ctx.attr.branch - shallow = "--depth=1" + local_ref = remote_name + ref + shallow = "--depth=1" directory = str(ctx.path(".")) if ctx.attr.strip_prefix: directory = directory + "-tmp" @@ -48,24 +64,40 @@ def _clone_or_update(ctx): ctx.attr.strip_prefix if ctx.attr.strip_prefix else "None", )) bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" + git_cache = '/tmp/bazel_cache/git_cache' + + # Set-up git_cache git repository. + st = ctx.execute([bash_exe, "-c", """set -ex + mkdir -p '{git_cache}' + git -C '{git_cache}' init --bare + git -C '{git_cache}' remote add '{remote_name}' '{remote}' || : + git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || git -C '{git_cache}' fetch '{remote_name}' {ref} + """.format( + git_cache=git_cache, + remote_name=remote_name, + remote=ctx.attr.remote, + ref=ref, + shallow=shallow)], environment = ctx.os.environ) + if st.return_code: + fail("Error fetching {}:\n{}".format(ctx.name, st.stderr)) + st = ctx.execute([bash_exe, "-c", """ set -ex -( cd {working_dir} && if ! ( cd '{dir_link}' && [[ "$(git rev-parse --git-dir)" == '.git' ]] ) >/dev/null 2>&1; then rm -rf '{directory}' '{dir_link}' - git clone {shallow} '{remote}' '{directory}' || git clone '{remote}' '{directory}' fi - git -C '{directory}' reset --hard {ref} || \ - ((git -C '{directory}' fetch {shallow} origin {ref}:{ref} || \ - git -C '{directory}' fetch origin {ref}:{ref}) && git -C '{directory}' reset --hard {ref}) - git -C '{directory}' clean -xdf ) + git -C '{git_cache}' worktree prune + git -C '{git_cache}' worktree add --track -b '{local_ref}' '{directory} {ref} + #git -C '{git_cache}' worktree add '{directory}' {ref} || : + git -C '{directory}' reset --hard {ref} + git -C '{directory}' clean -ffdx """.format( working_dir = ctx.path(".").dirname, dir_link = ctx.path("."), directory = directory, - remote = ctx.attr.remote, ref = ref, shallow = shallow, + git_cache = git_cache, )], environment = ctx.os.environ) if st.return_code: From 72f53fa3ddd2db0c42dc7e63cf1362b448dccc6f Mon Sep 17 00:00:00 2001 From: Christoph Siedentop Date: Fri, 12 Oct 2018 11:57:17 -0400 Subject: [PATCH 02/20] Fixup: Replace tabs & left-over work --- .../bazel/skylark_git_repository_test.sh | 2 +- tools/build_defs/repo/git.bzl | 53 ++++++++++++------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 4fb422bc179d44..e894a078423f1b 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -598,7 +598,7 @@ EOF bazel fetch //planets:planet-info >& $TEST_log \ || echo "Expect run to fail." - expect_log "error cloning" + expect_log "Error fetching" } run_suite "skylark git_repository tests" diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 5347c2f8de69b8..030a19dd255e55 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -15,8 +15,15 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "workspace_and_buildfile") + +def _if_debug(cond, st, what="Action"): + "Print if 'cont'." + if cond: + print("{} returned {}\n{}\n----\n{}".format(what, st.return_code, st.stdout, st.stderr)) + def _hash(ctx, value): - """Hash a value... TODO needs implementation""" + """Hash a value... TODO needs a proper implementation. + """ bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" key = ctx.execute([ bash_exe, @@ -32,20 +39,16 @@ def _clone_or_update(ctx): (ctx.attr.tag and ctx.attr.branch) or (ctx.attr.commit and ctx.attr.branch)): fail("Exactly one of commit, tag, or branch must be provided") - remote_name = _hash(ctx, ctx.attr.remote) + remote_name = "remote_" + _hash(ctx, ctx.attr.remote) shallow = "" if ctx.attr.commit: ref = ctx.attr.commit - #local_ref needs to be unique among _all_ repos in the git-cache. - local_ref = ref elif ctx.attr.tag: ref = "tags/" + ctx.attr.tag - local_ref = remote_name + "_" + ctx.attr.tag - shallow = "--depth=1" + shallow = "--depth=1" else: ref = ctx.attr.branch - local_ref = remote_name + ref - shallow = "--depth=1" + shallow = "--depth=1" directory = str(ctx.path(".")) if ctx.attr.strip_prefix: directory = directory + "-tmp" @@ -69,37 +72,47 @@ def _clone_or_update(ctx): # Set-up git_cache git repository. st = ctx.execute([bash_exe, "-c", """set -ex mkdir -p '{git_cache}' - git -C '{git_cache}' init --bare - git -C '{git_cache}' remote add '{remote_name}' '{remote}' || : - git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || git -C '{git_cache}' fetch '{remote_name}' {ref} + git -C '{git_cache}' init --bare || : + """.format(git_cache=git_cache)], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Init') + if st.return_code: + fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) + + # 'remote add x' must be done only if x does not exist + st = ctx.execute([bash_exe, "-c", """set -ex + git -C '{git_cache}' remote add '{remote_name}' '{remote}' || \ + git -C '{git_cache}' remote set-url '{remote_name}' '{remote}' + git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || \ + git -C '{git_cache}' fetch '{remote_name}' {ref} || \ + git -C '{git_cache}' {shallow} fetch '{remote_name}' """.format( git_cache=git_cache, remote_name=remote_name, remote=ctx.attr.remote, ref=ref, shallow=shallow)], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Fetching') + if st.return_code: - fail("Error fetching {}:\n{}".format(ctx.name, st.stderr)) + fail("Error fetching {}:\n{}\n----\n{}".format(ctx.name, st.stdout, st.stderr)) st = ctx.execute([bash_exe, "-c", """ set -ex - if ! ( cd '{dir_link}' && [[ "$(git rev-parse --git-dir)" == '.git' ]] ) >/dev/null 2>&1; then - rm -rf '{directory}' '{dir_link}' - fi + rm -rf '{directory}' '{dir_link}' git -C '{git_cache}' worktree prune - git -C '{git_cache}' worktree add --track -b '{local_ref}' '{directory} {ref} - #git -C '{git_cache}' worktree add '{directory}' {ref} || : - git -C '{directory}' reset --hard {ref} - git -C '{directory}' clean -ffdx + git -C '{git_cache}' worktree add '{directory}' {ref} || : + #git -C '{directory}' reset --hard {ref} + #git -C '{directory}' clean -ffdx """.format( working_dir = ctx.path(".").dirname, dir_link = ctx.path("."), directory = directory, ref = ref, shallow = shallow, - git_cache = git_cache, + git_cache = git_cache, )], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') if st.return_code: fail("error cloning %s:\n%s" % (ctx.name, st.stderr)) From 329507873dd6ce52cf3f54d44fbbb1ffa6b52362 Mon Sep 17 00:00:00 2001 From: Christoph Siedentop Date: Mon, 12 Nov 2018 17:00:34 -0800 Subject: [PATCH 03/20] Fix error message --- tools/build_defs/repo/git.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 030a19dd255e55..907497a79e0997 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -114,7 +114,7 @@ set -ex _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') if st.return_code: - fail("error cloning %s:\n%s" % (ctx.name, st.stderr)) + fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) if ctx.attr.strip_prefix: dest_link = "{}/{}".format(directory, ctx.attr.strip_prefix) From cf9effbc4abd413c8e114e331f7604be0f2b1b57 Mon Sep 17 00:00:00 2001 From: globegitter Date: Tue, 18 Dec 2018 08:54:53 +0100 Subject: [PATCH 04/20] Some progress on caching git repos only when BAZEL_GIT_REPOSITORY_CACHE is set. --- tools/build_defs/repo/git.bzl | 140 +++++++++++++++++++++++----------- 1 file changed, 97 insertions(+), 43 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 17493457dcb580..37d216488a2492 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -33,6 +33,34 @@ def _hash(ctx, value): key = key.split(sep=' ')[0] return key +def _setup_cache(ctx, git_cache): + # Set-up git_cache git repository. + st = ctx.execute([bash_exe, "-c", """set -ex + mkdir -p '{git_cache}' + git -C '{git_cache}' init --bare || : + """.format(git_cache=git_cache)], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Init') + if st.return_code: + fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) + + # 'remote add x' must be done only if x does not exist + st = ctx.execute([bash_exe, "-c", """set -ex + git -C '{git_cache}' remote add '{remote_name}' '{remote}' || \ + git -C '{git_cache}' remote set-url '{remote_name}' '{remote}' + git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || \ + git -C '{git_cache}' fetch '{remote_name}' {ref} || \ + git -C '{git_cache}' {shallow} fetch '{remote_name}' + """.format( + git_cache=git_cache, + remote_name=remote_name, + remote=ctx.attr.remote, + ref=ref, + shallow=shallow)], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Fetching') + + if st.return_code: + fail("Error fetching {}:\n{}\n----\n{}".format(ctx.name, st.stdout, st.stderr)) + def _clone_or_update(ctx): if ((not ctx.attr.tag and not ctx.attr.commit and not ctx.attr.branch) or (ctx.attr.tag and ctx.attr.commit) or @@ -69,53 +97,79 @@ def _clone_or_update(ctx): )) bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" git_cache = '/tmp/bazel_cache/git_cache' + git_cache = ctx.os.environ.get("BAZEL_GIT_REPOSITORY_CACHE") + + if git_cache: + # Set-up git_cache git repository. + st = ctx.execute([bash_exe, "-c", """set -ex + mkdir -p '{git_cache}' + git -C '{git_cache}' init --bare || : + """.format(git_cache=git_cache)], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Init') + if st.return_code: + fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) + + # 'remote add x' must be done only if x does not exist + st = ctx.execute([bash_exe, "-c", """set -ex + git -C '{git_cache}' remote add '{remote_name}' '{remote}' || \ + git -C '{git_cache}' remote set-url '{remote_name}' '{remote}' + git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || \ + git -C '{git_cache}' fetch '{remote_name}' {ref} || \ + git -C '{git_cache}' {shallow} fetch '{remote_name}' + """.format( + git_cache=git_cache, + remote_name=remote_name, + remote=ctx.attr.remote, + ref=ref, + shallow=shallow)], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Fetching') + + if st.return_code: + fail("Error fetching {}:\n{}\n----\n{}".format(ctx.name, st.stdout, st.stderr)) - # Set-up git_cache git repository. - st = ctx.execute([bash_exe, "-c", """set -ex - mkdir -p '{git_cache}' - git -C '{git_cache}' init --bare || : - """.format(git_cache=git_cache)], environment = ctx.os.environ) - _if_debug(cond=ctx.attr.verbose, st=st, what='Init') - if st.return_code: - fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) + st = ctx.execute([bash_exe, "-c", """ + set -ex + rm -rf '{directory}' '{dir_link}' + git -C '{git_cache}' worktree prune + git -C '{git_cache}' worktree add '{directory}' {ref} || : + #git -C '{directory}' reset --hard {ref} + #git -C '{directory}' clean -ffdx + """.format( + working_dir = ctx.path(".").dirname, + dir_link = ctx.path("."), + directory = directory, + ref = ref, + shallow = shallow, + git_cache = git_cache, + )], environment = ctx.os.environ) - # 'remote add x' must be done only if x does not exist - st = ctx.execute([bash_exe, "-c", """set -ex - git -C '{git_cache}' remote add '{remote_name}' '{remote}' || \ - git -C '{git_cache}' remote set-url '{remote_name}' '{remote}' - git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || \ - git -C '{git_cache}' fetch '{remote_name}' {ref} || \ - git -C '{git_cache}' {shallow} fetch '{remote_name}' - """.format( - git_cache=git_cache, - remote_name=remote_name, - remote=ctx.attr.remote, - ref=ref, - shallow=shallow)], environment = ctx.os.environ) - _if_debug(cond=ctx.attr.verbose, st=st, what='Fetching') + _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') + if st.return_code: + fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) + else: + st = ctx.execute([bash_exe, "-c", """ + set -ex + ( cd {working_dir} && + if ! ( cd '{dir_link}' && [[ "$(git rev-parse --git-dir)" == '.git' ]] ) >/dev/null 2>&1; then + rm -rf '{directory}' '{dir_link}' + git clone {shallow} '{remote}' '{directory}' || git clone '{remote}' '{directory}' + fi + git -C '{directory}' reset --hard {ref} || \ + ((git -C '{directory}' fetch {shallow} origin {ref}:{ref} || \ + git -C '{directory}' fetch origin {ref}:{ref}) && git -C '{directory}' reset --hard {ref}) + git -C '{directory}' clean -xdf ) + """.format( + working_dir = ctx.path(".").dirname, + dir_link = ctx.path("."), + directory = directory, + remote = ctx.attr.remote, + ref = ref, + shallow = shallow, + )], environment = ctx.os.environ) - if st.return_code: - fail("Error fetching {}:\n{}\n----\n{}".format(ctx.name, st.stdout, st.stderr)) + if st.return_code: + fail("Error cloning %s:\n%s" % (ctx.name, st.stderr)) - st = ctx.execute([bash_exe, "-c", """ -set -ex - rm -rf '{directory}' '{dir_link}' - git -C '{git_cache}' worktree prune - git -C '{git_cache}' worktree add '{directory}' {ref} || : - #git -C '{directory}' reset --hard {ref} - #git -C '{directory}' clean -ffdx - """.format( - working_dir = ctx.path(".").dirname, - dir_link = ctx.path("."), - directory = directory, - ref = ref, - shallow = shallow, - git_cache = git_cache, - )], environment = ctx.os.environ) - - _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') - if st.return_code: - fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) if ctx.attr.strip_prefix: dest_link = "{}/{}".format(directory, ctx.attr.strip_prefix) From 3f0cabbcd953e99d4a6c55e43ae078a5939d941a Mon Sep 17 00:00:00 2001 From: globegitter Date: Wed, 13 Feb 2019 22:44:51 +0100 Subject: [PATCH 05/20] Further progress and fixes for git cache. --- tools/build_defs/repo/git.bzl | 108 +++++++++++++++------------------- 1 file changed, 48 insertions(+), 60 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 5aa41172b5884e..4355e7eb16add4 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -35,27 +35,52 @@ def _hash(ctx, value): def _setup_cache(ctx, git_cache): # Set-up git_cache git repository. + bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" st = ctx.execute([bash_exe, "-c", """set -ex - mkdir -p '{git_cache}' - git -C '{git_cache}' init --bare || : + mkdir -p {git_cache} + git -C {git_cache} init --bare || : """.format(git_cache=git_cache)], environment = ctx.os.environ) _if_debug(cond=ctx.attr.verbose, st=st, what='Init') if st.return_code: fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) +def _get_repository_from_cache(ctx, directory, ref, shallow, git_cache): + bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" + st = ctx.execute([bash_exe, "-c", """ + cd {working_dir} + set -ex + rm -rf '{directory}' '{dir_link}' + git -C {git_cache} worktree prune + git -C {git_cache} worktree add '{directory}' {ref} + #git -C '{directory}' reset --hard {ref} + #git -C '{directory}' clean -ffdx + """.format( + working_dir = ctx.path(".").dirname, + dir_link = ctx.path("."), + directory = directory, + ref = ref, + shallow = shallow, + git_cache = git_cache, + )], environment = ctx.os.environ) + _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') + + return st.return_code + +def _populate_cache(ctx, git_cache, remote_name, ref, shallow): # 'remote add x' must be done only if x does not exist + bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" st = ctx.execute([bash_exe, "-c", """set -ex - git -C '{git_cache}' remote add '{remote_name}' '{remote}' || \ - git -C '{git_cache}' remote set-url '{remote_name}' '{remote}' - git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || \ - git -C '{git_cache}' fetch '{remote_name}' {ref} || \ - git -C '{git_cache}' {shallow} fetch '{remote_name}' + git -C {git_cache} remote add '{remote_name}' '{remote}' || \ + git -C {git_cache} remote set-url '{remote_name}' '{remote}' + git -C {git_cache} fetch {shallow} '{remote_name}' {ref} || \ + git -C {git_cache} fetch '{remote_name}' {ref} || \ + git -C {git_cache} {shallow} fetch '{remote_name}' """.format( - git_cache=git_cache, - remote_name=remote_name, - remote=ctx.attr.remote, - ref=ref, - shallow=shallow)], environment = ctx.os.environ) + git_cache=git_cache, + remote_name=remote_name, + remote=ctx.attr.remote, + ref=ref, + shallow=shallow)], environment = ctx.os.environ) _if_debug(cond=ctx.attr.verbose, st=st, what='Fetching') if st.return_code: @@ -96,57 +121,19 @@ def _clone_or_update(ctx): ctx.attr.strip_prefix if ctx.attr.strip_prefix else "None", )) bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" - git_cache = '/tmp/bazel_cache/git_cache' + git_cache = '/tmp/bazel_cache/git_cachee' git_cache = ctx.os.environ.get("BAZEL_GIT_REPOSITORY_CACHE") if git_cache: - # Set-up git_cache git repository. - st = ctx.execute([bash_exe, "-c", """set -ex - mkdir -p '{git_cache}' - git -C '{git_cache}' init --bare || : - """.format(git_cache=git_cache)], environment = ctx.os.environ) - _if_debug(cond=ctx.attr.verbose, st=st, what='Init') - if st.return_code: - fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) - - # 'remote add x' must be done only if x does not exist - st = ctx.execute([bash_exe, "-c", """set -ex - git -C '{git_cache}' remote add '{remote_name}' '{remote}' || \ - git -C '{git_cache}' remote set-url '{remote_name}' '{remote}' - git -C '{git_cache}' fetch {shallow} '{remote_name}' {ref} || \ - git -C '{git_cache}' fetch '{remote_name}' {ref} || \ - git -C '{git_cache}' {shallow} fetch '{remote_name}' - """.format( - git_cache=git_cache, - remote_name=remote_name, - remote=ctx.attr.remote, - ref=ref, - shallow=shallow)], environment = ctx.os.environ) - _if_debug(cond=ctx.attr.verbose, st=st, what='Fetching') + _setup_cache(ctx, git_cache) + return_code = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) - if st.return_code: - fail("Error fetching {}:\n{}\n----\n{}".format(ctx.name, st.stdout, st.stderr)) + if return_code: + _populate_cache(ctx, git_cache, remote_name, ref, shallow) + return_code = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) - st = ctx.execute([bash_exe, "-c", """ - cd {working_dir} - set -ex - rm -rf '{directory}' '{dir_link}' - git -C '{git_cache}' worktree prune - git -C '{git_cache}' worktree add '{directory}' {ref} || : - #git -C '{directory}' reset --hard {ref} - #git -C '{directory}' clean -ffdx - """.format( - working_dir = ctx.path(".").dirname, - dir_link = ctx.path("."), - directory = directory, - ref = ref, - shallow = shallow, - git_cache = git_cache, - )], environment = ctx.os.environ) - - _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') - if st.return_code: - fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) + if return_code: + fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) else: st = ctx.execute([bash_exe, "-c", """ cd {working_dir} @@ -187,8 +174,9 @@ set -ex """.format( directory = ctx.path("."), )], environment = ctx.os.environ) - if st.return_code: - fail("error updating submodules %s:\n%s" % (ctx.name, st.stderr)) + + if st.return_code: + fail("error updating submodules %s:\n%s" % (ctx.name, st.stderr)) ctx.report_progress("Recording actual commit") From 135cffcfdc77e7b0a48dd6d1002451d60b8209e2 Mon Sep 17 00:00:00 2001 From: globegitter Date: Wed, 13 Feb 2019 23:34:04 +0100 Subject: [PATCH 06/20] Fix tests. --- src/test/shell/bazel/skylark_git_repository_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 0585d91689c7c3..45403dd0a75414 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -640,7 +640,7 @@ EOF bazel fetch //planets:planet-info >& $TEST_log \ || echo "Expect run to fail." - expect_log "Error fetching" + expect_log "Error cloning" } run_suite "skylark git_repository tests" From e2666dd2c68c6e4409c4ff956c4d0de5df722e9d Mon Sep 17 00:00:00 2001 From: globegitter Date: Wed, 13 Feb 2019 23:54:08 +0100 Subject: [PATCH 07/20] Add simple test. --- .../bazel/skylark_git_repository_test.sh | 20 +++++++++++++++++++ tools/build_defs/repo/git.bzl | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 45403dd0a75414..d56fd2e4913a41 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -83,6 +83,9 @@ function set_up() { tar zxf outer-planets-repo.tar.gz tar zxf refetch-repo.tar.gz + local cache_dir=/tmp/bazel_cache + rm -rf $cache_dir + # Fix environment variables for a hermetic use of git. export GIT_CONFIG_NOSYSTEM=1 export GIT_CONFIG_NOGLOBAL=1 @@ -158,6 +161,23 @@ EOF expect_log "Pluto is a dwarf planet" } +# This test: +# 1. Creates a git_repository rule with some commit hash +# 2. Make sure worksapce can be built and repository cache is updated +function test_git_repositry_cache_is_populated() { + local pluto_repo_dir=$TEST_TMPDIR/repos/pluto + local cache_dir=/tmp/bazel_cache + local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" + + + export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir + + do_git_repository_test $commit_hash + + cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" + assert_equals $commit_hash $cache_commit_hash +} + function test_git_repository() { do_git_repository_test "52f9a3f87a2dd17ae0e5847bbae9734f09354afd" } diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 4355e7eb16add4..ca425df53a772d 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -121,7 +121,6 @@ def _clone_or_update(ctx): ctx.attr.strip_prefix if ctx.attr.strip_prefix else "None", )) bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" - git_cache = '/tmp/bazel_cache/git_cachee' git_cache = ctx.os.environ.get("BAZEL_GIT_REPOSITORY_CACHE") if git_cache: From edc5a0acea90f5acba8be4dad151e2fc61c8909b Mon Sep 17 00:00:00 2001 From: globegitter Date: Mon, 18 Feb 2019 11:05:41 +0100 Subject: [PATCH 08/20] Missing variable fix. --- tools/build_defs/repo/git.bzl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index ca425df53a772d..5009ea4116a89d 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -46,7 +46,7 @@ def _setup_cache(ctx, git_cache): def _get_repository_from_cache(ctx, directory, ref, shallow, git_cache): bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" - st = ctx.execute([bash_exe, "-c", """ + exec_result = ctx.execute([bash_exe, "-c", """ cd {working_dir} set -ex rm -rf '{directory}' '{dir_link}' @@ -62,9 +62,9 @@ def _get_repository_from_cache(ctx, directory, ref, shallow, git_cache): shallow = shallow, git_cache = git_cache, )], environment = ctx.os.environ) - _if_debug(cond=ctx.attr.verbose, st=st, what='Checkout') + _if_debug(cond=ctx.attr.verbose, st=exec_result, what='Checkout') - return st.return_code + return exec_result def _populate_cache(ctx, git_cache, remote_name, ref, shallow): # 'remote add x' must be done only if x does not exist @@ -125,13 +125,13 @@ def _clone_or_update(ctx): if git_cache: _setup_cache(ctx, git_cache) - return_code = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) + st = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) - if return_code: + if st.return_code: _populate_cache(ctx, git_cache, remote_name, ref, shallow) - return_code = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) + st = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) - if return_code: + if st.return_code: fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) else: st = ctx.execute([bash_exe, "-c", """ From f4e813d071a9061226a44b21c6be0728cde196c0 Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 10 Mar 2019 21:07:27 +0100 Subject: [PATCH 09/20] Progress on error. --- .../bazel/skylark_git_repository_test.sh | 20 ++++++++++++------- tools/build_defs/repo/git.bzl | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index d56fd2e4913a41..443f3f1af1d67b 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -165,17 +165,23 @@ EOF # 1. Creates a git_repository rule with some commit hash # 2. Make sure worksapce can be built and repository cache is updated function test_git_repositry_cache_is_populated() { - local pluto_repo_dir=$TEST_TMPDIR/repos/pluto - local cache_dir=/tmp/bazel_cache - local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" + function verlte() { printf '%s\n%s' "$1" "$2" | sort -C -V } + local git_version=$(git --version | awk '{print $3}') + if [[ verlte $git_version 2.5.0 && 1 == 1 ]]; then + local pluto_repo_dir=$TEST_TMPDIR/repos/pluto + local cache_dir=/tmp/bazel_cache + local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" - export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir + export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - do_git_repository_test $commit_hash + do_git_repository_test $commit_hash - cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" - assert_equals $commit_hash $cache_commit_hash + cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" + assert_equals $commit_hash $cache_commit_hash + else + + fi } function test_git_repository() { diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 5009ea4116a89d..026f3ce7666ea7 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -132,7 +132,7 @@ def _clone_or_update(ctx): st = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) if st.return_code: - fail("Error checking out worktree %s:\n%s" % (ctx.name, st.stderr)) + fail("Error checking out worktree %s. Maybe you have a too old git version?:\n%s" % (ctx.name, st.stderr)) else: st = ctx.execute([bash_exe, "-c", """ cd {working_dir} From 95ad420ee348206eca74903d26967556b2deb949 Mon Sep 17 00:00:00 2001 From: globegitter Date: Tue, 19 Mar 2019 22:21:45 +0100 Subject: [PATCH 10/20] Do not check git version anymore. --- .../bazel/skylark_git_repository_test.sh | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 443f3f1af1d67b..d56fd2e4913a41 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -165,23 +165,17 @@ EOF # 1. Creates a git_repository rule with some commit hash # 2. Make sure worksapce can be built and repository cache is updated function test_git_repositry_cache_is_populated() { - function verlte() { printf '%s\n%s' "$1" "$2" | sort -C -V } - local git_version=$(git --version | awk '{print $3}') - if [[ verlte $git_version 2.5.0 && 1 == 1 ]]; then - local pluto_repo_dir=$TEST_TMPDIR/repos/pluto - local cache_dir=/tmp/bazel_cache - local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" - + local pluto_repo_dir=$TEST_TMPDIR/repos/pluto + local cache_dir=/tmp/bazel_cache + local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" - export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - do_git_repository_test $commit_hash + export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" - assert_equals $commit_hash $cache_commit_hash - else + do_git_repository_test $commit_hash - fi + cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" + assert_equals $commit_hash $cache_commit_hash } function test_git_repository() { From 3b6bc569ac87847d11b37d8cdfff94c32e2e04a2 Mon Sep 17 00:00:00 2001 From: globegitter Date: Tue, 19 Mar 2019 22:37:20 +0100 Subject: [PATCH 11/20] Remove stray shallow and quote properly. --- tools/build_defs/repo/git.bzl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index d37e0353e384f3..096c9615044724 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -44,7 +44,7 @@ def _setup_cache(ctx, git_cache): if st.return_code: fail("Error ... {}:\n{}\n---\n{}".format(ctx.name, st.stdout, st.stderr)) -def _get_repository_from_cache(ctx, directory, ref, shallow, git_cache): +def _get_repository_from_cache(ctx, directory, ref, git_cache): bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" exec_result = ctx.execute([bash_exe, "-c", """ cd {working_dir} @@ -57,7 +57,6 @@ def _get_repository_from_cache(ctx, directory, ref, shallow, git_cache): dir_link = ctx.path("."), directory = directory, ref = ref, - shallow = shallow, git_cache = git_cache, )], environment = ctx.os.environ) _if_debug(cond=ctx.attr.verbose, st=exec_result, what='Checkout') @@ -70,9 +69,9 @@ def _populate_cache(ctx, git_cache, remote_name, ref, shallow): st = ctx.execute([bash_exe, "-c", """set -ex git -C {git_cache} remote add '{remote_name}' '{remote}' || \ git -C {git_cache} remote set-url '{remote_name}' '{remote}' - git -C {git_cache} fetch {shallow} '{remote_name}' {ref} || \ + git -C {git_cache} fetch '{shallow}' '{remote_name}' {ref} || \ git -C {git_cache} fetch '{remote_name}' {ref} || \ - git -C {git_cache} {shallow} fetch '{remote_name}' + git -C {git_cache} '{shallow}' fetch '{remote_name}' """.format( git_cache=git_cache, remote_name=remote_name, @@ -123,11 +122,11 @@ def _clone_or_update(ctx): if git_cache: _setup_cache(ctx, git_cache) - st = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) + st = _get_repository_from_cache(ctx, directory, ref, git_cache) if st.return_code: _populate_cache(ctx, git_cache, remote_name, ref, shallow) - st = _get_repository_from_cache(ctx, directory, ref, shallow, git_cache) + st = _get_repository_from_cache(ctx, directory, ref, git_cache) if st.return_code: fail("Error checking out worktree %s. Maybe you have a too old git version?:\n%s" % (ctx.name, st.stderr)) From 157ac5fc8b054ac369996f819f08fff8c4e8171b Mon Sep 17 00:00:00 2001 From: globegitter Date: Tue, 19 Mar 2019 23:56:21 +0100 Subject: [PATCH 12/20] Add additional fetch fallback without shallow and fix typo. --- tools/build_defs/repo/git.bzl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 096c9615044724..d18d7c0bbad648 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -17,7 +17,7 @@ load(":utils.bzl", "patch", "update_attrs", "workspace_and_buildfile") def _if_debug(cond, st, what="Action"): - "Print if 'cont'." + "Print if 'cond'." if cond: print("{} returned {}\n{}\n----\n{}".format(what, st.return_code, st.stdout, st.stderr)) @@ -71,7 +71,8 @@ def _populate_cache(ctx, git_cache, remote_name, ref, shallow): git -C {git_cache} remote set-url '{remote_name}' '{remote}' git -C {git_cache} fetch '{shallow}' '{remote_name}' {ref} || \ git -C {git_cache} fetch '{remote_name}' {ref} || \ - git -C {git_cache} '{shallow}' fetch '{remote_name}' + git -C {git_cache} '{shallow}' fetch '{remote_name}' || \ + git -C {git_cache} fetch '{remote_name}' """.format( git_cache=git_cache, remote_name=remote_name, From 61cd5ed56cafb261ce9f76e2bced84e6d52a947a Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 24 Mar 2019 14:03:16 +0100 Subject: [PATCH 13/20] Add better error message. --- tools/build_defs/repo/git.bzl | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index d18d7c0bbad648..5ed2f9ec54a396 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -21,18 +21,6 @@ def _if_debug(cond, st, what="Action"): if cond: print("{} returned {}\n{}\n----\n{}".format(what, st.return_code, st.stdout, st.stderr)) -def _hash(ctx, value): - """Hash a value... TODO needs a proper implementation. - """ - bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" - key = ctx.execute([ - bash_exe, - "-c", - "(echo '{value}' | shasum)".format(value=value), - ]).stdout - key = key.split(sep=' ')[0] - return key - def _setup_cache(ctx, git_cache): # Set-up git_cache git repository. bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash" @@ -90,7 +78,7 @@ def _clone_or_update(ctx): (ctx.attr.tag and ctx.attr.branch) or (ctx.attr.commit and ctx.attr.branch)): fail("Exactly one of commit, tag, or branch must be provided") - remote_name = "remote_" + _hash(ctx, ctx.attr.remote) + remote_name = "remote_" + hash(ctx.attr.remote) shallow = "" if ctx.attr.commit: ref = ctx.attr.commit @@ -130,7 +118,9 @@ def _clone_or_update(ctx): st = _get_repository_from_cache(ctx, directory, ref, git_cache) if st.return_code: - fail("Error checking out worktree %s. Maybe you have a too old git version?:\n%s" % (ctx.name, st.stderr)) + fail("Error checking out worktree %s. Maybe your git version is too old?. Using Git " + + "repository caching requires at least Git 2.5.0. Her is the error we got :\n%s" % + (ctx.name, st.stderr)) else: st = ctx.execute([bash_exe, "-c", """ cd {working_dir} From aa08e5942c51ff7b32ffdb3867b1182d54e35461 Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 24 Mar 2019 14:29:12 +0100 Subject: [PATCH 14/20] str of hash. --- tools/build_defs/repo/git.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 5ed2f9ec54a396..2ebd01e1973a42 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -78,7 +78,7 @@ def _clone_or_update(ctx): (ctx.attr.tag and ctx.attr.branch) or (ctx.attr.commit and ctx.attr.branch)): fail("Exactly one of commit, tag, or branch must be provided") - remote_name = "remote_" + hash(ctx.attr.remote) + remote_name = "remote_" + str(hash(ctx.attr.remote)) shallow = "" if ctx.attr.commit: ref = ctx.attr.commit From 2f2492f6923ec24e29f6d8167cd0cb5a541704cb Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 24 Mar 2019 15:46:35 +0100 Subject: [PATCH 15/20] Try other multiline string. --- tools/build_defs/repo/git.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/build_defs/repo/git.bzl b/tools/build_defs/repo/git.bzl index 2ebd01e1973a42..c6ffdf66035436 100644 --- a/tools/build_defs/repo/git.bzl +++ b/tools/build_defs/repo/git.bzl @@ -118,8 +118,8 @@ def _clone_or_update(ctx): st = _get_repository_from_cache(ctx, directory, ref, git_cache) if st.return_code: - fail("Error checking out worktree %s. Maybe your git version is too old?. Using Git " - + "repository caching requires at least Git 2.5.0. Her is the error we got :\n%s" % + fail("""Error checking out worktree %s. Maybe your git version is too old?. Using Git + repository caching requires at least Git 2.5.0. Her is the error we got :\n%s""" % (ctx.name, st.stderr)) else: st = ctx.execute([bash_exe, "-c", """ From 79ffdb633124f190cf61262a2b9c34daa28d01dc Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 24 Mar 2019 15:56:43 +0100 Subject: [PATCH 16/20] Skip test on ubuntu 14.04. --- src/test/shell/bazel/skylark_git_repository_test.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index d56fd2e4913a41..ad5158a2695d43 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -172,10 +172,14 @@ function test_git_repositry_cache_is_populated() { export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - do_git_repository_test $commit_hash + . /etc/lsb-release - cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" - assert_equals $commit_hash $cache_commit_hash + if [ "$DISTRIB_RELEASE" != "14.04" ]; then + do_git_repository_test $commit_hash + + cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" + assert_equals $commit_hash $cache_commit_hash + fi } function test_git_repository() { From acb3696a08c8eea94fe918aad907510d90652b85 Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 24 Mar 2019 19:51:31 +0100 Subject: [PATCH 17/20] Fix tests. --- src/test/shell/bazel/skylark_git_repository_test.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index ad5158a2695d43..895f4467e24ee6 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -168,13 +168,18 @@ function test_git_repositry_cache_is_populated() { local pluto_repo_dir=$TEST_TMPDIR/repos/pluto local cache_dir=/tmp/bazel_cache local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" + local DISTRIB_RELEASE="unknown" + local DISTRIB_ID="unknown" export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - . /etc/lsb-release + if [ -e /etc/lsb-release ]; then + . /etc/lsb-release + fi - if [ "$DISTRIB_RELEASE" != "14.04" ]; then + # Do not run tests on ubuntu 14 + if [[ !("$DISTRIB_RELEASE" == "14.04" && $DISTRIB_ID == "ubuntu") ]]; then do_git_repository_test $commit_hash cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" From da14007155503ce4630341d500b108463c9d44f7 Mon Sep 17 00:00:00 2001 From: globegitter Date: Sun, 24 Mar 2019 19:57:26 +0100 Subject: [PATCH 18/20] Fix if check to check for worktree command directly. --- src/test/shell/bazel/skylark_git_repository_test.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 895f4467e24ee6..78cbe06d845556 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -168,18 +168,12 @@ function test_git_repositry_cache_is_populated() { local pluto_repo_dir=$TEST_TMPDIR/repos/pluto local cache_dir=/tmp/bazel_cache local commit_hash="52f9a3f87a2dd17ae0e5847bbae9734f09354afd" - local DISTRIB_RELEASE="unknown" - local DISTRIB_ID="unknown" export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - if [ -e /etc/lsb-release ]; then - . /etc/lsb-release - fi - - # Do not run tests on ubuntu 14 - if [[ !("$DISTRIB_RELEASE" == "14.04" && $DISTRIB_ID == "ubuntu") ]]; then + # Do not run tests if the git worktree command does not exist + if git worktree --help; then do_git_repository_test $commit_hash cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" From 28db515ba5e12d7f83049772bd60a27ba1e18f63 Mon Sep 17 00:00:00 2001 From: globegitter Date: Fri, 5 Apr 2019 00:07:09 +0200 Subject: [PATCH 19/20] Retrigger tests. --- src/test/shell/bazel/skylark_git_repository_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 78cbe06d845556..4bf57cc2413107 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -172,7 +172,7 @@ function test_git_repositry_cache_is_populated() { export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir - # Do not run tests if the git worktree command does not exist + # Do not run tests if the git worktree command does not exist. if git worktree --help; then do_git_repository_test $commit_hash From cd5267db63883058cd93dc36c8e71d5b4de8a13c Mon Sep 17 00:00:00 2001 From: globegitter Date: Fri, 5 Apr 2019 00:34:08 +0200 Subject: [PATCH 20/20] Rerun tests normally everywhere. --- src/test/shell/bazel/skylark_git_repository_test.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/shell/bazel/skylark_git_repository_test.sh b/src/test/shell/bazel/skylark_git_repository_test.sh index 4bf57cc2413107..69cb975bf1f2da 100755 --- a/src/test/shell/bazel/skylark_git_repository_test.sh +++ b/src/test/shell/bazel/skylark_git_repository_test.sh @@ -173,12 +173,13 @@ function test_git_repositry_cache_is_populated() { export BAZEL_GIT_REPOSITORY_CACHE=$cache_dir # Do not run tests if the git worktree command does not exist. - if git worktree --help; then - do_git_repository_test $commit_hash + # Testing without if check - is windows timing out due to that? + # if git worktree --help; then + do_git_repository_test $commit_hash - cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" - assert_equals $commit_hash $cache_commit_hash - fi + cache_commit_hash="$(cat $cache_dir/worktrees/pluto/HEAD)" + assert_equals $commit_hash $cache_commit_hash + # fi } function test_git_repository() {