Revert "[cipd] Refactor CIPD template"

This reverts commit 3d6123e3472d61f05d7a7937dc9b6bb414e6e933.

Reason for revert: Broke official desktop continuous builder, at least for Fuchsia (see https://crbug.com/1070174).

Original change's description:
> [cipd] Refactor CIPD template
> 
> Currently, a CIPD staging directory is populated by copying specified
> `sources` into it, and producing a .yaml manifest which reflects the
> copied files.
> 
> This change refactors the template to invoke a pytho script to do the
> above instead of in GN, using the `yaml` library to write the file data
> in the proper format.
> 
> Also make the license filepath explicitly passed through sources.
> 
> Renames "archive" -> "package" and "manifest" -> "package definition" to
> be consistent with CIPD semantics (crbug.com/1042819#c8).
> 
> Finally, have the script emit a depfile for all files tracked by the
> .yaml manifest.
> 
> This refactor is desirable, as we want to create CIPD packages with more
> complicated rules than simply "copy and include these files" (see
> crrev.com/c/1925446, which extends the functionality of the template to
> allow for the inclusion of directories). Wriiting yamls with a library
> reduces the error-proneness of trying to recreate yaml's format in pure
> GN.
> 
> Also, emitting a depfile ensure that we track and rebuild if the CIPD
> package is modified.
> 
> Currently the potential danger of this change is limited in scope to
> fuchsia, as they are the only users of the template. I've checked
> locally that the produced CIPD packages for fuchsia are identical prior
> to this change.
> 
> Bug: fuchsia:41443
> Change-Id: If1b27d6a8fbbffdf767aaa4230bf7b527a553170
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135186
> Commit-Queue: Anthony Fandrianto <atyfto@google.com>
> Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
> Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#758433}

TBR=kmarshall@chromium.org,brucedawson@chromium.org,joshuaseaton@google.com,atyfto@google.com

Change-Id: I68f850f43ca121c3dfb7f87d0ec68e7f96448d94
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: fuchsia:41443
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144183
Reviewed-by: Wez <wez@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#758489}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: e9ca13dea7f7f50903c3e9c2f63867bd4445eb5f
This commit is contained in:
Wez 2020-04-13 10:03:51 +00:00 коммит произвёл Commit Bot
Родитель cda07ba655
Коммит 50de2b1b41
2 изменённых файлов: 20 добавлений и 105 удалений

Просмотреть файл

@ -4,12 +4,12 @@
# Build targets for constructing CIPD packages.
#
# Prepares a CIPD package and generates a package definition.
# Prepares a CIPD archive and generates a manifest file.
#
# TODO(crbug.com/1042819): Add support for including directories.
#
# Parameters:
# package_definition_name: CIPD package definition filename. "cipd.yaml"
# package_definition_yaml: CIPD package definition filename. "cipd.yaml"
# if unspecified.
# package: The path where the package will be located inside the CIPD
# repository.
@ -47,33 +47,27 @@ template("cipd_package_definition") {
assert(_install_mode == "copy" || _install_mode == "symlink",
"\"install_mode\" arg should be either \"copy\" or \"symlink\".")
_package_definition_name = "cipd.yaml"
if (defined(invoker.package_definition_name)) {
_package_definition_name = invoker.package_definition_name
_cipd_definition_yaml = "cipd.yaml"
if (defined(invoker.package_definition_yaml)) {
_cipd_definition_yaml = invoker.package_definition_yaml
}
_package_root = "${target_gen_dir}/${target_name}"
_package_staging_dir = "${target_gen_dir}/${target_name}"
action(target_name) {
script = "//build/cipd/prepare_cipd_package_definition.py"
depfile = "$target_gen_dir/$target_name.d"
_definition_path = "${_package_root}/${_package_definition_name}"
outputs = [ _definition_path ]
_yaml_contents = [
"package: ${invoker.package}",
"description: ${invoker.description}",
"root: \${outdir}/" + rebase_path(_package_staging_dir, root_build_dir),
"install_mode: ${_install_mode}",
"data:",
]
foreach(source, sources) {
_yaml_contents += [ " - file: " + get_path_info(source, "file") ]
}
args = [
"--pkg-name",
invoker.package,
"--description",
invoker.description,
"--pkg-root",
rebase_path(_package_root, root_build_dir),
"--install-mode",
_install_mode,
"--pkg-def",
rebase_path(_definition_path, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
args += [ "--copy-files" ] + rebase_path(sources, root_build_dir)
write_file("${_package_staging_dir}/${_cipd_definition_yaml}", _yaml_contents)
copy(target_name) {
outputs = [ "${_package_staging_dir}/{{source_file_part}}" ]
}
}

Просмотреть файл

@ -1,79 +0,0 @@
#!/usr/bin/env python
#
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Prepares a directory and a corresponding package definition which can be
used to create a CIPD package."""
import argparse
import errno
import os
import sys
import yaml
def main(args):
parser = argparse.ArgumentParser()
parser.add_argument('--pkg-name',
type=str,
required=True,
help='Name of the CIPD package.')
parser.add_argument('--description',
type=str,
required=True,
help='Description of the CIPD package.')
parser.add_argument('--pkg-root',
type=str,
required=True,
help='Path to the package root.')
parser.add_argument('--install-mode',
type=str,
choices=['copy', 'symlink'],
required=True,
help='CIPD install mode.')
parser.add_argument('--pkg-def',
type=str,
required=True,
help='Path to the output package definition.')
parser.add_argument('--depfile',
type=str,
required=True,
help='Path to the depfile.')
parser.add_argument('--copy-files',
nargs='+',
help='Files to be copied into --pkg-root and included '
'in the package definition.')
args = parser.parse_args(args)
pkg_def = {
'package': args.pkg_name,
'description': args.description,
'root': '${outdir}/%s' % os.path.join(args.pkg_root),
'install_mode': args.install_mode,
'data': [],
}
deps = set()
# Copy files into the root.
for filepath in args.copy_files:
basename = os.path.basename(filepath)
dest = os.path.join(args.pkg_root, basename)
try:
os.link(filepath, dest)
except OSError as e:
if e.errno != errno.EEXIST:
raise
pkg_def['data'].append({'file': basename})
deps.add(dest)
with open(args.pkg_def, 'w') as f:
yaml.dump(pkg_def, f)
with open(args.depfile, 'w') as f:
f.writelines('%s: %s\n' % (args.pkg_def, ' '.join(sorted(deps))))
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))