Return a custom result type from bot_update.ensure_checkout.
In order to facilitate removing uses of api.path.checkout_dir from downstream repos, this change adds a custom return type for bot_update.ensure_checkout. Now instead of a standard step result, an object of Result will be returned. Result records the relevant paths (directory where the checkout was performed, the repo that was checked out and the repo that was patched, if any). This provides the caller the ability to work in any of these directories without using api.path.checkout_dir and without requiring boilerplate to construct the paths. It also includes some attributes that provide details from within the json output to abstract that out. Bug: 329113288, 339472834 Change-Id: I2ec6db635c5b799bdb65d4e9364e7d99aae4159e Recipe-Manual-Change: build Recipe-Manual-Change: build_limited Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5523194 Reviewed-by: Yiwei Zhang <yiwzhang@google.com> Commit-Queue: Garrett Beaty <gbeaty@google.com>changes/94/5523194/11
parent
e5cacc3a8a
commit
fd81abb19d
@ -0,0 +1,36 @@
|
||||
google_issue_default {
|
||||
host: "crbug.com"
|
||||
}
|
||||
warning {
|
||||
name: "BOT_UPDATE_CUSTOM_RESULT_ATTRIBUTES"
|
||||
description: "The custom result type returned from"
|
||||
description: "`bot_update.ensure_checkout` provides attributes that give easy"
|
||||
description: "access to the information that is often accessed via the"
|
||||
description: "existing step result's `presentation` or `json.output` values."
|
||||
description: "These uses should be updated as follows:"
|
||||
description: ""
|
||||
description: "1) `result.presentation.properties` should be replaced with"
|
||||
description: "`result.properties`."
|
||||
description: ""
|
||||
description: "2) `result.json.output['properties']`,"
|
||||
description: "`result.json.output['manifest']` and"
|
||||
description: "`result.json.output['fixed_revisions']` should be replaced"
|
||||
description: "with `result.properties`, `result.manifest` and"
|
||||
description: "`result.fixed_revisions`, respectively."
|
||||
description: ""
|
||||
description: "3) Getting the source root and the patch root should no longer"
|
||||
description: "be done via `result.json.output['root']` and"
|
||||
description: "`result.json.output['patch_root']`. `result.source_root` and"
|
||||
description: "`result.patch_root` should be used instead. These objects have"
|
||||
description: "`path` and `name` attributes. The `path` attribute gives a"
|
||||
description: "`Path` for the location of the repo. The `name` attribute is"
|
||||
description: "the gclient \"name\" of the repo, i.e. the path relative to the"
|
||||
description: "directory where the checkout was performed. This removes the"
|
||||
description: "need to do path manipulation in the common cases. If no patch"
|
||||
description: "was applied, `result.patch_root` will be `None`."
|
||||
description: ""
|
||||
description: "4) `result.json.output['did_run']` does not need to be"
|
||||
description: "accessed, it is always guaranteed to be True if a result was"
|
||||
description: "returned."
|
||||
google_issue { id: 339472834 }
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
# Copyright 2018 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.
|
||||
|
||||
from recipe_engine import post_process
|
||||
from recipe_engine import recipe_api
|
||||
|
||||
PYTHON_VERSION_COMPATIBILITY = 'PY3'
|
||||
|
||||
DEPS = [
|
||||
'bot_update',
|
||||
'gclient',
|
||||
'recipe_engine/assertions',
|
||||
'recipe_engine/buildbucket',
|
||||
'recipe_engine/path',
|
||||
'recipe_engine/properties',
|
||||
]
|
||||
|
||||
PROPERTIES = {
|
||||
'expected_checkout_dir': recipe_api.Property(),
|
||||
'expected_source_root_name': recipe_api.Property(),
|
||||
'expected_patch_root_name': recipe_api.Property(default=None),
|
||||
}
|
||||
|
||||
|
||||
# TODO: crbug.com/339472834 - Once all downstream uses of presentation and
|
||||
# json.output have been removed, this test can be updated to not reference them
|
||||
# and the decorator can be removed
|
||||
@recipe_api.ignore_warnings('^depot_tools/BOT_UPDATE_CUSTOM_RESULT_ATTRIBUTES$')
|
||||
def RunSteps(api, expected_checkout_dir, expected_source_root_name,
|
||||
expected_patch_root_name):
|
||||
api.gclient.set_config('depot_tools')
|
||||
result = api.bot_update.ensure_checkout()
|
||||
|
||||
api.assertions.assertEqual(result.checkout_dir, expected_checkout_dir)
|
||||
|
||||
api.assertions.assertEqual(result.source_root.name, expected_source_root_name)
|
||||
api.assertions.assertEqual(result.source_root.path,
|
||||
expected_checkout_dir / expected_source_root_name)
|
||||
|
||||
if expected_patch_root_name is not None:
|
||||
api.assertions.assertEqual(result.patch_root.name, expected_patch_root_name)
|
||||
api.assertions.assertEqual(result.patch_root.path,
|
||||
expected_checkout_dir / expected_patch_root_name)
|
||||
else:
|
||||
api.assertions.assertIsNone(result.patch_root)
|
||||
|
||||
api.assertions.assertEqual(result.properties, result.presentation.properties)
|
||||
api.assertions.assertEqual(result.manifest,
|
||||
result.json.output.get('manifest', {}))
|
||||
api.assertions.assertEqual(result.fixed_revisions,
|
||||
result.json.output.get('fixed_revisions', {}))
|
||||
|
||||
|
||||
def GenTests(api):
|
||||
yield api.test(
|
||||
'basic',
|
||||
api.properties(
|
||||
expected_checkout_dir=api.path.start_dir,
|
||||
expected_source_root_name='depot_tools',
|
||||
),
|
||||
api.expect_status('SUCCESS'),
|
||||
api.post_process(post_process.DropExpectation),
|
||||
)
|
||||
|
||||
yield api.test(
|
||||
'patch',
|
||||
api.buildbucket.try_build(),
|
||||
api.properties(
|
||||
expected_checkout_dir=api.path.start_dir,
|
||||
expected_source_root_name='depot_tools',
|
||||
expected_patch_root_name='depot_tools',
|
||||
),
|
||||
api.expect_status('SUCCESS'),
|
||||
api.post_process(post_process.DropExpectation),
|
||||
)
|
Loading…
Reference in New Issue