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

Unified Diff: webrtc/generate_srcjar.py

Issue 2610823002: Fixing package-boundary violation with srjar_deps (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | webrtc/modules/audio_device/BUILD.gn » ('j') | webrtc/modules/audio_device/BUILD.gn » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/generate_srcjar.py
diff --git a/webrtc/generate_srcjar.py b/webrtc/generate_srcjar.py
new file mode 100755
index 0000000000000000000000000000000000000000..7e061201689cff0999a9200df82e138a8c5a1b86
--- /dev/null
+++ b/webrtc/generate_srcjar.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
kjellander_webrtc 2017/01/04 14:25:21 New files should have the current year.
mbonadei 2017/01/04 15:19:06 Good catch, I am still writing 2016 everywhere. :-
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+#TODO(mbonadei): move this script into chromium (build/android/gyp)
kjellander_webrtc 2017/01/04 14:25:21 Comments usually don't start right after the #. I
mbonadei 2017/01/04 15:19:06 Acknowledged.
+# when approved
+
+#TODO(mbonadei): write some documentation on how to use this script
+
+import re
+import optparse
+import os
+import sys
+import zipfile
+import ntpath
kjellander_webrtc 2017/01/04 14:25:21 sort alphabetically
mbonadei 2017/01/04 15:19:06 Acknowledged.
+
+#TODO(mbonadei): fix this import and meke it relative to the chromium
kjellander_webrtc 2017/01/04 14:25:21 meke -> make
mbonadei 2017/01/04 15:19:06 Acknowledged.
+# build/android/gyp folder.
+sys.path.insert(0, os.path.abspath('../../build/android/gyp/util'))
kjellander_webrtc 2017/01/04 14:25:21 Please build the path using os.path.join and os.pa
mbonadei 2017/01/04 15:19:06 Acknowledged.
+import build_utils
+
+
+def FindZipPathFromSource(src_file):
kjellander_webrtc 2017/01/04 14:25:21 Can you add a docstring what this method does? I
mbonadei 2017/01/04 15:19:06 Acknowledged.
+ with open(src_file, "r") as f:
kjellander_webrtc 2017/01/04 14:25:21 You can leave out 'r', as it's the default if mode
mbonadei 2017/01/04 15:19:06 Acknowledged.
+ file_src = f.read()
+ package = re.search("package (.*);", file_src).group(1)
kjellander_webrtc 2017/01/04 14:25:21 Please use single-quotes for all strings. The styl
mbonadei 2017/01/04 15:19:06 Acknowledged.
+ zip_folder = package.replace('.', os.path.sep)
+ file_name = ntpath.basename(src_file)
kjellander_webrtc 2017/01/04 14:25:21 I don't ntpath is useful here. Just regular os.pat
mbonadei 2017/01/04 15:19:06 Acknowledged.
+ return os.path.join(zip_folder, file_name)
+
+
+def DoMain(argv):
+ usage = 'usage: %prog [options] [output_dir] input_file(s)...'
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option('--srcjar',
kjellander_webrtc 2017/01/04 14:25:21 For our use case this is a required flag, right? T
mbonadei 2017/01/04 15:19:06 Acknowledged. I am not throwing parser.error in t
+ help='When specified, a .srcjar at the given path is '
+ 'created instead of individual .java files.')
+
+ options, args = parser.parse_args(argv)
+
+ if not args:
+ parser.error('Need to specify at least one input file')
+ input_paths = args
+
+ with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar:
+ for src_path in input_paths:
+ zip_path = FindZipPathFromSource(src_path)
kjellander_webrtc 2017/01/04 14:25:21 This manipulation just to figure out the path insi
mbonadei 2017/01/04 15:19:06 Yeah, I agree but I think that probably it is the
+ build_utils.AddToZipHermetic(srcjar, zip_path, src_path)
+
+
+if __name__ == '__main__':
+ DoMain(sys.argv[1:])
« no previous file with comments | « no previous file | webrtc/modules/audio_device/BUILD.gn » ('j') | webrtc/modules/audio_device/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698