From fe92995d40a79af9c8a2cd31babda3fe53cc683f Mon Sep 17 00:00:00 2001 From: Dan Jacques Date: Sun, 21 May 2017 19:44:35 -0700 Subject: [PATCH] [cipd] Allow packaging whole root. Currently, the "cipd" recipe module allows a package to be created by adding directories to a PackageDefinition via "add_dir". However, there is no current way to add the entirety of a root directory to a package. The PackageDefinition will generate a relative path of "''", which CIPD will reject as empty. Make it so that if the user supplies the root directory as the directory to add to the package, it properly includes it as ".". BUG=None TEST=local - Ran recipe with this modification, seems to work R=iannucci@chromium.org, nodir@chromium.org, vadimsh@chromium.org Change-Id: Ib5c72038cf153776808f084db835c60f61fd9044 Reviewed-on: https://chromium-review.googlesource.com/510309 Reviewed-by: Vadim Shtayura Reviewed-by: Robbie Iannucci Commit-Queue: Daniel Jacques --- recipes/recipe_modules/cipd/api.py | 4 +++- recipes/recipe_modules/cipd/example.expected/basic_pkg.json | 2 +- recipes/recipe_modules/cipd/example.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/recipes/recipe_modules/cipd/api.py b/recipes/recipe_modules/cipd/api.py index 27b6e84f3..4aefd0d7e 100644 --- a/recipes/recipe_modules/cipd/api.py +++ b/recipes/recipe_modules/cipd/api.py @@ -61,7 +61,9 @@ class PackageDefinition(object): def _rel_path(self, path): """Returns a forward-slash-delimited version of `path` which is relative to the package root. Will raise ValueError if path is not inside the root.""" - if path != self.package_root and not self.package_root.is_parent_of(path): + if path == self.package_root: + return '.' + if not self.package_root.is_parent_of(path): raise ValueError( 'path %r is not the package root %r and not a child thereof' % (path, self.package_root)) diff --git a/recipes/recipe_modules/cipd/example.expected/basic_pkg.json b/recipes/recipe_modules/cipd/example.expected/basic_pkg.json index d667fff88..bf2fbb70d 100644 --- a/recipes/recipe_modules/cipd/example.expected/basic_pkg.json +++ b/recipes/recipe_modules/cipd/example.expected/basic_pkg.json @@ -286,7 +286,7 @@ "cipd", "create", "-pkg-def", - "{\"data\": [{\"file\": \"a/path/to/file.py\"}, {\"file\": \"some_config.cfg\"}, {\"dir\": \"directory\", \"exclude\": []}, {\"dir\": \"other_dir\", \"exclude\": [\".*\\\\.pyc\"]}], \"install_mode\": \"\", \"package\": \"infra/fake-package\", \"root\": \"[START_DIR]/some_subdir\"}", + "{\"data\": [{\"file\": \"a/path/to/file.py\"}, {\"file\": \"some_config.cfg\"}, {\"dir\": \".\", \"exclude\": []}, {\"dir\": \"directory\", \"exclude\": []}, {\"dir\": \"other_dir\", \"exclude\": [\".*\\\\.pyc\"]}], \"install_mode\": \"\", \"package\": \"infra/fake-package\", \"root\": \"[START_DIR]/some_subdir\"}", "-json-output", "/path/to/tmp/json", "-service-account-json", diff --git a/recipes/recipe_modules/cipd/example.py b/recipes/recipe_modules/cipd/example.py index 07acdbb42..0a1abbbd1 100644 --- a/recipes/recipe_modules/cipd/example.py +++ b/recipes/recipe_modules/cipd/example.py @@ -68,6 +68,7 @@ def RunSteps(api, use_pkg, pkg_files, pkg_dirs, ver_files, install_mode): pkg = api.cipd.PackageDefinition('infra/fake-package', root, install_mode) for fullpath in pkg_files: pkg.add_file(api.path.abs_to_path(fullpath)) + pkg.add_dir(root) for obj in pkg_dirs: pkg.add_dir(api.path.abs_to_path(obj.get('path', '')), obj.get('exclusions'))