From 19210d5715a8504debf0f479791c0f0d1aba91bf Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Wed, 27 Jan 2021 16:19:43 -0800 Subject: [PATCH] Accurate re-generate command in TARGETS file (#7902) Summary: TIL we have different versions of TARGETS file generated with options passed to buckifier. Someone thought they were totally fine to squash the file by re-running the command to generate (pretty reasonable assumption) but the command was incorrect due to missing the extra argument used to generate THAT TARGETS file. This change includes in the command written in the TARGETS header the extra argument passed to buckify (when used). Pull Request resolved: https://github.com/facebook/rocksdb/pull/7902 Test Plan: manual, as in the (now fixed) comments at the top of buckify_rocksdb.py Reviewed By: ajkr Differential Revision: D26108317 Pulled By: pdillinger fbshipit-source-id: 46e93dc1465e27bd18e0e0baa8eeee1b591c765d --- TARGETS | 3 ++- buckifier/buckify_rocksdb.py | 16 +++++++++++----- buckifier/targets_builder.py | 5 +++-- buckifier/targets_cfg.py | 7 ++++--- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/TARGETS b/TARGETS index 4b9460f05f..26c6d9a48c 100644 --- a/TARGETS +++ b/TARGETS @@ -1,4 +1,5 @@ -# This file @generated by `python3 buckifier/buckify_rocksdb.py` +# This file @generated by: +#$ python3 buckifier/buckify_rocksdb.py # --> DO NOT EDIT MANUALLY <-- # This file is a Facebook-specific integration for buck builds, so can # only be validated by Facebook employees. diff --git a/buckifier/buckify_rocksdb.py b/buckifier/buckify_rocksdb.py index f0909bc617..6dfedbce1e 100644 --- a/buckifier/buckify_rocksdb.py +++ b/buckifier/buckify_rocksdb.py @@ -24,10 +24,10 @@ from util import ColorString # (This generates a TARGET file without user-specified dependency for unit # tests.) # $python3 buckifier/buckify_rocksdb.py \ -# '{"fake": { \ -# "extra_deps": [":test_dep", "//fakes/module:mock1"], \ -# "extra_compiler_flags": ["-DROCKSDB_LITE", "-Os"], \ -# } \ +# '{"fake": { +# "extra_deps": [":test_dep", "//fakes/module:mock1"], +# "extra_compiler_flags": ["-DROCKSDB_LITE", "-Os"] +# } # }' # (Generated TARGETS file has test_dep and mock1 as dependencies for RocksDB # unit tests, and will use the extra_compiler_flags to compile the unit test @@ -129,7 +129,13 @@ def generate_targets(repo_path, deps_map): if src_mk is None or cc_files is None or parallel_tests is None: return False - TARGETS = TARGETSBuilder("%s/TARGETS" % repo_path) + extra_argv = "" + if len(sys.argv) >= 2: + # Heuristically quote and canonicalize whitespace for inclusion + # in how the file was generated. + extra_argv = " '{0}'".format(" ".join(sys.argv[1].split())) + + TARGETS = TARGETSBuilder("%s/TARGETS" % repo_path, extra_argv) # rocksdb_lib TARGETS.add_library( diff --git a/buckifier/targets_builder.py b/buckifier/targets_builder.py index e55238b2fa..bf61b3ae1f 100644 --- a/buckifier/targets_builder.py +++ b/buckifier/targets_builder.py @@ -25,10 +25,11 @@ def pretty_list(lst, indent=8): class TARGETSBuilder(object): - def __init__(self, path): + def __init__(self, path, extra_argv): self.path = path self.targets_file = open(path, 'wb') - header = targets_cfg.rocksdb_target_header_template + header = targets_cfg.rocksdb_target_header_template.format( + extra_argv=extra_argv) self.targets_file.write(header.encode("utf-8")) self.total_lib = 0 self.total_bin = 0 diff --git a/buckifier/targets_cfg.py b/buckifier/targets_cfg.py index 0c20ef095c..986a75b881 100644 --- a/buckifier/targets_cfg.py +++ b/buckifier/targets_cfg.py @@ -5,7 +5,8 @@ from __future__ import print_function from __future__ import unicode_literals rocksdb_target_header_template = \ - """# This file \100generated by `python3 buckifier/buckify_rocksdb.py` + """# This file \100generated by: +#$ python3 buckifier/buckify_rocksdb.py{extra_argv} # --> DO NOT EDIT MANUALLY <-- # This file is a Facebook-specific integration for buck builds, so can # only be validated by Facebook employees. @@ -99,11 +100,11 @@ ROCKSDB_PREPROCESSOR_FLAGS = [ "-I" + REPO_PATH, ] -ROCKSDB_ARCH_PREPROCESSOR_FLAGS = { +ROCKSDB_ARCH_PREPROCESSOR_FLAGS = {{ "x86_64": [ "-DHAVE_PCLMUL", ], -} +}} build_mode = read_config("fbcode", "build_mode")