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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « infra/bots/win_toolchain_hash.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: infra/bots/win_toolchain_utils.py
diff --git a/infra/bots/win_toolchain_utils.py b/infra/bots/win_toolchain_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..43f62863cde3de8a457830d6339c50bc8bc47e4e
--- /dev/null
+++ b/infra/bots/win_toolchain_utils.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Utilities for manipulating the win_toolchain.json file."""
+
+
+import json
+
+
+PLACEHOLDER = '<(TOOLCHAIN_BASE_DIR)'
+
+
+def _replace_prefix(val, before, after):
+ """Replace the given prefix with the given string."""
+ if val.startswith(before):
+ return val.replace(before, after, 1)
+ return val
+
+
+def _replace(val, before, after):
+ """Replace occurrences of one string with another within the data."""
+ if isinstance(val, basestring):
+ return _replace_prefix(val, before, after)
+ elif isinstance(val, (list, tuple)):
+ return [_replace(elem, before, after) for elem in val]
+ elif isinstance(val, dict):
+ return {_replace(k, before, after):
+ _replace(v, before, after) for k, v in val.iteritems()}
+ raise Exception('Cannot replace variable: %s' % val)
+
+
+def _replace_in_file(filename, before, after):
+ """Replace occurrences of one string with another within the file."""
+ with open(filename) as f:
+ contents = json.load(f)
+ new_contents = _replace(contents, before, after)
+ with open(filename, 'w') as f:
+ json.dump(new_contents, f)
+
+
+def abstract(win_toolchain_json, old_path):
+ """Replace absolute paths in win_toolchain.json with placeholders."""
+ _replace_in_file(win_toolchain_json, old_path, PLACEHOLDER)
+
+
+def resolve(win_toolchain_json, new_path):
+ """Replace placeholders in win_toolchain.json with absolute paths."""
+ _replace_in_file(win_toolchain_json, PLACEHOLDER, new_path)
« 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