| # Copyright 2021 The Pigweed Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| # use this file except in compliance with the License. You may obtain a copy of |
| # the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations under |
| # the License. |
| """Recipe for running a specified script from.""" |
| |
| import re |
| |
| from PB.recipes.pigweed.run_script import InputProperties |
| |
| DEPS = [ |
| 'fuchsia/status_check', |
| 'pigweed/checkout', |
| 'pigweed/environment', |
| 'recipe_engine/context', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api, props): |
| checkout = api.checkout(props.checkout_options) |
| env = api.environment.init(checkout.root, props.environment_options) |
| |
| cmd = [checkout.root.join(props.script)] |
| |
| with env(): |
| for arg in props.arguments: |
| repl = lambda match: getattr(env, match.group(1)) |
| arg = re.sub(r'\$([\w]+)', repl, arg) |
| arg = re.sub(r'\$\{([\w]+)\}', repl, arg) |
| cmd.append(arg) |
| |
| with api.context(cwd=checkout.root): |
| api.step('run {}'.format(props.script), cmd) |
| |
| |
| def GenTests(api): |
| def properties(**kwargs): |
| new_kwargs = api.checkout.git_properties() |
| new_kwargs.update(kwargs) |
| return api.properties(**new_kwargs) |
| |
| yield ( |
| api.status_check.test('run_script') |
| + properties(script='foo/bar/run-tests.sh', arguments='foo bar'.split()) |
| ) |
| |
| yield ( |
| api.status_check.test('variable_substitution') |
| + properties( |
| script='run-tests.sh', |
| arguments='without=$PW_TEST_VAR with=${PW_TEST_VAR}'.split(), |
| ) |
| ) |