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

Unified Diff: build/android/gyp/util/build_utils.py

Issue 321463002: Pass resources to dependents as zip files instead of directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: this document Created 6 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
« no previous file with comments | « build/android/gyp/process_resources.py ('k') | build/android/gyp/zip.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/util/build_utils.py
diff --git a/build/android/gyp/util/build_utils.py b/build/android/gyp/util/build_utils.py
index 36c83193c1ad3347b6a4b563b14ac5c76552b087..2a53312b85c06724509e62429fac65344815540a 100644
--- a/build/android/gyp/util/build_utils.py
+++ b/build/android/gyp/util/build_utils.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import contextlib
import fnmatch
import json
import os
@@ -10,6 +11,17 @@ import shlex
import shutil
import subprocess
import sys
+import tempfile
+import zipfile
+
+
+@contextlib.contextmanager
+def TempDir():
+ dirname = tempfile.mkdtemp()
+ try:
+ yield dirname
+ finally:
+ shutil.rmtree(dirname)
def MakeDirectory(dir_path):
@@ -142,6 +154,39 @@ def IsDeviceReady():
return device_state.strip() == 'device'
+def CheckZipPath(name):
+ if os.path.normpath(name) != name:
+ raise Exception('Non-canonical zip path: %s, %s' % name)
+ if os.path.isabs(name):
+ raise Exception('Absolute zip path: %s, %s' % name)
+
+
+def ExtractAll(zip_path, path=None, no_clobber=True):
+ if path is None:
+ path = os.getcwd()
+ elif not os.path.exists(path):
+ MakeDirectory(path)
+
+ with zipfile.ZipFile(zip_path) as z:
+ for name in z.namelist():
+ CheckZipPath(name)
+ if no_clobber:
+ output_path = os.path.join(path, name)
+ if os.path.exists(output_path):
+ raise Exception(
+ 'Path already exists from zip: %s %s %s'
+ % (zip_path, name, output_path))
+
+ z.extractall(path=path)
+
+
+def DoZip(inputs, output, base_dir):
+ with zipfile.ZipFile(output, 'w') as outfile:
+ for f in inputs:
+ CheckZipPath(f)
+ outfile.write(f, os.path.relpath(f, base_dir))
+
+
def PrintWarning(message):
print 'WARNING: ' + message
« no previous file with comments | « build/android/gyp/process_resources.py ('k') | build/android/gyp/zip.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698