Skip to content

Commit

Permalink
Fuchsia: Add support for package dependencies to fuchsia_package_runner.
Browse files Browse the repository at this point in the history
fuchsia_package_runner() targets can now specify multiple packages for
deployment, using the "package_deps" argument.

Bug: 855242
Change-Id: Ib9bb67be14d6b120ea2bf008edd2941d14c36e46
Reviewed-on: https://chromium-review.googlesource.com/1111274
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569907}
  • Loading branch information
Kevin Marshall authored and Commit Bot committed Jun 23, 2018
1 parent 26f26cd commit b63246b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
16 changes: 16 additions & 0 deletions build/config/fuchsia/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ blobstore_qcow_path = "$root_out_dir/fvm.blk.qcow2"
# package: The package() target which will be run.
# package_name_override: Specifies the name of the generated package, if its
# name is different than the |package| target name.
# package_deps: An array of [package, package_name_override] array pairs
# which specify additional dependency packages to be installed
# prior to execution.
# runner_script: The runner script implementation to use, relative to
# "build/fuchsia". Defaults to "exe_runner.py".
template("fuchsia_package_runner") {
Expand Down Expand Up @@ -79,6 +82,19 @@ template("fuchsia_package_runner") {
args += [ "--enable-test-server" ]
}

if (defined(invoker.package_deps)) {
foreach(cur_package, invoker.package_deps) {
deps += [ cur_package[0] ]
dep_package_path =
"$root_out_dir/gen/" + get_label_info(cur_package[0], "dir") + "/" +
cur_package[1] + "/" + cur_package[1] + ".far"
args += [
"--package-dep",
rebase_path(dep_package_path, root_out_dir, root_build_dir),
]
}
}

# Arguments used at runtime by the test runner.
args += [
"--runner-script",
Expand Down
2 changes: 2 additions & 0 deletions build/fuchsia/common_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def AddCommonArgs(arg_parser):
common_args.add_argument('--package-manifest',
type=os.path.realpath, required=True,
help='Path to the Fuchsia package manifest file.')
common_args.add_argument('--package-dep', action='append', default=[],
help='Path to an additional package to install.')
common_args.add_argument('--output-directory',
type=os.path.realpath, required=True,
help=('Path to the directory in which build files '
Expand Down
4 changes: 4 additions & 0 deletions build/fuchsia/create_runner_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def main(args):
group = parser.add_argument_group('Test runner path arguments.')
group.add_argument('--output-directory')
group.add_argument('--package')
group.add_argument('--package-dep', action='append', default=[])
group.add_argument('--package-manifest')
args, runner_args = parser.parse_known_args(args)

Expand All @@ -71,6 +72,9 @@ def RelativizePathToScript(path):
('--output-directory', RelativizePathToScript(args.output_directory)))
runner_path_args.append(
('--package', RelativizePathToScript(args.package)))
for next_package_dep in args.package_dep:
runner_path_args.append(
('--package-dep', RelativizePathToScript(next_package_dep)))
runner_path_args.append(
('--package-manifest', RelativizePathToScript(args.package_manifest)))

Expand Down
3 changes: 2 additions & 1 deletion build/fuchsia/exe_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def main():
target.Start()
return RunPackage(
args.output_directory, target, args.package, args.package_name,
args.child_args, args.include_system_logs, args.package_manifest)
args.package_dep, args.child_args, args.include_system_logs,
args.package_manifest)


if __name__ == '__main__':
Expand Down
39 changes: 19 additions & 20 deletions build/fuchsia/run_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def DrainStreamToStdout(stream, quit_event):
poll.unregister(stream.fileno())


def RunPackage(output_dir, target, package_path, package_name, run_args,
system_logging, symbolizer_config=None):
def RunPackage(output_dir, target, package_path, package_name, package_deps,
run_args, system_logging, symbolizer_config=None):
"""Copies the Fuchsia package at |package_path| to the target,
executes it with |run_args|, and symbolizes its output.
Expand All @@ -102,7 +102,6 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,


system_logger = _AttachKernelLogReader(target) if system_logging else None
package_copied = False
try:
if system_logger:
# Spin up a thread to asynchronously dump the system log to stdout
Expand All @@ -114,21 +113,25 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,
log_output_thread.daemon = True
log_output_thread.start()

logging.info('Copying package to target.')
install_path = os.path.join('/data', os.path.basename(package_path))
target.PutFile(package_path, install_path)
package_copied = True
for next_package_path in ([package_path] + package_deps):
logging.info('Installing ' + os.path.basename(next_package_path) + '.')

logging.info('Installing package.')
p = target.RunCommandPiped(['pm', 'install', install_path],
stderr=subprocess.PIPE)
output = p.stderr.readlines()
p.wait()
# Copy the package archive.
install_path = os.path.join('/data', os.path.basename(next_package_path))
target.PutFile(next_package_path, install_path)

if p.returncode != 0:
# Don't error out if the package already exists on the device.
if len(output) != 1 or 'ErrAlreadyExists' not in output[0]:
raise Exception('Error while installing: %s' % '\n'.join(output))
# Install the package.
p = target.RunCommandPiped(['pm', 'install', install_path],
stderr=subprocess.PIPE)
output = p.stderr.readlines()
p.wait()
if p.returncode != 0:
# Don't error out if the package already exists on the device.
if len(output) != 1 or 'ErrAlreadyExists' not in output[0]:
raise Exception('Error while installing: %s' % '\n'.join(output))

# Clean up the package archive.
target.RunCommand(['rm', install_path])

if system_logger:
log_output_quit_event.set()
Expand Down Expand Up @@ -173,9 +176,5 @@ def RunPackage(output_dir, target, package_path, package_name, run_args,
log_output_thread.join()
system_logger.kill()

if package_copied:
logging.info('Removing package source from device.')
target.RunCommand(['rm', install_path])


return process.returncode
3 changes: 2 additions & 1 deletion build/fuchsia/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def main():

returncode = RunPackage(
args.output_directory, target, args.package, args.package_name,
child_args, args.include_system_logs, args.package_manifest)
args.package_dep, child_args, args.include_system_logs,
args.package_manifest)

if forwarder:
forwarder.terminate()
Expand Down

0 comments on commit b63246b

Please sign in to comment.