Skip to content

Commit e67c961

Browse files
philwocopybara-github
authored andcommitted
Fix a non-determinism in create_embedded_tools.py.
PiperOrigin-RevId: 246804128
1 parent 60cd10b commit e67c961

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

scripts/bootstrap/compile.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ EOF
272272

273273
# Set up @bazel_tools//platforms properly
274274
mkdir -p ${BAZEL_TOOLS_REPO}/platforms
275-
cp tools/platforms/platforms.BUILD ${BAZEL_TOOLS_REPO}/platforms/BUILD
275+
cp tools/platforms/BUILD.tools ${BAZEL_TOOLS_REPO}/platforms/BUILD
276276

277277
# Overwrite tools.WORKSPACE, this is only for the bootstrap binary
278278
chmod u+w "${OUTPUT_DIR}/classes/com/google/devtools/build/lib/bazel/rules/tools.WORKSPACE"

src/BUILD

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ genquery(
6161
# Create dummy tools so we can do select to prevent building iOS target on
6262
# Linux.
6363
OSX_DUMMY_TARGETS = [
64-
"src/tools/xcode/actoolwrapper/actoolwrapper",
65-
"src/tools/xcode/ibtoolwrapper/ibtoolwrapper",
66-
"src/tools/xcode/momcwrapper/momcwrapper",
64+
"src/tools/xcode/actoolwrapper/actoolwrapper.sh",
65+
"src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh",
66+
"src/tools/xcode/momcwrapper/momcwrapper.sh",
6767
"src/objc_tools/bundlemerge/bundlemerge_deploy.jar",
6868
"src/objc_tools/plmerge/plmerge_deploy.jar",
6969
"src/tools/xcode/realpath/realpath",
@@ -83,9 +83,9 @@ OSX_DUMMY_TARGETS = [
8383
filegroup(
8484
name = "darwin_tools",
8585
srcs = [
86-
"//src/tools/xcode/actoolwrapper:actoolwrapper",
87-
"//src/tools/xcode/ibtoolwrapper:ibtoolwrapper",
88-
"//src/tools/xcode/momcwrapper:momcwrapper",
86+
"//src/tools/xcode/actoolwrapper:actoolwrapper.sh",
87+
"//src/tools/xcode/ibtoolwrapper:ibtoolwrapper.sh",
88+
"//src/tools/xcode/momcwrapper:momcwrapper.sh",
8989
"//src/objc_tools/bundlemerge:bundlemerge_deploy.jar",
9090
"//src/objc_tools/plmerge:plmerge_deploy.jar",
9191
"//src/tools/xcode/realpath:realpath",

src/create_embedded_tools.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
('*tools/jdk/BUILD', lambda x: 'tools/jdk/BUILD'),
3232
('*tools/build_defs/repo/BUILD.repo',
3333
lambda x: 'tools/build_defs/repo/BUILD'),
34-
('*tools/platforms/platforms.BUILD', lambda x: 'platforms/BUILD'),
34+
('*tools/platforms/BUILD.tools', lambda x: 'platforms/BUILD'),
3535
('*tools/platforms/*', lambda x: 'platforms/' + os.path.basename(x)),
3636
('*tools/cpp/runfiles/generated_*',
3737
lambda x: 'tools/cpp/runfiles/' + os.path.basename(x)[len('generated_'):]),
@@ -51,9 +51,7 @@
5151
lambda x: 'tools/objc/make_hashed_objlist.py'),
5252
('*xcode*realpath', lambda x: 'tools/objc/realpath'),
5353
('*xcode*xcode-locator', lambda x: 'tools/objc/xcode-locator'),
54-
('*src/tools/xcode/*.sh', lambda x: 'tools/objc/' + os.path.basename(x)),
55-
('*src/tools/xcode/*',
56-
lambda x: 'tools/objc/' + os.path.basename(x) + '.sh'),
54+
('*src/tools/xcode/*', lambda x: 'tools/objc/' + os.path.basename(x)),
5755
('*external/openjdk_*/file/*.tar.gz', lambda x: 'jdk.tar.gz'),
5856
('*external/openjdk_*/file/*.zip', lambda x: 'jdk.zip'),
5957
('*src/minimal_jdk.tar.gz', lambda x: 'jdk.tar.gz'),
@@ -70,15 +68,18 @@ def get_output_path(path):
7068

7169

7270
def get_input_files(argsfile):
73-
"""Returns a sorted list of tuples (archive_file, input_file).
71+
"""Returns a dict of archive_file to input_file.
7472
7573
This describes the files that should be put into the generated archive.
7674
7775
Args:
7876
argsfile: The file containing the list of input files.
77+
78+
Raises:
79+
ValueError: When two input files map to the same output file.
7980
"""
8081
with open(argsfile, 'r') as f:
81-
input_files = set(x.strip() for x in f.readlines())
82+
input_files = sorted(set(x.strip() for x in f.readlines()))
8283

8384
result = {}
8485
for input_file in input_files:
@@ -87,14 +88,16 @@ def get_input_files(argsfile):
8788
input_file + '.tools' in input_files):
8889
continue
8990

90-
# This gives us the same behavior as the older bash version of this
91-
# tool: If two input files map to the same output files, the one that
92-
# comes last in the list of input files overrides all earlier ones.
93-
result[get_output_path(input_file)] = input_file
91+
# It's an error to have two files map to the same output file, because the
92+
# result is hard to predict and can easily be wrong.
93+
output_path = get_output_path(input_file)
94+
if output_path in result:
95+
raise ValueError(
96+
'Duplicate output file: Both {} and {} map to {}'.format(
97+
result[output_path], input_file, output_path))
98+
result[output_path] = input_file
9499

95-
# By sorting the file list, the resulting ZIP file will not be reproducible
96-
# and deterministic.
97-
return sorted(result.items())
100+
return result
98101

99102

100103
def copy_jdk_into_archive(output_zip, archive_file, input_file):
@@ -124,7 +127,9 @@ def main():
124127
zipinfo.external_attr = 0o644 << 16
125128
output_zip.writestr(zipinfo, 'workspace(name = "bazel_tools")\n')
126129

127-
for archive_file, input_file in input_files:
130+
# By sorting the file list, the resulting ZIP file will be reproducible and
131+
# deterministic.
132+
for archive_file, input_file in sorted(input_files.items()):
128133
if os.path.basename(archive_file) in ('jdk.tar.gz', 'jdk.zip'):
129134
copy_jdk_into_archive(output_zip, archive_file, input_file)
130135
else:

tools/platforms/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package(
77
filegroup(
88
name = "package-srcs",
99
srcs = [
10-
"platforms.BUILD",
10+
"BUILD.tools",
1111
],
1212
)
1313

File renamed without changes.

0 commit comments

Comments
 (0)