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

Side by Side Diff: webrtc/generate_srcjar.py

Issue 2610823002: Fixing package-boundary violation with srjar_deps (Closed)
Patch Set: Addressing comments 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 unified diff | Download patch
« no previous file with comments | « webrtc/build/webrtc.gni ('k') | webrtc/modules/audio_device/BUILD.gn » ('j') | 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 (c) 2017 The WebRTC project authors. All Rights Reserved.
4 #
5 # Use of this source code is governed by a BSD-style license
6 # that can be found in the LICENSE file in the root of the source
7 # tree. An additional intellectual property rights grant can be found
8 # in the file PATENTS. All contributing project authors may
9 # be found in the AUTHORS file in the root of the source tree.
10
11 # TODO(mbonadei): move this script into chromium (build/android/gyp)
12 # when approved
13
14 # TODO(mbonadei): write some documentation on how to use this script
15
16 import optparse
17 import os
18 import re
19 import sys
20 import zipfile
21
22 # TODO(mbonadei): fix this import and make it relative to the chromium
23 # build/android/gyp folder.
24 sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, os.pardir, 'build',
25 'android', 'gyp', 'util')))
26 import build_utils
27
28
29 def PackageToPath(src_file):
30 """Given a path to a .java source file it returns the path of the file
kjellander_webrtc 2017/01/04 20:03:45 The first sentence in the docstring (the short des
mbonadei 2017/01/05 08:17:52 Acknowledged.
31 according to the package definition.
32
33 Example:
34 src_file='/home/foo/bar/org/android/TestClass.java'
35 With the following package definition:
36 package org.android;
37
38 It will return 'org/android'.
39
40 Args:
41 A string with the path of the .java source file to analyze.
42
43 Returns:
44 A string with the translation of the package definition into a path.
45 """
46 with open(src_file) as f:
47 file_src = f.read()
48 package = re.search('package (.*);', file_src).group(1)
49 zip_folder = package.replace('.', os.path.sep)
50 file_name = os.path.basename(src_file)
51 return os.path.join(zip_folder, file_name)
52
53
54 def DoMain(argv):
55 usage = 'usage: %prog [options] input_file(s)...'
56 parser = optparse.OptionParser(usage=usage)
57 parser.add_option('-s', '--srcjar',
58 help='The path where the .srcjar file will be generated')
59
60 options, args = parser.parse_args(argv)
61
62 if not args:
63 parser.error('Need to specify at least one input file')
64 input_paths = args
65
66 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar:
67 for src_path in input_paths:
68 zip_path = PackageToPath(src_path)
69 build_utils.AddToZipHermetic(srcjar, zip_path, src_path)
70
71
72 if __name__ == '__main__':
73 DoMain(sys.argv[1:])
OLDNEW
« no previous file with comments | « webrtc/build/webrtc.gni ('k') | webrtc/modules/audio_device/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698