From a64485dbb378d7ac6afc9082fd7176a957815a8c Mon Sep 17 00:00:00 2001 From: Michael Case Date: Fri, 22 Dec 2017 15:44:29 -0800 Subject: [PATCH] Run gen_git_source.py inside of a repo_rule instead of configure. PiperOrigin-RevId: 179971055 --- configure.py | 14 -------------- tensorflow/tensorflow.bzl | 6 +++--- tensorflow/tools/git/BUILD | 4 +--- tensorflow/tools/git/gen/branch_ref | 1 - tensorflow/tools/git/gen/head | 1 - tensorflow/tools/git/gen/spec.json | 3 --- tensorflow/tools/git/gen_git_source.py | 11 ++++++++--- tensorflow/workspace.bzl | 2 ++ third_party/git/BUILD | 0 third_party/git/BUILD.tpl | 10 ++++++++++ third_party/git/git_configure.bzl | 20 ++++++++++++++++++++ 11 files changed, 44 insertions(+), 28 deletions(-) delete mode 100644 tensorflow/tools/git/gen/branch_ref delete mode 100644 tensorflow/tools/git/gen/head delete mode 100644 tensorflow/tools/git/gen/spec.json create mode 100644 third_party/git/BUILD create mode 100644 third_party/git/BUILD.tpl create mode 100644 third_party/git/git_configure.bzl diff --git a/configure.py b/configure.py index 1917af4b65c..e4218b56518 100644 --- a/configure.py +++ b/configure.py @@ -265,19 +265,6 @@ def reset_tf_configure_bazelrc(): f.write('import %workspace%/.tf_configure.bazelrc\n') -def run_gen_git_source(environ_cp): - """Run the gen_git_source to create links. - - The links are for bazel to track dependencies for git hash propagation. - - Args: - environ_cp: copy of the os.environ. - """ - cmd = '"%s" tensorflow/tools/git/gen_git_source.py --configure %s' % ( - environ_cp.get('PYTHON_BIN_PATH'), os.getcwd()) - os.system(cmd) - - def cleanup_makefile(): """Delete any leftover BUILD files from the Makefile build. @@ -1251,7 +1238,6 @@ def main(): reset_tf_configure_bazelrc() cleanup_makefile() setup_python(environ_cp) - run_gen_git_source(environ_cp) if is_windows(): environ_cp['TF_NEED_S3'] = '0' diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index b71328f847c..82675a91c51 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -1561,9 +1561,9 @@ def tf_version_info_genrule(): native.genrule( name="version_info_gen", srcs=[ - clean_dep("//tensorflow/tools/git:gen/spec.json"), - clean_dep("//tensorflow/tools/git:gen/head"), - clean_dep("//tensorflow/tools/git:gen/branch_ref"), + clean_dep("@local_config_git//:gen/spec.json"), + clean_dep("@local_config_git//:gen/head"), + clean_dep("@local_config_git//:gen/branch_ref"), ], outs=["util/version_info.cc"], cmd= diff --git a/tensorflow/tools/git/BUILD b/tensorflow/tools/git/BUILD index f502c8dde07..942ceab85fc 100644 --- a/tensorflow/tools/git/BUILD +++ b/tensorflow/tools/git/BUILD @@ -7,9 +7,7 @@ package(default_visibility = ["//tensorflow:internal"]) licenses(["notice"]) # Apache 2.0 exports_files( - glob(["gen/*"]) + [ - "gen_git_source.py", - ], + ["gen_git_source.py"], ) # ----------------------------------------------------------------------------- diff --git a/tensorflow/tools/git/gen/branch_ref b/tensorflow/tools/git/gen/branch_ref deleted file mode 100644 index 8b137891791..00000000000 --- a/tensorflow/tools/git/gen/branch_ref +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tensorflow/tools/git/gen/head b/tensorflow/tools/git/gen/head deleted file mode 100644 index 8b137891791..00000000000 --- a/tensorflow/tools/git/gen/head +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tensorflow/tools/git/gen/spec.json b/tensorflow/tools/git/gen/spec.json deleted file mode 100644 index 176bbc21ccb..00000000000 --- a/tensorflow/tools/git/gen/spec.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "git": false -} diff --git a/tensorflow/tools/git/gen_git_source.py b/tensorflow/tools/git/gen_git_source.py index 2e27487d2ff..3630dbd740e 100755 --- a/tensorflow/tools/git/gen_git_source.py +++ b/tensorflow/tools/git/gen_git_source.py @@ -62,7 +62,7 @@ def parse_branch_ref(filename): raise RuntimeError("Git directory has unparseable HEAD") -def configure(src_base_path, debug=False): +def configure(src_base_path, gen_path, debug=False): """Configure `src_base_path` to embed git hashes if available.""" # TODO(aselle): No files generated or symlinked here are deleted by @@ -71,7 +71,6 @@ def configure(src_base_path, debug=False): # without running ./configure again. git_path = os.path.join(src_base_path, ".git") - gen_path = os.path.join(src_base_path, "tensorflow", "tools", "git", "gen") # Remove and recreate the path if os.path.exists(gen_path): @@ -260,6 +259,10 @@ parser.add_argument( "--configure", type=str, help="Path to configure as a git repo dependency tracking sentinel") +parser.add_argument( + "--gen_root_path", type=str, + help="Root path to place generated git files (created by --configure).") + parser.add_argument( "--generate", type=str, @@ -274,7 +277,9 @@ parser.add_argument( args = parser.parse_args() if args.configure is not None: - configure(args.configure, debug=args.debug) + if args.gen_root_path is None: + raise RuntimeError("Must pass --gen_root_path arg when running --configure") + configure(args.configure, args.gen_root_path, debug=args.debug) elif args.generate is not None: generate(args.generate) elif args.raw_generate is not None: diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl index 6a496f53f0a..6571d9c463a 100644 --- a/tensorflow/workspace.bzl +++ b/tensorflow/workspace.bzl @@ -2,6 +2,7 @@ load("//third_party/gpus:cuda_configure.bzl", "cuda_configure") load("//third_party/mkl:build_defs.bzl", "mkl_repository") +load("//third_party/git:git_configure.bzl", "git_configure") load("//third_party/py:python_configure.bzl", "python_configure") load("//third_party/sycl:sycl_configure.bzl", "sycl_configure") load("//third_party/toolchains/cpus/arm:arm_compiler_configure.bzl", "arm_compiler_configure") @@ -47,6 +48,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): # version we require here. check_version("0.5.4") cuda_configure(name="local_config_cuda") + git_configure(name="local_config_git") sycl_configure(name="local_config_sycl") python_configure(name="local_config_python") diff --git a/third_party/git/BUILD b/third_party/git/BUILD new file mode 100644 index 00000000000..e69de29bb2d diff --git a/third_party/git/BUILD.tpl b/third_party/git/BUILD.tpl new file mode 100644 index 00000000000..7b031e74d58 --- /dev/null +++ b/third_party/git/BUILD.tpl @@ -0,0 +1,10 @@ +# Description: +# Exports generated files used to generate tensorflow/core/util/version_info.cc + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +exports_files( + glob(["gen/*"]), +) diff --git a/third_party/git/git_configure.bzl b/third_party/git/git_configure.bzl new file mode 100644 index 00000000000..bd197bfd24f --- /dev/null +++ b/third_party/git/git_configure.bzl @@ -0,0 +1,20 @@ +"""Repository rule for Git autoconfiguration.""" + +def _git_conf_impl(repository_ctx): + repository_ctx.template( + "BUILD", + Label("//third_party/git:BUILD.tpl")) + + tensorflow_root_path = str(repository_ctx.path( + Label("@org_tensorflow//:BUILD")))[:-len("BUILD")] + python_script_path = repository_ctx.path( + Label("@org_tensorflow//tensorflow/tools/git:gen_git_source.py")) + generated_files_path = repository_ctx.path("gen") + + repository_ctx.execute([ + python_script_path, "--configure", tensorflow_root_path, + "--gen_root_path", generated_files_path], quiet=False) + +git_configure = repository_rule( + implementation = _git_conf_impl, +)