diff --git a/build-system/Make/BazelLocation.py b/build-system/Make/BazelLocation.py index 4d33191a94..e246d5ba47 100644 --- a/build-system/Make/BazelLocation.py +++ b/build-system/Make/BazelLocation.py @@ -1,10 +1,41 @@ import os import stat import sys +from urllib.parse import urlparse, urlunparse +import tempfile +import hashlib +import shutil -from BuildEnvironment import is_apple_silicon, resolve_executable, call_executable, BuildEnvironmentVersions +from BuildEnvironment import is_apple_silicon, resolve_executable, call_executable, run_executable_with_status, BuildEnvironmentVersions -def locate_bazel(base_path): +def transform_cache_host_into_http(grpc_url): + parsed_url = urlparse(grpc_url) + + new_scheme = "http" + new_port = 8080 + + transformed_url = urlunparse(( + new_scheme, + f"{parsed_url.hostname}:{new_port}", + parsed_url.path, + parsed_url.params, + parsed_url.query, + parsed_url.fragment + )) + + return transformed_url + + +def calculate_sha256(file_path): + sha256_hash = hashlib.sha256() + with open(file_path, "rb") as file: + # Read the file in chunks to avoid using too much memory + for byte_block in iter(lambda: file.read(4096), b""): + sha256_hash.update(byte_block) + return sha256_hash.hexdigest() + + +def locate_bazel(base_path, cache_host): build_input_dir = '{}/build-input'.format(base_path) if not os.path.isdir(build_input_dir): os.mkdir(build_input_dir) @@ -17,6 +48,33 @@ def locate_bazel(base_path): bazel_name = 'bazel-{version}-{arch}'.format(version=versions.bazel_version, arch=arch) bazel_path = '{}/build-input/{}'.format(base_path, bazel_name) + if not os.path.isfile(bazel_path): + if cache_host is not None and versions.bazel_version_sha256 is not None: + http_cache_host = transform_cache_host_into_http(cache_host) + + with tempfile.NamedTemporaryFile(delete=True) as temp_output_file: + call_executable([ + 'curl', + '-L', + '{cache_host}/cache/cas/{hash}'.format( + cache_host=http_cache_host, + hash=versions.bazel_version_sha256 + ), + '--output', + temp_output_file.name + ], check_result=False) + test_sha256 = calculate_sha256(temp_output_file.name) + if test_sha256 == versions.bazel_version_sha256: + shutil.copyfile(temp_output_file.name, bazel_path) + + + if os.path.isfile(bazel_path) and versions.bazel_version_sha256 is not None: + test_sha256 = calculate_sha256(bazel_path) + if test_sha256 != versions.bazel_version_sha256: + print(f"Bazel at {bazel_path} does not match SHA256 {versions.bazel_version_sha256}, removing") + os.remove(bazel_path) + + if not os.path.isfile(bazel_path): call_executable([ 'curl', @@ -29,6 +87,27 @@ def locate_bazel(base_path): bazel_path ]) + if os.path.isfile(bazel_path) and versions.bazel_version_sha256 is not None: + test_sha256 = calculate_sha256(bazel_path) + if test_sha256 != versions.bazel_version_sha256: + print(f"Bazel at {bazel_path} does not match SHA256 {versions.bazel_version_sha256}, removing") + os.remove(bazel_path) + + if cache_host is not None and versions.bazel_version_sha256 is not None: + http_cache_host = transform_cache_host_into_http(cache_host) + print(f"Uploading bazel@{versions.bazel_version_sha256} to bazel-remote") + call_executable([ + 'curl', + '-X', + 'PUT', + '-T', + bazel_path, + '{cache_host}/cache/cas/{hash}'.format( + cache_host=http_cache_host, + hash=versions.bazel_version_sha256 + ) + ], check_result=False) + if not os.access(bazel_path, os.X_OK): st = os.stat(bazel_path) os.chmod(bazel_path, st.st_mode | stat.S_IEXEC) diff --git a/build-system/Make/BuildConfiguration.py b/build-system/Make/BuildConfiguration.py index 1052bb5ef1..835ecff11c 100644 --- a/build-system/Make/BuildConfiguration.py +++ b/build-system/Make/BuildConfiguration.py @@ -62,7 +62,7 @@ class BuildConfiguration: def build_configuration_from_json(path): if not os.path.exists(path): - print('Could not load build configuration from {}'.format(path)) + print('Could not load build configuration from non-existing path {}'.format(path)) sys.exit(1) with open(path) as file: configuration_dict = json.load(file) diff --git a/build-system/Make/BuildEnvironment.py b/build-system/Make/BuildEnvironment.py index 8d31133fe1..3f7311aa73 100644 --- a/build-system/Make/BuildEnvironment.py +++ b/build-system/Make/BuildEnvironment.py @@ -65,6 +65,28 @@ def run_executable_with_output(path, arguments, decode=True, input=None, stderr_ return output_data +def run_executable_with_status(arguments, use_clean_environment=True): + executable_path = resolve_executable(arguments[0]) + if executable_path is None: + raise Exception(f'Could not resolve {arguments[0]} to a valid executable file') + + if use_clean_environment: + resolved_env = get_clean_env() + else: + resolved_env = os.environ + + resolved_arguments = [executable_path] + arguments[1:] + + result = subprocess.run( + resolved_arguments, + env=resolved_env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + return result.returncode + + def call_executable(arguments, use_clean_environment=True, check_result=True): executable_path = resolve_executable(arguments[0]) if executable_path is None: @@ -135,7 +157,9 @@ class BuildEnvironmentVersions: if configuration_dict['bazel'] is None: raise Exception('Missing bazel version in {}'.format(configuration_path)) else: - self.bazel_version = configuration_dict['bazel'] + bazel_version, bazel_version_sha256 = configuration_dict['bazel'].split(':') + self.bazel_version = bazel_version + self.bazel_version_sha256 = bazel_version_sha256 if configuration_dict['xcode'] is None: raise Exception('Missing xcode version in {}'.format(configuration_path)) else: diff --git a/build-system/Make/Make.py b/build-system/Make/Make.py index cb67b72a1b..00cb956868 100644 --- a/build-system/Make/Make.py +++ b/build-system/Make/Make.py @@ -985,7 +985,7 @@ if __name__ == '__main__': bazel_path = None if args.bazel is None: - bazel_path = locate_bazel(base_path=os.getcwd()) + bazel_path = locate_bazel(base_path=os.getcwd(), cache_host=args.cacheHost) else: bazel_path = args.bazel diff --git a/build-system/Make/RemoteBuild.py b/build-system/Make/RemoteBuild.py index 89ed9b0d13..2b38318c6b 100644 --- a/build-system/Make/RemoteBuild.py +++ b/build-system/Make/RemoteBuild.py @@ -161,7 +161,7 @@ def remote_build(darwin_containers_path, darwin_containers_host, macos_version, sys.exit(1) DarwinContainers.run_remote_ssh(credentials=credentials, command='') - sys.exit(0) + #sys.exit(0) def handle_stopped(): pass diff --git a/build-system/fake-codesigning/BroadcastUpload.mobileprovision b/build-system/fake-codesigning/BroadcastUpload.mobileprovision new file mode 100644 index 0000000000..76d68f7932 Binary files /dev/null and b/build-system/fake-codesigning/BroadcastUpload.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/BroadcastUpload.mobileprovision b/build-system/fake-codesigning/profiles/BroadcastUpload.mobileprovision deleted file mode 100644 index 76f8200f50..0000000000 Binary files a/build-system/fake-codesigning/profiles/BroadcastUpload.mobileprovision and /dev/null differ diff --git a/build-system/fake-codesigning/profiles/Intents.mobileprovision b/build-system/fake-codesigning/profiles/Intents.mobileprovision index 8787665b41..2c3dbc97ff 100644 Binary files a/build-system/fake-codesigning/profiles/Intents.mobileprovision and b/build-system/fake-codesigning/profiles/Intents.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/NotificationContent.mobileprovision b/build-system/fake-codesigning/profiles/NotificationContent.mobileprovision index 915083850a..4a550cb1c7 100644 Binary files a/build-system/fake-codesigning/profiles/NotificationContent.mobileprovision and b/build-system/fake-codesigning/profiles/NotificationContent.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/NotificationService.mobileprovision b/build-system/fake-codesigning/profiles/NotificationService.mobileprovision index 022bdb091f..aff76a794c 100644 Binary files a/build-system/fake-codesigning/profiles/NotificationService.mobileprovision and b/build-system/fake-codesigning/profiles/NotificationService.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/Share.mobileprovision b/build-system/fake-codesigning/profiles/Share.mobileprovision index d5c133b40c..5f45bc81be 100644 Binary files a/build-system/fake-codesigning/profiles/Share.mobileprovision and b/build-system/fake-codesigning/profiles/Share.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/Telegram.mobileprovision b/build-system/fake-codesigning/profiles/Telegram.mobileprovision index 496ad79a68..18336d85be 100644 Binary files a/build-system/fake-codesigning/profiles/Telegram.mobileprovision and b/build-system/fake-codesigning/profiles/Telegram.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/WatchApp.mobileprovision b/build-system/fake-codesigning/profiles/WatchApp.mobileprovision index 0eb5a56cb3..7996879fbe 100644 Binary files a/build-system/fake-codesigning/profiles/WatchApp.mobileprovision and b/build-system/fake-codesigning/profiles/WatchApp.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/WatchExtension.mobileprovision b/build-system/fake-codesigning/profiles/WatchExtension.mobileprovision index 85b1a95f8d..3bf56c09fb 100644 Binary files a/build-system/fake-codesigning/profiles/WatchExtension.mobileprovision and b/build-system/fake-codesigning/profiles/WatchExtension.mobileprovision differ diff --git a/build-system/fake-codesigning/profiles/Widget.mobileprovision b/build-system/fake-codesigning/profiles/Widget.mobileprovision index f6fe6677e2..dfdc9cd48a 100644 Binary files a/build-system/fake-codesigning/profiles/Widget.mobileprovision and b/build-system/fake-codesigning/profiles/Widget.mobileprovision differ diff --git a/versions.json b/versions.json index 1a573248dd..ca9eaedf32 100644 --- a/versions.json +++ b/versions.json @@ -1,6 +1,6 @@ { "app": "11.3", "xcode": "16.0", - "bazel": "7.3.1", + "bazel": "7.3.1:981f82a470bad1349322b6f51c9c6ffa0aa291dab1014fac411543c12e661dff", "macos": "15.0" }