From bc2a5ae634b7c623ada23ebcbc713a0f7eb6f011 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Wed, 31 Jul 2019 20:53:07 -0700 Subject: [PATCH] use the correct project-specific context when computing hashes Summary: Update `BuildOpts.compute_dirs()` to use the correct project-specific manifest context when computing project hashes. Previously it was incorrectly using the initial project's context when evaluating all dependencies. This would result in some projects potentially seeing the wrong values for variables that may change from project to project (like `test`). Reviewed By: pkaush Differential Revision: D16477398 fbshipit-source-id: 6c23f5e5e19b2402000a138b3920b79044446041 --- build/fbcode_builder/getdeps.py | 8 ++++---- build/fbcode_builder/getdeps/buildopts.py | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build/fbcode_builder/getdeps.py b/build/fbcode_builder/getdeps.py index 1564b0f1f..80f8812b1 100755 --- a/build/fbcode_builder/getdeps.py +++ b/build/fbcode_builder/getdeps.py @@ -156,7 +156,7 @@ class ShowInstDirCmd(SubCmd): for m in manifests: ctx = ctx_gen.get_context(m.name) fetcher = m.create_fetcher(opts, ctx) - dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx) + dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx_gen) inst_dir = dirs["inst_dir"] print(inst_dir) @@ -236,7 +236,7 @@ class BuildCmd(SubCmd): if args.clean: fetcher.clean() - dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx) + dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx_gen) build_dir = dirs["build_dir"] inst_dir = dirs["inst_dir"] @@ -331,7 +331,7 @@ class FixupDeps(SubCmd): ctx = ctx_gen.get_context(m.name) fetcher = m.create_fetcher(opts, ctx) - dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx) + dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx_gen) inst_dir = dirs["inst_dir"] install_dirs.append(inst_dir) @@ -388,7 +388,7 @@ class TestCmd(SubCmd): ctx = ctx_gen.get_context(m.name) fetcher = m.create_fetcher(opts, ctx) - dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx) + dirs = opts.compute_dirs(m, fetcher, manifests_by_name, ctx_gen) build_dir = dirs["build_dir"] inst_dir = dirs["inst_dir"] diff --git a/build/fbcode_builder/getdeps/buildopts.py b/build/fbcode_builder/getdeps/buildopts.py index 7e842d36e..d0e2b6339 100644 --- a/build/fbcode_builder/getdeps/buildopts.py +++ b/build/fbcode_builder/getdeps/buildopts.py @@ -148,7 +148,7 @@ class BuildOptions(object): } ) - def _compute_hash(self, hash_by_name, manifest, manifests_by_name, ctx): + def _compute_hash(self, hash_by_name, manifest, manifests_by_name, ctx_gen): """ This recursive function computes a hash for a given manifest. The hash takes into account some environmental factors on the host machine and includes the hashes of its dependencies. @@ -173,6 +173,7 @@ class BuildOptions(object): for tool in ["cc", "c++", "gcc", "g++", "clang", "clang++"]: env["tool-%s" % tool] = path_search(os.environ, tool) + ctx = ctx_gen.get_context(manifest.name) fetcher = manifest.create_fetcher(self, ctx) env["fetcher.hash"] = fetcher.hash() @@ -187,7 +188,7 @@ class BuildOptions(object): dep_list = sorted(manifest.get_section_as_dict("dependencies", ctx).keys()) for dep in dep_list: dep_hash = self._compute_hash( - hash_by_name, manifests_by_name[dep], manifests_by_name, ctx + hash_by_name, manifests_by_name[dep], manifests_by_name, ctx_gen ) hasher.update(dep_hash.encode("utf-8")) @@ -203,9 +204,9 @@ class BuildOptions(object): return h - def compute_dirs(self, manifest, fetcher, manifests_by_name, ctx): + def compute_dirs(self, manifest, fetcher, manifests_by_name, ctx_gen): hash_by_name = {} - hash = self._compute_hash(hash_by_name, manifest, manifests_by_name, ctx) + hash = self._compute_hash(hash_by_name, manifest, manifests_by_name, ctx_gen) if manifest.is_first_party_project(): directory = manifest.name