Skip to content

Commit 21d0c37

Browse files
authored
Verbose output on CI from download_dart_sdk.py (flutter#27484)
1 parent cf524b4 commit 21d0c37

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

tools/download_dart_sdk.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ def ArchitecturesForOS(os_name):
6868

6969

7070
# Downloads a Dart SDK to //flutter/prebuilts.
71-
def DownloadDartSDK(channel, version, os_name, arch):
71+
def DownloadDartSDK(channel, version, os_name, arch, verbose):
7272
file = 'dartsdk-{}-{}-release.zip'.format(os_name, arch)
7373
url = 'https://storage.googleapis.com/dart-archive/channels/{}/raw/{}/sdk/{}'.format(
7474
channel, version, file,
7575
)
7676
dest = os.path.join(FLUTTER_PREBUILTS_DIR, file)
7777

78+
if verbose:
79+
print('Dart SDK url: "%s"' % url)
80+
print('Dart SDK destination path: "%s"' % dest)
81+
7882
stamp_file = '{}.stamp'.format(dest)
7983
version_stamp = None
8084
try:
@@ -83,22 +87,40 @@ def DownloadDartSDK(channel, version, os_name, arch):
8387
except:
8488
version_stamp = 'none'
8589

90+
if verbose:
91+
print('Dart SDK version stamp = "%s"' % version_stamp)
92+
8693
if version == version_stamp:
8794
# The prebuilt Dart SDK is already up-to-date. Indicate that the download
8895
# should be skipped by returning the empty string.
96+
if verbose:
97+
print('Dart SDK stamp files match. Skipping download.')
8998
return ''
9099

91100
if os.path.isfile(dest):
92101
os.unlink(dest)
93102

94-
curl_command = ['curl', url, '-o', dest]
103+
curl_command = [
104+
'curl',
105+
'--retry', '3',
106+
'--continue-at', '-', '--location',
107+
'--output', dest,
108+
url,
109+
]
110+
if verbose:
111+
curl_command.append('--verbose')
112+
print('Running: "%s"' % (' '.join(curl_command)))
95113
curl_result = subprocess.run(
96114
curl_command,
97115
stdout=subprocess.PIPE,
98116
stderr=subprocess.PIPE,
99117
universal_newlines=True,
100118
)
101-
if curl_result.returncode != 0:
119+
if curl_result.returncode == 0 and verbose:
120+
print('curl output:stdout:\n{}\nstderr:\n{}'.format(
121+
curl_result.stdout, curl_result.stderr,
122+
))
123+
elif curl_result.returncode != 0:
102124
eprint('Failed to download: stdout:\n{}\nstderr:\n{}'.format(
103125
curl_result.stdout, curl_result.stderr,
104126
))
@@ -122,7 +144,7 @@ def _extract_member(self, member, targetpath, pwd):
122144

123145

124146
# Extracts a Dart SDK in //fluter/prebuilts
125-
def ExtractDartSDK(archive, os_name, arch):
147+
def ExtractDartSDK(archive, os_name, arch, verbose):
126148
os_arch = '{}-{}'.format(os_name, arch)
127149
dart_sdk = os.path.join(FLUTTER_PREBUILTS_DIR, os_arch, 'dart-sdk')
128150
if os.path.isdir(dart_sdk):
@@ -131,17 +153,25 @@ def ExtractDartSDK(archive, os_name, arch):
131153
extract_dest = os.path.join(FLUTTER_PREBUILTS_DIR, os_arch)
132154
os.makedirs(extract_dest, exist_ok=True)
133155

156+
if verbose:
157+
print('Extracting "%s" to "%s"' % (archive, extract_dest))
158+
134159
with ZipFileWithPermissions(archive, "r") as z:
135160
z.extractall(extract_dest)
136161

137162

138-
def DownloadAndExtract(channel, version, os_name, arch):
139-
archive = DownloadDartSDK(channel, version, os_name, arch)
163+
164+
def DownloadAndExtract(channel, version, os_name, arch, verbose):
165+
archive = DownloadDartSDK(channel, version, os_name, arch, verbose)
140166
if archive == None:
141167
return 1
142168
if archive == '':
143169
return 0
144-
ExtractDartSDK(archive, os_name, arch)
170+
try:
171+
ExtractDartSDK(archive, os_name, arch, verbose)
172+
except Exception as e:
173+
eprint('Failed to extract Dart SDK archive:\n%s' % e)
174+
return 1
145175
try:
146176
stamp_file = '{}.stamp'.format(archive)
147177
with open(stamp_file, "w") as fd:
@@ -157,13 +187,21 @@ def Main():
157187
parser.add_argument(
158188
'--fail-loudly',
159189
action='store_true',
160-
default=False,
190+
default='LUCI_CONTEXT' in os.environ,
161191
help="Return an error code if a prebuilt couldn't be fetched and extracted")
192+
parser.add_argument(
193+
'--verbose',
194+
action='store_true',
195+
default='LUCI_CONTEXT' in os.environ,
196+
help='Emit verbose output')
162197
args = parser.parse_args()
163198
fail_loudly = 1 if args.fail_loudly else 0
199+
verbose = args.verbose
164200

165201
prebuilt_enabled = os.environ.get(FLUTTER_PREBUILTS_ENV_VAR, 'false')
166202
if prebuilt_enabled == '0' or prebuilt_enabled.lower() == 'false':
203+
if verbose:
204+
print('Skipping prebuild Dart SDK download.')
167205
return 0
168206

169207
os.makedirs(FLUTTER_PREBUILTS_DIR, exist_ok=True)
@@ -172,14 +210,20 @@ def Main():
172210
# Dart SDK version.
173211
version = utils.ReadVersionFile()
174212
if version == None:
213+
eprint('Failed to read the Dart VERSION file.')
175214
return fail_loudly
176215
channel = version.channel
216+
if verbose:
217+
print('Dart SDK channel = "%s".' % channel)
177218

178219
# A short Dart SDK version string used in the download url.
179220
if channel == 'be':
180221
dart_git_rev = utils.GetGitRevision()
181222
semantic_version = 'hash/{}'.format(dart_git_rev)
182-
semantic_version = utils.GetSemanticSDKVersion()
223+
else:
224+
semantic_version = utils.GetSemanticSDKVersion()
225+
if verbose:
226+
print('Semantic Dart SDK version = "%s".' % semantic_version)
183227

184228
os_name = GuessOS()
185229
if os_name == None:
@@ -191,7 +235,7 @@ def Main():
191235

192236
# Download and extract variants in parallel
193237
pool = multiprocessing.Pool()
194-
tasks = [(channel, semantic_version, os_name, arch) for arch in architectures]
238+
tasks = [(channel, semantic_version, os_name, arch, verbose) for arch in architectures]
195239
async_results = [pool.apply_async(DownloadAndExtract, t) for t in tasks]
196240
success = True
197241
for async_result in async_results:

0 commit comments

Comments
 (0)