7""" Builds all Fuchsia artifacts vended by Flutter.
20from gather_flutter_runner_artifacts
import CreateMetaPackage, CopyPath
21from gen_package
import CreateFarPackage
23_script_dir = os.path.abspath(os.path.join(os.path.realpath(__file__),
'..'))
24_src_root_dir = os.path.join(_script_dir,
'..',
'..',
'..')
25_out_dir = os.path.join(_src_root_dir,
'out',
'ci')
26_bucket_directory = os.path.join(_out_dir,
'fuchsia_bucket')
30 return platform.system() ==
'Linux'
34 return platform.system() ==
'Darwin'
48 return os.path.join(_src_root_dir,
'fuchsia',
'sdk', host_os)
52 host_arch = platform.machine()
54 if host_arch
in [
'x86_64',
'AMD64']:
56 elif host_arch ==
'aarch64':
58 raise Exception(
'Unsupported host architecture: %s' % host_arch)
66 subprocess.check_call(command, cwd=_src_root_dir)
70 print(
'Running gn for variant "%s" with flags: %s' % (variant_dir,
','.
join(flags)))
72 os.path.join(
'flutter',
'tools',
'gn'),
75 assert os.path.exists(os.path.join(_out_dir, variant_dir))
79 assert os.path.exists(os.path.join(_out_dir, variant_dir))
81 print(
'Running autoninja for targets: %s' % targets)
82 RunExecutable([
'autoninja',
'-C', os.path.join(_out_dir, variant_dir)] + targets)
86 if not os.path.exists(path):
89 if os.path.isfile(path)
or os.path.islink(path):
97 shutil.copytree(source, destination)
98 except OSError
as error:
99 if error.errno == errno.ENOTDIR:
100 shutil.copy(source, destination)
106 for root, dirs, files
in os.walk(path):
108 return os.path.join(root, name)
116 dst_path = os.path.join(dest_parent, dst_name)
121 source_root = os.path.join(_out_dir, source)
122 destination_base = os.path.join(destination,
'dart_binaries')
126 'kernel_compiler.dart.snapshot', source_root, destination_base,
'kernel_compiler.snapshot'
129 'frontend_server.dart.snapshot', source_root, destination_base,
130 'flutter_frontend_server.snapshot'
133 'list_libraries.dart.snapshot', source_root, destination_base,
'list_libraries.snapshot'
138 source_root = os.path.join(_out_dir, source)
139 destination_base = os.path.join(destination,
'flutter_binaries')
144 source_root = os.path.join(_out_dir, source)
145 destination_base = os.path.join(destination,
'flutter_binaries')
150 mode =
'aot' if aot
else 'jit'
151 product_suff =
'_product' if product
else ''
152 runner_name =
'%s_%s%s_runner' % (runner_type, mode, product_suff)
153 far_dir_name =
'%s_far' % runner_name
154 source_root = os.path.join(_out_dir, source)
155 far_base = os.path.join(source_root, far_dir_name)
158 key_path = os.path.join(_script_dir,
'development.key')
160 destination = os.path.join(_bucket_directory, destination, mode)
162 patched_sdk_dirname =
'%s_runner_patched_sdk' % runner_type
163 patched_sdk_dir = os.path.join(source_root, patched_sdk_dirname)
164 dest_sdk_path = os.path.join(destination, patched_sdk_dirname)
165 if not os.path.exists(dest_sdk_path):
166 CopyPath(patched_sdk_dir, dest_sdk_path)
181 filename = os.path.join(os.path.dirname(__file__),
'../../build/config/fuchsia/gn_configs.gni')
182 with open(filename)
as f:
184 if line.startswith(
'fuchsia_target_api_level'):
185 return line.split(
'=')[-1].strip()
186 assert False,
'No fuchsia_target_api_level found in //flutter/build/config/fuchsia/gn_configs.gni'
191 deps_bucket_path = os.path.join(_bucket_directory, dst)
192 if not os.path.exists(deps_bucket_path):
193 FindFileAndCopyTo(
'VkLayer_khronos_validation.json',
'%s/pkg' % (sdk_path), deps_bucket_path)
195 'VkLayer_khronos_validation.so',
'%s/arch/%s' % (sdk_path, arch), deps_bucket_path
200 source_root = os.path.join(_out_dir, src)
201 deps_bucket_path = os.path.join(_bucket_directory, dst)
206 unopt =
"_unopt" if not optimized
else ""
208 out_dir =
'fuchsia_%s%s_%s/' % (runtime_mode, unopt, arch)
209 bucket_dir =
'flutter/%s/%s%s/' % (arch, runtime_mode, unopt)
210 deps_dir =
'flutter/%s/deps/' % (arch)
218 cipd_yaml = os.path.join(_script_dir,
'fuchsia.cipd.yaml')
219 CopyFiles(cipd_yaml, os.path.join(_bucket_directory,
'fuchsia.cipd.yaml'))
223 bucket_root = os.path.join(_bucket_directory,
'flutter')
224 licenses_root = os.path.join(_src_root_dir,
'flutter/ci/licenses_golden')
225 license_files = [
'licenses_flutter',
'licenses_fuchsia',
'licenses_skia']
226 for license
in license_files:
227 src_path = os.path.join(licenses_root, license)
228 dst_path = os.path.join(bucket_root, license)
233 '''Check to see if the current package/tag combo has been published'''
241 stdout = subprocess.check_output(command)
243 stdout = stdout
if isinstance(stdout, str)
else stdout.decode(
'UTF-8')
244 match = re.search(
r'No matching instances\.', stdout)
256 for tries
in range(num_tries):
258 subprocess.check_call(command, cwd=_bucket_directory)
260 except subprocess.CalledProcessError:
261 print(
'Failed %s times' % tries + 1)
262 if tries == num_tries - 1:
267 if not upload
or not IsLinux():
269 'cipd',
'pkg-build',
'-pkg-def',
'fuchsia.cipd.yaml',
'-out',
270 os.path.join(_bucket_directory,
'fuchsia.cipd')
278 if engine_version
is None:
279 print(
'--upload requires --engine-version to be specified.')
282 tag =
'git_revision:%s' % engine_version
285 print(
'CIPD package flutter/fuchsia tag %s already exists!' % tag)
301 runtime_mode, arch, optimized, enable_lto, enable_legacy, asan, dart_version_git_info,
302 prebuilt_dart_sdk, build_targets
304 unopt =
"_unopt" if not optimized
else ""
305 out_dir =
'fuchsia_%s%s_%s' % (runtime_mode, unopt, arch)
315 flags.append(
'--unoptimized')
317 flags.append(
'--no-lto')
318 if not enable_legacy:
319 flags.append(
'--no-fuchsia-legacy')
321 flags.append(
'--asan')
322 if not dart_version_git_info:
323 flags.append(
'--no-dart-version-git-info')
324 if not prebuilt_dart_sdk:
325 flags.append(
'--no-prebuilt-dart-sdk')
327 RunGN(out_dir, flags)
334 parser = argparse.ArgumentParser()
340 help=
'If set, creates the CIPD package but does not upload it.'
347 help=
'If set, uploads the CIPD package and tags it as the latest.'
350 parser.add_argument(
'--engine-version', required=
False, help=
'Specifies the flutter engine SHA.')
356 help=
'If set, disables compiler optimization for the build.'
360 '--runtime-mode', type=str, choices=[
'debug',
'profile',
'release',
'all'], default=
'all'
363 parser.add_argument(
'--archs', type=str, choices=[
'x64',
'arm64',
'all'], default=
'all')
369 help=
'If set, enables address sanitization (including leak sanitization) for the build.'
373 '--no-lto', action=
'store_true', default=
False, help=
'If set, disables LTO for the build.'
380 help=
'If set, disables legacy code for the build.'
387 help=
'If set, skips building and just creates packages.'
393 help=(
'Comma-separated list; adds additional targets to build for '
398 '--no-dart-version-git-info',
401 help=
'If set, turns off the Dart SDK git hash check.'
405 '--no-prebuilt-dart-sdk',
408 help=
'If set, builds the Dart SDK locally instead of using the prebuilt Dart SDK.'
412 '--copy-unoptimized-debug-artifacts',
415 help=
'If set, unoptimized debug artifacts will be copied into CIPD along '
416 'with optimized builds. This is a hack to allow infra to make '
417 'and copy two debug builds, one with ASAN and one without.'
422 '--skip-remove-buckets',
425 help=
'This allows for multiple runtimes to exist in the default bucket directory. If '
426 'set, will skip over the removal of existing artifacts in the bucket directory '
427 '(which is the default behavior).'
430 args = parser.parse_args()
431 build_mode = args.runtime_mode
432 if (
not args.skip_remove_buckets):
435 archs = [
'x64',
'arm64']
if args.archs ==
'all' else [args.archs]
436 runtime_modes = [
'debug',
'profile',
'release']
437 product_modes = [
False,
False,
True]
439 optimized =
not args.unoptimized
440 enable_lto =
not args.no_lto
441 enable_legacy =
not args.no_legacy
445 for i
in range(
len(runtime_modes)):
446 runtime_mode = runtime_modes[i]
447 product = product_modes[i]
448 if build_mode ==
'all' or runtime_mode == build_mode:
449 if not args.skip_build:
451 runtime_mode, arch, optimized, enable_lto, enable_legacy, args.asan,
452 not args.no_dart_version_git_info,
not args.no_prebuilt_dart_sdk,
453 args.targets.split(
",")
if args.targets
else [
'flutter']
465 if args.copy_unoptimized_debug_artifacts
and runtime_mode ==
'debug' and optimized:
470 should_upload = args.upload
471 engine_version = args.engine_version
472 if not engine_version:
473 engine_version =
'HEAD'
474 should_upload =
False
477 if args.cipd_dry_run
or args.upload:
483if __name__ ==
'__main__':
SkPath CopyPath(const SkPath &a)
def CopyVulkanDepsToBucket(src, dst, arch)
def RunExecutable(command)
def RunCIPDCommandWithRetries(command)
def RemoveDirectoryIfExists(path)
def BuildNinjaTargets(variant_dir, targets)
def CheckCIPDPackageExists(package_name, tag)
def GetHostArchFromPlatform()
def FindFileAndCopyTo(file_name, source, dest_parent, dst_name=None)
def CopyToBucketWithMode(source, destination, aot, product, runner_type, api_level)
def CopyToBucket(src, dst, product=False)
def ProcessCIPDPackage(upload, engine_version)
def CopyBuildToBucket(runtime_mode, arch, optimized, product)
def CopyZirconFFILibIfExists(source, destination)
def CopyFlutterTesterBinIfExists(source, destination)
def CopyFiles(source, destination)
def RunGN(variant_dir, flags)
def BuildTarget(runtime_mode, arch, optimized, enable_lto, enable_legacy, asan, dart_version_git_info, prebuilt_dart_sdk, build_targets)
def CopyIcuDepsToBucket(src, dst)
def CopyGenSnapshotIfExists(source, destination)
def CreateMetaPackage(dst_root, far_name)
def CreateFarPackage(pm_bin, package_dir, signing_key, dst_dir, api_level)
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)