896af751f8
Simplifies the process of nesting environments. Usage: with api.env({'myvar': 'myval'}): # do stuff Same as api.step.context but specialized for just environment and merges PATH variable intelligently. Bug: skia:6473 Change-Id: I5769c69cbbbcdab0c6298cee6c5e1fe9caf89c78 Reviewed-on: https://skia-review.googlesource.com/14189 Reviewed-by: Kevin Lubick <kjlubick@google.com> Commit-Queue: Eric Boren <borenet@google.com>
21 lines
711 B
Python
21 lines
711 B
Python
# Copyright 2017 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 recipe_api
|
|
|
|
|
|
class EnvApi(recipe_api.RecipeApi):
|
|
def __call__(self, env_dict):
|
|
env = self.m.step.get_from_context('env', {})
|
|
# If PATH is defined in both, merge them together, merging default_env into
|
|
# path by replacing %(PATH)s
|
|
upstream_path = env.get('PATH', '')
|
|
env.update(env_dict)
|
|
my_path = env_dict.get('PATH', '')
|
|
if upstream_path and my_path and upstream_path != my_path:
|
|
env['PATH'] = upstream_path.replace(r'%(PATH)s', my_path)
|
|
|
|
return self.m.step.context({'env': env})
|