Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: infra/bots/win_toolchain_utils.py

Issue 1782943002: Fixes for Win toolchain isolate (Closed) Base URL: https://skia.googlesource.com/skia.git@swarm_win_toolchain
Patch Set: Update toolchain hashes Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « infra/bots/win_toolchain_hash.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Utilities for manipulating the win_toolchain.json file."""
10
11
12 import json
13
14
15 PLACEHOLDER = '<(TOOLCHAIN_BASE_DIR)'
16
17
18 def _replace_prefix(val, before, after):
19 """Replace the given prefix with the given string."""
20 if val.startswith(before):
21 return val.replace(before, after, 1)
22 return val
23
24
25 def _replace(val, before, after):
26 """Replace occurrences of one string with another within the data."""
27 if isinstance(val, basestring):
28 return _replace_prefix(val, before, after)
29 elif isinstance(val, (list, tuple)):
30 return [_replace(elem, before, after) for elem in val]
31 elif isinstance(val, dict):
32 return {_replace(k, before, after):
33 _replace(v, before, after) for k, v in val.iteritems()}
34 raise Exception('Cannot replace variable: %s' % val)
35
36
37 def _replace_in_file(filename, before, after):
38 """Replace occurrences of one string with another within the file."""
39 with open(filename) as f:
40 contents = json.load(f)
41 new_contents = _replace(contents, before, after)
42 with open(filename, 'w') as f:
43 json.dump(new_contents, f)
44
45
46 def abstract(win_toolchain_json, old_path):
47 """Replace absolute paths in win_toolchain.json with placeholders."""
48 _replace_in_file(win_toolchain_json, old_path, PLACEHOLDER)
49
50
51 def resolve(win_toolchain_json, new_path):
52 """Replace placeholders in win_toolchain.json with absolute paths."""
53 _replace_in_file(win_toolchain_json, PLACEHOLDER, new_path)
OLDNEW
« no previous file with comments | « infra/bots/win_toolchain_hash.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698