blob: 550070d377bbe8efe221db11fd2df2e9988fd8a0 [file] [log] [blame]
David Reveman9705efe2019-05-06 11:44:47 -04001# 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
5import os
6import sys
7import shutil
8import subprocess
9import argparse
10import re
11
12parser = argparse.ArgumentParser(description="Upload goldfish libvulkan to CIPD")
13
14parser.add_argument("--release-dir")
15parser.add_argument("--arch")
16parser.add_argument("--dry-run", action="store_true")
17parser.add_argument("--ignore-branch", action="store_true")
18parser.add_argument("--ignore-rebuild", action="store_true")
19parser.add_argument("--ignore-buildtype", action="store_true")
20
21args = parser.parse_args()
22
23dir_path = os.path.dirname(os.path.realpath(__file__))
24
25os.chdir(dir_path)
26
27fuchsia_root = os.path.abspath(os.path.join(dir_path, "../../../"))
Yilong Li97ac2972019-10-20 22:57:06 -070028fx_path = os.path.join(fuchsia_root, "scripts/fx")
David Reveman9705efe2019-05-06 11:44:47 -040029
30if args.release_dir:
31 release_dir = os.path.abspath(args.release_dir)
32else:
33 release_dir = os.path.join(fuchsia_root, "out/default")
34
35if not os.path.exists(release_dir):
36 print "Release dir: %s doesn't exist" % release_dir
37 sys.exit(1)
38
39if args.arch:
40 arch = args.arch
41else:
42 arch = "x64"
43
Yilong Lifcceb3c2020-07-08 17:58:12 -070044target_name = "%s-shared/libvulkan_goldfish.so" % arch
David Reveman9705efe2019-05-06 11:44:47 -040045git_repo_location = "%s/third_party/goldfish-opengl" % fuchsia_root
46package_dir = "libvulkan_goldfish/%s" % arch
47package_name = "fuchsia/lib/libvulkan/%s" % package_dir
48
Yilong Lifcceb3c2020-07-08 17:58:12 -070049debug_target_name = "%s-shared/lib.unstripped/libvulkan_goldfish.so" % arch
50debug_dir = "libvulkan_goldfish/debug-symbols-%s" % arch
51debug_package_name = "fuchsia/lib/libvulkan/%s" % debug_dir
52
Yilong Li97ac2972019-10-20 22:57:06 -070053repo_name = "goldfish-opengl"
David Reveman9705efe2019-05-06 11:44:47 -040054git_branch = subprocess.check_output([
55 "git", "-C", git_repo_location, "rev-parse", "--abbrev-ref", "HEAD"
56]).strip()
57if 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
67ninja_output = subprocess.check_output([
Yilong Li97ac2972019-10-20 22:57:06 -070068 fx_path, "ninja", "-C", release_dir, "-v", "-n", target_name
David Reveman9705efe2019-05-06 11:44:47 -040069])
70
71if "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
79gn_output = subprocess.check_output([
Yilong Li97ac2972019-10-20 22:57:06 -070080 fx_path, "gn", "args", release_dir, "--list=is_debug", "--short"
David Reveman9705efe2019-05-06 11:44:47 -040081]).strip()
82if 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 Lifcceb3c2020-07-08 17:58:12 -070090# Prepare libvulkan_goldfish binaries
David Reveman9705efe2019-05-06 11:44:47 -040091file_name = "libvulkan_goldfish.so"
92full_name = os.path.join(package_dir, file_name)
93
94source_file_name = os.path.join(release_dir, target_name)
95try:
96 os.remove(full_name)
97except:
98 pass
Craig Stout649009c2019-11-14 14:05:10 -080099try:
100 os.makedirs(package_dir)
101except:
102 pass
David Reveman9705efe2019-05-06 11:44:47 -0400103shutil.copyfile(source_file_name, full_name)
104
Yilong Lifcceb3c2020-07-08 17:58:12 -0700105# Prepare libvulkan_goldfish debug binaries
106debug_source_file_name = os.path.join(release_dir, debug_target_name)
107elf_info = re.search(r'Build ID: ([a-f0-9]*)',
108 subprocess.check_output(['readelf', '-n', debug_source_file_name]).strip())
109if not elf_info:
110 print("Fatal: Cannot find build ID in elf binary")
111 sys.exit(1)
112
113build_id = elf_info.group(1)
Yilong Li69064122020-07-09 17:42:33 -0700114debug_output_dir = os.path.join(debug_dir, build_id[:2])
Yilong Lifcceb3c2020-07-08 17:58:12 -0700115
116try:
117 shutil.rmtree(debug_dir)
118except:
119 pass
120os.makedirs(debug_output_dir)
121shutil.copyfile(debug_source_file_name, os.path.join(debug_output_dir, build_id[2:] + '.debug'))
122
123# Create libvulkan_goldfish CIPD package
David Reveman9705efe2019-05-06 11:44:47 -0400124git_rev = subprocess.check_output(
125 ["git", "-C", git_repo_location, "rev-parse", "HEAD"]).strip()
126
David Revemanbc448e32019-10-23 15:09:35 -0400127cipd_command = ("%s cipd create -in %s -name %s -ref latest"
Yilong Li97ac2972019-10-20 22:57:06 -0700128 " -install-mode copy -tag git_revision:%s") % (
129 fx_path, package_dir, package_name, git_rev)
David Reveman9705efe2019-05-06 11:44:47 -0400130print cipd_command
131if not args.dry_run:
132 subprocess.check_call(cipd_command.split(" "))
133
Yilong Lifcceb3c2020-07-08 17:58:12 -0700134# Create libvulkan_goldfish/debug-symbols package
135cipd_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)
138print cipd_command
139if not args.dry_run:
140 subprocess.check_call(cipd_command.split(" "))
141
142
David Reveman9705efe2019-05-06 11:44:47 -0400143print ("""
144 <package name="%s"
145 version="git_revision:%s"
Yilong Li7464a442020-04-16 01:24:13 -0700146 path="prebuilt/third_party/%s"/>
David Revemanf1093da2019-05-23 18:08:39 -0400147""" % (package_name, git_rev, package_dir))[1:-1]
Yilong Lifcceb3c2020-07-08 17:58:12 -0700148print ("""
149 <package name="%s"
150 version="git_revision:%s"
Yilong Li69064122020-07-09 17:42:33 -0700151 path="prebuilt/.build-id"
Yilong Lifcceb3c2020-07-08 17:58:12 -0700152 attributes="debug-symbols,debug-symbols-%s"/>
Yilong Li69064122020-07-09 17:42:33 -0700153""" % (debug_package_name, git_rev, arch))[1:-1]