Files
sdk/third_party/binaryen/generate_needed_files.py
T
Jonas Termansen 5c9d67edcd Fix binaryen build being unreproducible.
The source files were linked in filesystem order rather than sorted
order, which meant the binaryen programs were not built reproducibly.

The binaryen config.h contains the version of the binaryen based on the
git tag, however gclient sync does not pull down additional git tags
when the checkout is updated. Effectively the git tags are frozen and
the wrong version may be reported, leading to divergent builds and lack
of remote build cache sharing. Use the git commit instead.

Fix the gitignore rules to not ignore the files actually checked into
the Dart SDK.

Fixes: b/333761738
Change-Id: Ib2d812a04e629e5ce3da7185869051e30457d7e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362187
Commit-Queue: Jonas Termansen <sortie@google.com>
Commit-Queue: William Hesse <whesse@google.com>
Auto-Submit: Jonas Termansen <sortie@google.com>
Reviewed-by: William Hesse <whesse@google.com>
2024-04-10 21:35:39 +00:00

55 lines
1.7 KiB
Python

#!/usr/bin/env python3
# Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
import os
import re
import subprocess
import sys
def main(args):
# Build Wasm WasmIntrinsics.cpp.
wasm_intrinsics_wat = args[0]
wasm_intrinsics_cpp_in = args[1]
wasm_intrinsics_cpp_out = args[2]
with open(wasm_intrinsics_wat, 'rb') as fd:
wat = fd.read()
wat_hex = ','.join([hex(byte) for byte in wat])
with open(wasm_intrinsics_cpp_in) as fd:
template = fd.read()
template = template.replace('@WASM_INTRINSICS_SIZE@', '%s' % len(wat))
template = template.replace('@WASM_INTRINSICS_EMBED@', wat_hex)
with open(wasm_intrinsics_cpp_out, 'w') as fd:
fd.write(template)
# Build config.h
cmake_in = args[3]
config_h_in = args[4]
config_out = args[5]
with open(cmake_in) as fd:
cmake = fd.read()
with open(config_h_in) as fd:
template = fd.read()
match = re.search(
r'project\(binaryen LANGUAGES C CXX VERSION (?P<version>[0-9]+)\)',
cmake)
version = match['version']
git_args = ['git', 'rev-parse', 'HEAD']
try:
output = subprocess.check_output(git_args,
cwd=os.path.dirname(cmake_in),
text=True)
version = '%s (%s)' % (version, output.strip())
except:
pass
template = template.replace('#cmakedefine', '#define')
template = template.replace('${PROJECT_VERSION}', version)
with open(config_out, 'w') as fd:
fd.write(template)
if __name__ == '__main__':
main(sys.argv[1:])