build_and_upload.py (3345B)
1 #!/usr/bin/env python3 2 # Copyright 2016 The Chromium Authors 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 """Automates running sysroot_creator.py for each supported arch. 7 """ 8 9 import concurrent.futures 10 import json 11 import os 12 import subprocess 13 import sys 14 import textwrap 15 16 import sysroot_creator 17 18 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) 19 20 21 def build_and_upload(arch): 22 try: 23 sysroot_creator.build_sysroot(arch) 24 result = sysroot_creator.upload_sysroot(arch) 25 return (arch, True, result) # (architecture, success, result) 26 except Exception as e: 27 return (arch, False, str(e)) # (architecture, failure, error message) 28 29 30 def main(): 31 with concurrent.futures.ThreadPoolExecutor() as executor: 32 # Map the function over the architectures 33 futures = [ 34 executor.submit(build_and_upload, arch) 35 for arch in sysroot_creator.TRIPLES 36 ] 37 38 failures = 0 39 results = {} 40 for future in concurrent.futures.as_completed(futures): 41 arch, success, result = future.result() 42 if not success: 43 failures += 1 44 name = (f"{sysroot_creator.DISTRO}_{sysroot_creator.RELEASE}" + 45 f"_{arch.lower()}-sysroot") 46 results[name] = (success, result) 47 48 globals = {"Str": lambda x: x, "Var": lambda x: x} 49 deps = open(os.path.join(SCRIPT_DIR, "..", "..", "..", "DEPS")).read() 50 exec(deps, globals) 51 updates = {} 52 53 print("SYSROOT CREATION SUMMARY") 54 for name, (success, result) in results.items(): 55 status = "SUCCESS" if success else "FAILURE" 56 print(name, status, sep=":\t") 57 key = f"src/build/linux/{name}" 58 updates[key] = globals["deps"][key] 59 if success: 60 result = " ".join(result.splitlines()[1:]) 61 updates[key]["objects"] = json.loads(result)["path"]["objects"] 62 63 print("Updating DEPS files") 64 for key, objects in updates.items(): 65 obj = objects["objects"][0] 66 object_info = ','.join([ 67 obj["object_name"], 68 obj["sha256sum"], 69 str(obj["size_bytes"]), 70 str(obj["generation"]), 71 ]) 72 73 print(f"Updating {key} in src/DEPS") 74 subprocess.call(["gclient", "setdep", "-r", f"{key}@{object_info}"]) 75 prefix = 'src/build/' 76 substr_key = key[len(prefix):] 77 print(f"Updating {substr_key} in src/build/DEPS") 78 subprocess.call([ 79 "gclient", "setdep", "-r", f"{substr_key}@{object_info}", 80 "--deps-file", "build/DEPS" 81 ]) 82 83 if not failures: 84 key = (sysroot_creator.ARCHIVE_TIMESTAMP + "-" + 85 str(sysroot_creator.SYSROOT_RELEASE)) 86 sysroot_gni = textwrap.dedent(f"""\ 87 # Copyright 2024 The Chromium Authors 88 # Use of this source code is governed by a BSD-style license that 89 # can be found in the LICENSE file. 90 91 # This file was generated by 92 # build/linux/sysroot_scripts/build_and_upload.py 93 94 cr_sysroot_key = "{key}" 95 """) 96 fname = os.path.join(SCRIPT_DIR, "sysroot.gni") 97 with open(fname, "w") as f: 98 f.write(sysroot_gni) 99 100 return failures 101 102 103 if __name__ == "__main__": 104 sys.exit(main())