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

Side by Side Diff: build/android/gyp/jar.py

Issue 2014983003: [Android] Build changes needed for Robolectric 3.0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | build/android/gyp/javac.py » ('j') | build/config/android/internal_rules.gni » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import optparse 7 import optparse
8 import os 8 import os
9 import shutil
9 import sys 10 import sys
10 11
11 from util import build_utils 12 from util import build_utils
12 13
13 14
14 _RESOURCE_CLASSES = [ 15 _RESOURCE_CLASSES = [
15 "R.class", 16 "R.class",
16 "R##*.class", 17 "R##*.class",
17 "Manifest.class", 18 "Manifest.class",
18 "Manifest##*.class", 19 "Manifest##*.class",
19 ] 20 ]
20 21
21 22
22 def Jar(class_files, classes_dir, jar_path, manifest_file=None): 23 def Jar(class_files, classes_dir, jar_path, manifest_file=None,
24 provider_configurations=None):
23 jar_path = os.path.abspath(jar_path) 25 jar_path = os.path.abspath(jar_path)
24 26
25 # The paths of the files in the jar will be the same as they are passed in to 27 # The paths of the files in the jar will be the same as they are passed in to
26 # the command. Because of this, the command should be run in 28 # the command. Because of this, the command should be run in
27 # options.classes_dir so the .class file paths in the jar are correct. 29 # options.classes_dir so the .class file paths in the jar are correct.
28 jar_cwd = classes_dir 30 jar_cwd = classes_dir
29 class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files] 31 class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files]
30 jar_cmd = ['jar', 'cf0', jar_path] 32 jar_cmd = ['jar', 'cf0', jar_path]
31 if manifest_file: 33 if manifest_file:
32 jar_cmd[1] += 'm' 34 jar_cmd[1] += 'm'
33 jar_cmd.append(os.path.abspath(manifest_file)) 35 jar_cmd.append(os.path.abspath(manifest_file))
34 jar_cmd.extend(class_files_rel) 36 jar_cmd.extend(class_files_rel)
35 37
38 if provider_configurations:
39 service_dir = os.path.join(jar_cwd, 'META-INF', 'services')
40 if not os.path.exists(service_dir):
41 os.makedirs(service_dir)
42 for config in provider_configurations:
43 config_jar_path = os.path.join(service_dir, os.path.basename(config))
44 shutil.copy(config, config_jar_path)
45 jar_cmd.append(os.path.relpath(config_jar_path, jar_cwd))
46
36 if not class_files_rel: 47 if not class_files_rel:
37 empty_file = os.path.join(classes_dir, '.empty') 48 empty_file = os.path.join(classes_dir, '.empty')
38 build_utils.Touch(empty_file) 49 build_utils.Touch(empty_file)
39 jar_cmd.append(os.path.relpath(empty_file, jar_cwd)) 50 jar_cmd.append(os.path.relpath(empty_file, jar_cwd))
40 build_utils.CheckOutput(jar_cmd, cwd=jar_cwd) 51 build_utils.CheckOutput(jar_cmd, cwd=jar_cwd)
41 build_utils.Touch(jar_path, fail_if_missing=True) 52 build_utils.Touch(jar_path, fail_if_missing=True)
42 53
43 54
44 def JarDirectory(classes_dir, jar_path, manifest_file=None, predicate=None): 55 def JarDirectory(classes_dir, jar_path, manifest_file=None, predicate=None,
56 provider_configurations=None):
45 class_files = build_utils.FindInDirectory(classes_dir, '*.class') 57 class_files = build_utils.FindInDirectory(classes_dir, '*.class')
46 if predicate: 58 if predicate:
47 class_files = [f for f in class_files if predicate(f)] 59 class_files = [f for f in class_files if predicate(f)]
48 60
49 Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file) 61 Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file,
62 provider_configurations=provider_configurations)
50 63
51 64
52 def main(): 65 def main():
53 parser = optparse.OptionParser() 66 parser = optparse.OptionParser()
54 parser.add_option('--classes-dir', help='Directory containing .class files.') 67 parser.add_option('--classes-dir', help='Directory containing .class files.')
55 parser.add_option('--input-jar', help='Jar to include .class files from') 68 parser.add_option('--input-jar', help='Jar to include .class files from')
56 parser.add_option('--jar-path', help='Jar output path.') 69 parser.add_option('--jar-path', help='Jar output path.')
57 parser.add_option('--excluded-classes', 70 parser.add_option('--excluded-classes',
58 help='GYP list of .class file patterns to exclude from the jar.') 71 help='GYP list of .class file patterns to exclude from the jar.')
59 parser.add_option('--strip-resource-classes-for', 72 parser.add_option('--strip-resource-classes-for',
(...skipping 25 matching lines...) Expand all
85 classes_dir = temp_dir 98 classes_dir = temp_dir
86 JarDirectory(classes_dir, options.jar_path, predicate=predicate) 99 JarDirectory(classes_dir, options.jar_path, predicate=predicate)
87 100
88 if options.stamp: 101 if options.stamp:
89 build_utils.Touch(options.stamp) 102 build_utils.Touch(options.stamp)
90 103
91 104
92 if __name__ == '__main__': 105 if __name__ == '__main__':
93 sys.exit(main()) 106 sys.exit(main())
94 107
OLDNEW
« no previous file with comments | « no previous file | build/android/gyp/javac.py » ('j') | build/config/android/internal_rules.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698