[fuchsia] Use GatherArtifacts to create the requisite dir structure (flutter/engine#10004)

* [fuchsia] Create command to gather fuchsia artifacts

- We will use this gathered artifacts to create the
  directory tree that we will package to a far.

- Currently this is not used anywhere, we will use it
  as such:
  	1. Build all the fuchsia artifacts
	2. Gather the artifacts to a directory
	3. Use `pm` to package up the directory into a far.

* reformat files

* commit chromium style

* [fuchsia] Use the directory format that fuchsia expects

* Farify the artifacts

* Create far archives and have tmp artifact dir
This commit is contained in:
Kaushik Iska
2019-07-22 13:59:46 -07:00
committed by GitHub
parent 8be5805dff
commit 4989a8919d
6 changed files with 212 additions and 105 deletions

View File

@@ -0,0 +1,2 @@
[style]
based_on_style = chromium

View File

@@ -3,7 +3,6 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Builds all Fuchsia artifacts vended by Flutter.
"""
@@ -14,18 +13,43 @@ import platform
import shutil
import subprocess
import sys
import tempfile
from gather_flutter_runner_artifacts import GatherArtifacts
from gen_package import CreateFarPackage
_script_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..'))
_src_root_dir = os.path.join(_script_dir, '..', '..', '..')
_out_dir = os.path.join(_src_root_dir, 'out')
_bucket_directory = os.path.join(_out_dir, 'fuchsia_bucket')
def IsLinux():
return platform.system() == 'Linux'
def IsMac():
return platform.system() == 'Darwin'
def GetPMBinPath():
# host_os references the gn host_os
# https://gn.googlesource.com/gn/+/master/docs/reference.md#var_host_os
host_os = ''
if IsLinux():
host_os = 'linux'
elif IsMac():
host_os = 'mac'
else:
host_os = 'windows'
return os.path.join(_src_root_dir, 'fuchsia', 'sdk', host_os, 'tools', 'pm')
def RunExecutable(command):
subprocess.check_call(command, cwd=_src_root_dir)
def RunGN(variant_dir, flags):
RunExecutable([
os.path.join('flutter', 'tools', 'gn'),
@@ -33,14 +57,12 @@ def RunGN(variant_dir, flags):
assert os.path.exists(os.path.join(_out_dir, variant_dir))
def BuildNinjaTargets(variant_dir, targets):
assert os.path.exists(os.path.join(_out_dir, variant_dir))
RunExecutable([
'autoninja',
'-C',
os.path.join(_out_dir, variant_dir)
] + targets)
RunExecutable(['autoninja', '-C',
os.path.join(_out_dir, variant_dir)] + targets)
def RemoveDirectoryIfExists(path):
@@ -52,41 +74,26 @@ def RemoveDirectoryIfExists(path):
else:
shutil.rmtree(path)
def CopyFiles(source, destination):
try:
shutil.copytree(source, destination)
except OSError as error:
if error.errno == errno.ENOTDIR:
shutil.copy(source, destination)
else:
raise
def CopyToBucket(source, destination):
source = os.path.join(_out_dir, source)
temp_artifact_dir = tempfile.mkdtemp()
GatherArtifacts(source, temp_artifact_dir)
pm_bin = GetPMBinPath()
key_path = os.path.join(_script_dir, 'development.key')
destination = os.path.join(_bucket_directory, destination)
CreateFarPackage(pm_bin, temp_artifact_dir, key_path, destination)
assert os.path.exists(source), '"%s" does not exist!' % source
CopyFiles(source, destination)
def BuildBucket():
RemoveDirectoryIfExists(_bucket_directory)
CopyToBucket('fuchsia_debug/flutter_patched_sdk', 'flutter/debug/flutter_patched_sdk')
CopyToBucket('fuchsia_profile/flutter_patched_sdk', 'flutter/profile/flutter_patched_sdk')
CopyToBucket('fuchsia_release/flutter_patched_sdk', 'flutter/release/flutter_patched_sdk')
CopyToBucket('fuchsia_debug/', 'flutter/debug/')
CopyToBucket('fuchsia_profile/', 'flutter/profile/')
CopyToBucket('fuchsia_release/', 'flutter/release/')
CopyToBucket('fuchsia_debug/flutter_runner', 'flutter/debug/flutter_runner')
CopyToBucket('fuchsia_profile/flutter_runner', 'flutter/profile/flutter_runner')
CopyToBucket('fuchsia_release/flutter_runner', 'flutter/release/flutter_runner')
CopyToBucket('fuchsia_debug/dart_runner', 'flutter/debug/dart_runner')
CopyToBucket('fuchsia_profile/dart_runner', 'flutter/profile/dart_runner')
CopyToBucket('fuchsia_release/dart_runner', 'flutter/release/dart_runner')
CopyToBucket('fuchsia_debug/icudtl.dat', 'flutter/debug/icudtl.dat')
CopyToBucket('fuchsia_profile/icudtl.dat', 'flutter/profile/icudtl.dat')
CopyToBucket('fuchsia_release/icudtl.dat', 'flutter/release/icudtl.dat')
def ProcessCIPDPakcage(upload, engine_version):
# Copy the CIPD YAML template from the source directory to be next to the bucket
@@ -96,68 +103,56 @@ def ProcessCIPDPakcage(upload, engine_version):
if upload and IsLinux():
command = [
'cipd',
'create',
'-pkg-def',
'fuchsia.cipd.yaml',
'-ref',
'latest',
'-tag',
'git_revision:%s' % engine_version
'cipd', 'create', '-pkg-def', 'fuchsia.cipd.yaml', '-ref', 'latest',
'-tag',
'git_revision:%s' % engine_version
]
else:
command = [
'cipd',
'pkg-build',
'-pkg-def',
'fuchsia.cipd.yaml',
'-out',
os.path.join(_bucket_directory, 'fuchsia.cipd')
'cipd', 'pkg-build', '-pkg-def', 'fuchsia.cipd.yaml', '-out',
os.path.join(_bucket_directory, 'fuchsia.cipd')
]
subprocess.check_call(command, cwd=_bucket_directory)
def main():
parser = argparse.ArgumentParser();
parser.add_argument('--upload', default=False, action='store_true',
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--upload',
default=False,
action='store_true',
help='If set, uploads the CIPD package and tags it as the latest.')
parser.add_argument('--engine-version', required=True,
parser.add_argument(
'--engine-version',
required=True,
help='Specifies the flutter engine SHA.')
args = parser.parse_args()
common_flags = [
'--fuchsia',
# The source does not require LTO and LTO is not wired up for targets.
'--no-lto',
'--fuchsia',
# The source does not require LTO and LTO is not wired up for targets.
'--no-lto',
]
RunGN('fuchsia_debug', common_flags + [
'--runtime-mode',
'debug'
]);
RunGN('fuchsia_debug', common_flags + ['--runtime-mode', 'debug'])
RunGN('fuchsia_profile', common_flags + [
'--runtime-mode',
'profile'
]);
RunGN('fuchsia_profile', common_flags + ['--runtime-mode', 'profile'])
RunGN('fuchsia_release', common_flags + [
'--runtime-mode',
'release'
]);
RunGN('fuchsia_release', common_flags + ['--runtime-mode', 'release'])
targets_to_build = [
# The Flutter Runner.
'flutter/shell/platform/fuchsia/flutter:flutter',
# The Flutter Runner.
'flutter/shell/platform/fuchsia/flutter:flutter',
# The Dart Runner.
'flutter/shell/platform/fuchsia/dart:dart',
# The Dart Runner.
'flutter/shell/platform/fuchsia/dart:dart',
# The Snapshots.
'flutter/lib/snapshot:snapshot',
# The Snapshots.
'flutter/lib/snapshot:snapshot',
]
BuildNinjaTargets('fuchsia_debug', targets_to_build)
@@ -171,4 +166,3 @@ def main():
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,92 @@
#!/usr/bin/env python
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Gather all the fuchsia artifacts to a destination directory.
"""
import argparse
import errno
import json
import os
import platform
import shutil
import subprocess
import sys
_ARTIFACT_PATH_TO_DST = {
'flutter_runner': 'flutter_runner',
'icudtl.dat': 'data/icudtl.dat',
'dart_runner': 'dart_runner',
'flutter_patched_sdk': 'flutter_patched_sdk'
}
def EnsureParentExists(path):
dir_name, _ = os.path.split(path)
if not os.path.exists(dir_name):
os.makedirs(dir_name)
def CopyPath(src, dst):
try:
EnsureParentExists(dst)
shutil.copytree(src, dst)
except OSError as exc:
if exc.errno == errno.ENOTDIR:
shutil.copy(src, dst)
else:
raise
def CreateMetaPackage(dst_root):
meta = os.path.join(dst_root, 'meta')
if not os.path.isdir(meta):
os.makedirs(meta)
content = {}
content['name'] = 'flutter_runner'
content['version'] = '0.0.1'
package = os.path.join(meta, 'package')
with open(package, 'w') as out_file:
json.dump(content, out_file)
def GatherArtifacts(src_root, dst_root, create_meta_package=True):
if not os.path.exists(dst_root):
os.makedirs(dst_root)
else:
shutil.rmtree(dst_root)
for src_rel, dst_rel in _ARTIFACT_PATH_TO_DST.iteritems():
src_full = os.path.join(src_root, src_rel)
dst_full = os.path.join(dst_root, dst_rel)
if not os.path.exists(src_full):
print 'Unable to find artifact: ', str(src_full)
sys.exit(1)
CopyPath(src_full, dst_full)
if create_meta_package:
CreateMetaPackage(dst_root)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--artifacts-root', dest='artifacts_root', action='store', required=True)
parser.add_argument(
'--dest-dir', dest='dst_dir', action='store', required=True)
args = parser.parse_args()
assert os.path.exists(args.artifacts_root)
dst_parent = os.path.abspath(os.path.join(args.dst_dir, os.pardir))
assert os.path.exists(dst_parent)
GatherArtifacts(args.artifacts_root, args.dst_dir)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -3,7 +3,6 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Genrate a Fuchsia FAR Archive from an asset manifest and a signing key.
"""
@@ -14,13 +13,31 @@ import os
import subprocess
import sys
def CreateFarPackage(pm_bin, package_dir, signing_key, dst_dir):
pm_command_base = [
pm_bin, '-m', package_dir, '-k', signing_key, '-o', dst_dir
]
# Build the package
subprocess.check_call(pm_command_base + ['build'])
# Archive the package
subprocess.check_call(pm_command_base + ['archive'])
return 0
def main():
parser = argparse.ArgumentParser();
parser = argparse.ArgumentParser()
parser.add_argument('--pm-bin', dest='pm_bin', action='store', required=True)
parser.add_argument('--package-dir', dest='package_dir', action='store', required=True)
parser.add_argument('--signing-key', dest='signing_key', action='store', required=True)
parser.add_argument('--manifest-file', dest='manifest_file', action='store', required=True)
parser.add_argument(
'--package-dir', dest='package_dir', action='store', required=True)
parser.add_argument(
'--signing-key', dest='signing_key', action='store', required=True)
parser.add_argument(
'--manifest-file', dest='manifest_file', action='store', required=True)
args = parser.parse_args()
@@ -30,22 +47,23 @@ def main():
assert os.path.exists(args.manifest_file)
pm_command_base = [
args.pm_bin,
'-o',
args.package_dir,
'-k',
args.signing_key,
'-m',
args.manifest_file,
args.pm_bin,
'-o',
args.package_dir,
'-k',
args.signing_key,
'-m',
args.manifest_file,
]
# Build the package
subprocess.check_call(pm_command_base + [ 'build' ]);
subprocess.check_call(pm_command_base + ['build'])
# Archive the package
subprocess.check_call(pm_command_base + [ 'archive' ]);
subprocess.check_call(pm_command_base + ['archive'])
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -3,7 +3,6 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Generate a Fuchsia repo capable of serving Fuchsia archives over the
network.
"""
@@ -16,41 +15,39 @@ import sys
def main():
parser = argparse.ArgumentParser();
parser = argparse.ArgumentParser()
parser.add_argument('--pm-bin', dest='pm_bin', action='store', required=True)
parser.add_argument('--repo-dir', dest='repo_dir', action='store', required=True)
parser.add_argument('--archive', dest='archives', action='append', required=True)
parser.add_argument(
'--repo-dir', dest='repo_dir', action='store', required=True)
parser.add_argument(
'--archive', dest='archives', action='append', required=True)
args = parser.parse_args()
assert os.path.exists(args.pm_bin)
if not os.path.exists(args.repo_dir):
pm_newrepo_command = [
args.pm_bin,
'newrepo',
'-repo',
args.repo_dir
]
subprocess.check_call(pm_newrepo_command);
pm_newrepo_command = [args.pm_bin, 'newrepo', '-repo', args.repo_dir]
subprocess.check_call(pm_newrepo_command)
pm_publish_command = [
args.pm_bin,
'publish',
'-C', # Remove all previous registrations.
'-a', # Publish archives from an archive (mode).
'-repo',
args.repo_dir
args.pm_bin,
'publish',
'-C', # Remove all previous registrations.
'-a', # Publish archives from an archive (mode).
'-repo',
args.repo_dir
]
for archive in args.archives:
pm_publish_command.append('-f')
pm_publish_command.append(archive)
pm_publish_command.append('-f')
pm_publish_command.append(archive)
subprocess.check_call(pm_publish_command)
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -367,7 +367,11 @@ def main(argv):
command.append(out_dir)
command.append('--args=%s' % ' '.join(gn_args))
print "Generating GN files in: %s" % out_dir
gn_call_result = subprocess.call(command, cwd=SRC_ROOT)
try:
gn_call_result = subprocess.call(command, cwd=SRC_ROOT)
except subprocess.CalledProcessError as exc:
print "Failed to generate gn files: ", exc.returncode, exc.output
sys.exit(1)
if gn_call_result == 0:
# Generate/Replace the compile commands database in out.