David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 1 | # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import os |
| 6 | import sys |
| 7 | import shutil |
| 8 | import subprocess |
| 9 | import argparse |
| 10 | import re |
| 11 | |
| 12 | parser = argparse.ArgumentParser(description="Upload goldfish libvulkan to CIPD") |
| 13 | |
| 14 | parser.add_argument("--release-dir") |
| 15 | parser.add_argument("--arch") |
| 16 | parser.add_argument("--dry-run", action="store_true") |
| 17 | parser.add_argument("--ignore-branch", action="store_true") |
| 18 | parser.add_argument("--ignore-rebuild", action="store_true") |
| 19 | parser.add_argument("--ignore-buildtype", action="store_true") |
| 20 | |
| 21 | args = parser.parse_args() |
| 22 | |
| 23 | dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 24 | |
| 25 | os.chdir(dir_path) |
| 26 | |
| 27 | fuchsia_root = os.path.abspath(os.path.join(dir_path, "../../../")) |
Yilong Li | 97ac297 | 2019-10-20 22:57:06 -0700 | [diff] [blame] | 28 | fx_path = os.path.join(fuchsia_root, "scripts/fx") |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 29 | |
| 30 | if args.release_dir: |
| 31 | release_dir = os.path.abspath(args.release_dir) |
| 32 | else: |
| 33 | release_dir = os.path.join(fuchsia_root, "out/default") |
| 34 | |
| 35 | if not os.path.exists(release_dir): |
| 36 | print "Release dir: %s doesn't exist" % release_dir |
| 37 | sys.exit(1) |
| 38 | |
| 39 | if args.arch: |
| 40 | arch = args.arch |
| 41 | else: |
| 42 | arch = "x64" |
| 43 | |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 44 | target_name = "%s-shared/libvulkan_goldfish.so" % arch |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 45 | git_repo_location = "%s/third_party/goldfish-opengl" % fuchsia_root |
| 46 | package_dir = "libvulkan_goldfish/%s" % arch |
| 47 | package_name = "fuchsia/lib/libvulkan/%s" % package_dir |
| 48 | |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 49 | debug_target_name = "%s-shared/lib.unstripped/libvulkan_goldfish.so" % arch |
| 50 | debug_dir = "libvulkan_goldfish/debug-symbols-%s" % arch |
| 51 | debug_package_name = "fuchsia/lib/libvulkan/%s" % debug_dir |
| 52 | |
Yilong Li | 97ac297 | 2019-10-20 22:57:06 -0700 | [diff] [blame] | 53 | repo_name = "goldfish-opengl" |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 54 | git_branch = subprocess.check_output([ |
| 55 | "git", "-C", git_repo_location, "rev-parse", "--abbrev-ref", "HEAD" |
| 56 | ]).strip() |
| 57 | if git_branch != "master": |
| 58 | print("Git repo %s on incorrect branch %s (should be master)" % |
| 59 | (repo_name, git_branch)) |
| 60 | if args.ignore_branch: |
| 61 | print("Ignoring") |
| 62 | else: |
| 63 | print("Use --ignore-branch flag to upload anyway") |
| 64 | sys.exit(1) |
| 65 | |
| 66 | # Force ninja dry-run |
| 67 | ninja_output = subprocess.check_output([ |
Yilong Li | 97ac297 | 2019-10-20 22:57:06 -0700 | [diff] [blame] | 68 | fx_path, "ninja", "-C", release_dir, "-v", "-n", target_name |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 69 | ]) |
| 70 | |
| 71 | if "ninja: no work to do." not in ninja_output: |
| 72 | print("Ninja reported work needed to be done for %s" % target_name) |
| 73 | if args.ignore_rebuild: |
| 74 | print("Ignoring") |
| 75 | else: |
| 76 | print("Use --ignore-rebuild flag to upload anyway") |
| 77 | sys.exit(1) |
| 78 | |
| 79 | gn_output = subprocess.check_output([ |
Yilong Li | 97ac297 | 2019-10-20 22:57:06 -0700 | [diff] [blame] | 80 | fx_path, "gn", "args", release_dir, "--list=is_debug", "--short" |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 81 | ]).strip() |
| 82 | if gn_output != "is_debug = false": |
| 83 | print("GN argument \"%s\" unexpected" % gn_output) |
| 84 | if args.ignore_buildtype: |
| 85 | print("Ignoring") |
| 86 | else: |
| 87 | print("Use --ignore-buildtype flag to upload anyway") |
| 88 | sys.exit(1) |
| 89 | |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 90 | # Prepare libvulkan_goldfish binaries |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 91 | file_name = "libvulkan_goldfish.so" |
| 92 | full_name = os.path.join(package_dir, file_name) |
| 93 | |
| 94 | source_file_name = os.path.join(release_dir, target_name) |
| 95 | try: |
| 96 | os.remove(full_name) |
| 97 | except: |
| 98 | pass |
Craig Stout | 649009c | 2019-11-14 14:05:10 -0800 | [diff] [blame] | 99 | try: |
| 100 | os.makedirs(package_dir) |
| 101 | except: |
| 102 | pass |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 103 | shutil.copyfile(source_file_name, full_name) |
| 104 | |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 105 | # Prepare libvulkan_goldfish debug binaries |
| 106 | debug_source_file_name = os.path.join(release_dir, debug_target_name) |
| 107 | elf_info = re.search(r'Build ID: ([a-f0-9]*)', |
| 108 | subprocess.check_output(['readelf', '-n', debug_source_file_name]).strip()) |
| 109 | if not elf_info: |
| 110 | print("Fatal: Cannot find build ID in elf binary") |
| 111 | sys.exit(1) |
| 112 | |
| 113 | build_id = elf_info.group(1) |
Yilong Li | 6906412 | 2020-07-09 17:42:33 -0700 | [diff] [blame] | 114 | debug_output_dir = os.path.join(debug_dir, build_id[:2]) |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 115 | |
| 116 | try: |
| 117 | shutil.rmtree(debug_dir) |
| 118 | except: |
| 119 | pass |
| 120 | os.makedirs(debug_output_dir) |
| 121 | shutil.copyfile(debug_source_file_name, os.path.join(debug_output_dir, build_id[2:] + '.debug')) |
| 122 | |
| 123 | # Create libvulkan_goldfish CIPD package |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 124 | git_rev = subprocess.check_output( |
| 125 | ["git", "-C", git_repo_location, "rev-parse", "HEAD"]).strip() |
| 126 | |
David Reveman | bc448e3 | 2019-10-23 15:09:35 -0400 | [diff] [blame] | 127 | cipd_command = ("%s cipd create -in %s -name %s -ref latest" |
Yilong Li | 97ac297 | 2019-10-20 22:57:06 -0700 | [diff] [blame] | 128 | " -install-mode copy -tag git_revision:%s") % ( |
| 129 | fx_path, package_dir, package_name, git_rev) |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 130 | print cipd_command |
| 131 | if not args.dry_run: |
| 132 | subprocess.check_call(cipd_command.split(" ")) |
| 133 | |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 134 | # Create libvulkan_goldfish/debug-symbols package |
| 135 | cipd_command = ("%s cipd create -in %s -name %s -ref latest" |
| 136 | " -install-mode copy -tag git_revision:%s") % ( |
| 137 | fx_path, debug_dir, debug_package_name, git_rev) |
| 138 | print cipd_command |
| 139 | if not args.dry_run: |
| 140 | subprocess.check_call(cipd_command.split(" ")) |
| 141 | |
| 142 | |
David Reveman | 9705efe | 2019-05-06 11:44:47 -0400 | [diff] [blame] | 143 | print (""" |
| 144 | <package name="%s" |
| 145 | version="git_revision:%s" |
Yilong Li | 7464a44 | 2020-04-16 01:24:13 -0700 | [diff] [blame] | 146 | path="prebuilt/third_party/%s"/> |
David Reveman | f1093da | 2019-05-23 18:08:39 -0400 | [diff] [blame] | 147 | """ % (package_name, git_rev, package_dir))[1:-1] |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 148 | print (""" |
| 149 | <package name="%s" |
| 150 | version="git_revision:%s" |
Yilong Li | 6906412 | 2020-07-09 17:42:33 -0700 | [diff] [blame] | 151 | path="prebuilt/.build-id" |
Yilong Li | fcceb3c | 2020-07-08 17:58:12 -0700 | [diff] [blame] | 152 | attributes="debug-symbols,debug-symbols-%s"/> |
Yilong Li | 6906412 | 2020-07-09 17:42:33 -0700 | [diff] [blame] | 153 | """ % (debug_package_name, git_rev, arch))[1:-1] |