17SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18FUCHSIA_SDK_DIR = os.path.join(SRC_ROOT,
'fuchsia',
'sdk')
19FLUTTER_DIR = os.path.join(SRC_ROOT,
'flutter')
24 print(*args, file=sys.stderr, **kwargs)
28 return sdk_path.split(
'/')[-1]
33 url =
'https://storage.googleapis.com/fuchsia-artifacts/{}'.
format(sdk_path)
34 dest = os.path.join(FUCHSIA_SDK_DIR, file)
37 print(
'Fuchsia SDK url: "%s"' % url)
38 print(
'Fuchsia SDK destination path: "%s"' % dest)
40 if os.path.isfile(dest):
44 os.makedirs(FUCHSIA_SDK_DIR, exist_ok=
True)
57 print(
'Running: "%s"' % (
' '.
join(curl_command)))
58 curl_result = subprocess.run(
60 stdout=subprocess.PIPE,
61 stderr=subprocess.PIPE,
62 universal_newlines=
True,
64 if curl_result.returncode == 0
and verbose:
65 print(
'curl output:stdout:\n{}\nstderr:\n{}'.
format(
69 elif curl_result.returncode != 0:
71 'Failed to download: stdout:\n{}\nstderr:\n{}'.
format(
83 Error handler for ``shutil.rmtree``.
85 If the error
is due to an access error (read only file)
86 it attempts to add write permission
and then retries.
87 If the error
is for another reason it re-raises the error.
89 Usage : ``shutil.rmtree(path, onerror=onerror)``
93 if not os.access(path, os.W_OK):
94 os.chmod(path, stat.S_IWUSR)
101 sdk_dest = os.path.join(FUCHSIA_SDK_DIR, host_os)
102 if os.path.isdir(sdk_dest):
103 shutil.rmtree(sdk_dest, onerror=OnErrorRmTree)
105 extract_dest = os.path.join(FUCHSIA_SDK_DIR,
'temp')
106 if os.path.isdir(extract_dest):
107 shutil.rmtree(extract_dest, onerror=OnErrorRmTree)
108 os.makedirs(extract_dest, exist_ok=
True)
111 print(
'Extracting "%s" to "%s"' % (archive, extract_dest))
113 with tarfile.open(archive,
'r')
as z:
114 z.extractall(extract_dest)
116 shutil.move(extract_dest, sdk_dest)
120 parser = argparse.ArgumentParser()
125 help=
"Return an error code if a prebuilt couldn't be fetched and extracted"
131 default=
'LUCI_CONTEXT' in os.environ,
132 help=
'Emit verbose output'
135 parser.add_argument(
'--host-os', help=
'The host os')
137 parser.add_argument(
'--fuchsia-sdk-path', help=
'The path in gcs to the fuchsia sdk to download')
139 args = parser.parse_args()
140 fail_loudly = 1
if args.fail_loudly
else 0
141 verbose = args.verbose
142 host_os = args.host_os
143 fuchsia_sdk_path = args.fuchsia_sdk_path
145 if fuchsia_sdk_path
is None:
146 eprint(
'sdk_path can not be empty')
151 eprint(
'Failed to download SDK from %s' % fuchsia_sdk_path)
157 return 0
if success
else fail_loudly
160if __name__ ==
'__main__':
uint32_t uint32_t * format
def ExtractGzipArchive(archive, host_os, verbose)
def FileNameForSdkPath(sdk_path)
def eprint(*args, **kwargs)
def OnErrorRmTree(func, path, exc_info)
def DownloadFuchsiaSDKFromGCS(sdk_path, verbose)
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)