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

Unified Diff: tools/grit/grit/util.py

Issue 2094193004: Strip comments and whitespace from Javascript resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also strip Javascript browser resources Created 4 years, 6 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
Index: tools/grit/grit/util.py
diff --git a/tools/grit/grit/util.py b/tools/grit/grit/util.py
index 93dce2610074cdef7fbc0190e3e36d3950d1d94f..c013a69c54a4a1a4e02c3158415a5618e207188c 100755
--- a/tools/grit/grit/util.py
+++ b/tools/grit/grit/util.py
@@ -21,6 +21,8 @@ from grit import lazy_re
_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+_replacement_paths = {}
+
# Unique constants for use by ReadFile().
BINARY, RAW_TEXT = range(2)
@@ -203,8 +205,10 @@ def ReadFile(filename, encoding):
the file in binary mode, or RAW_TEXT to read it with newline
conversion but without decoding to Unicode.
'''
+ path = os.path.abspath(filename)
+ replacement_path = _replacement_paths.get(path, path)
mode = 'rb' if encoding == BINARY else 'rU'
- with open(filename, mode) as f:
+ with open(replacement_path, mode) as f:
data = f.read()
if encoding not in (BINARY, RAW_TEXT):
data = data.decode(encoding)
@@ -660,3 +664,7 @@ class TempDir(object):
os.chdir(self.path)
def __exit__(self, *exc_info):
os.chdir(self.oldpath)
+
+def SetReplacementPaths(replacement_paths):
+ global _replacement_paths
+ _replacement_paths = replacement_paths

Powered by Google App Engine
This is Rietveld 408576698