Flutter Engine
The Flutter Engine
Functions | Variables
download_fuchsia_sdk Namespace Reference

Functions

def eprint (*args, **kwargs)
 
def FileNameForSdkPath (sdk_path)
 
def DownloadFuchsiaSDKFromGCS (sdk_path, verbose)
 
def OnErrorRmTree (func, path, exc_info)
 
def ExtractGzipArchive (archive, host_os, verbose)
 
def Main ()
 

Variables

 SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 FUCHSIA_SDK_DIR = os.path.join(SRC_ROOT, 'fuchsia', 'sdk')
 
 FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter')
 

Function Documentation

◆ DownloadFuchsiaSDKFromGCS()

def download_fuchsia_sdk.DownloadFuchsiaSDKFromGCS (   sdk_path,
  verbose 
)

Definition at line 31 of file download_fuchsia_sdk.py.

31def DownloadFuchsiaSDKFromGCS(sdk_path, verbose):
32 file = FileNameForSdkPath(sdk_path)
33 url = 'https://storage.googleapis.com/fuchsia-artifacts/{}'.format(sdk_path)
34 dest = os.path.join(FUCHSIA_SDK_DIR, file)
35
36 if verbose:
37 print('Fuchsia SDK url: "%s"' % url)
38 print('Fuchsia SDK destination path: "%s"' % dest)
39
40 if os.path.isfile(dest):
41 os.unlink(dest)
42
43 # Ensure destination folder exists.
44 os.makedirs(FUCHSIA_SDK_DIR, exist_ok=True)
45 curl_command = [
46 'curl',
47 '--retry',
48 '3',
49 '--continue-at',
50 '-',
51 '--location',
52 '--output',
53 dest,
54 url,
55 ]
56 if verbose:
57 print('Running: "%s"' % (' '.join(curl_command)))
58 curl_result = subprocess.run(
59 curl_command,
60 stdout=subprocess.PIPE,
61 stderr=subprocess.PIPE,
62 universal_newlines=True,
63 )
64 if curl_result.returncode == 0 and verbose:
65 print('curl output:stdout:\n{}\nstderr:\n{}'.format(
66 curl_result.stdout,
67 curl_result.stderr,
68 ))
69 elif curl_result.returncode != 0:
70 eprint(
71 'Failed to download: stdout:\n{}\nstderr:\n{}'.format(
72 curl_result.stdout,
73 curl_result.stderr,
74 )
75 )
76 return None
77
78 return dest
79
80
uint32_t uint32_t * format
def FileNameForSdkPath(sdk_path)
def eprint(*args, **kwargs)
def DownloadFuchsiaSDKFromGCS(sdk_path, verbose)
def print(*args, **kwargs)
Definition: run_tests.py:49
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ eprint()

def download_fuchsia_sdk.eprint ( args,
**  kwargs 
)

Definition at line 23 of file download_fuchsia_sdk.py.

23def eprint(*args, **kwargs):
24 print(*args, file=sys.stderr, **kwargs)
25
26

◆ ExtractGzipArchive()

def download_fuchsia_sdk.ExtractGzipArchive (   archive,
  host_os,
  verbose 
)

Definition at line 100 of file download_fuchsia_sdk.py.

100def ExtractGzipArchive(archive, host_os, verbose):
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)
104
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)
109
110 if verbose:
111 print('Extracting "%s" to "%s"' % (archive, extract_dest))
112
113 with tarfile.open(archive, 'r') as z:
114 z.extractall(extract_dest)
115
116 shutil.move(extract_dest, sdk_dest)
117
118
def ExtractGzipArchive(archive, host_os, verbose)

◆ FileNameForSdkPath()

def download_fuchsia_sdk.FileNameForSdkPath (   sdk_path)

Definition at line 27 of file download_fuchsia_sdk.py.

27def FileNameForSdkPath(sdk_path):
28 return sdk_path.split('/')[-1]
29
30

◆ Main()

def download_fuchsia_sdk.Main ( )

Definition at line 119 of file download_fuchsia_sdk.py.

119def Main():
120 parser = argparse.ArgumentParser()
121 parser.add_argument(
122 '--fail-loudly',
123 action='store_true',
124 default=False,
125 help="Return an error code if a prebuilt couldn't be fetched and extracted"
126 )
127
128 parser.add_argument(
129 '--verbose',
130 action='store_true',
131 default='LUCI_CONTEXT' in os.environ,
132 help='Emit verbose output'
133 )
134
135 parser.add_argument('--host-os', help='The host os')
136
137 parser.add_argument('--fuchsia-sdk-path', help='The path in gcs to the fuchsia sdk to download')
138
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
144
145 if fuchsia_sdk_path is None:
146 eprint('sdk_path can not be empty')
147 return fail_loudly
148
149 archive = DownloadFuchsiaSDKFromGCS(fuchsia_sdk_path, verbose)
150 if archive is None:
151 eprint('Failed to download SDK from %s' % fuchsia_sdk_path)
152 return fail_loudly
153
154 ExtractGzipArchive(archive, host_os, verbose)
155
156 success = True
157 return 0 if success else fail_loudly
158
159

◆ OnErrorRmTree()

def download_fuchsia_sdk.OnErrorRmTree (   func,
  path,
  exc_info 
)
Error handler for ``shutil.rmtree``.

If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it re-raises the error.

Usage : ``shutil.rmtree(path, onerror=onerror)``

Definition at line 81 of file download_fuchsia_sdk.py.

81def OnErrorRmTree(func, path, exc_info):
82 """
83 Error handler for ``shutil.rmtree``.
84
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.
88
89 Usage : ``shutil.rmtree(path, onerror=onerror)``
90 """
91 import stat
92 # Is the error an access error?
93 if not os.access(path, os.W_OK):
94 os.chmod(path, stat.S_IWUSR)
95 func(path)
96 else:
97 raise
98
99
def OnErrorRmTree(func, path, exc_info)

Variable Documentation

◆ FLUTTER_DIR

download_fuchsia_sdk.FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter')

Definition at line 19 of file download_fuchsia_sdk.py.

◆ FUCHSIA_SDK_DIR

download_fuchsia_sdk.FUCHSIA_SDK_DIR = os.path.join(SRC_ROOT, 'fuchsia', 'sdk')

Definition at line 18 of file download_fuchsia_sdk.py.

◆ SRC_ROOT

download_fuchsia_sdk.SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

Definition at line 17 of file download_fuchsia_sdk.py.