3 # Copyright (c) 2014 Intel Corporation. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 # pylint: disable=F0401
14 LIBRARY_PROJECT_NAME = 'xwalk_core_library'
15 AAR_LIBRARY_NAME = 'xwalk_core_library_aar'
17 def AddGeneratorOptions(option_parser):
18 option_parser.add_option('-s', dest='source',
19 help='Source directory of project root.',
21 option_parser.add_option('-t', dest='target',
22 help='Product out target directory.',
26 def CopyProjectFiles(out_dir):
27 """cp out/Release/xwalk_core_library/AndroidManifest<file>
28 out/Release/xwalk_core_library_aar/<file>
31 print 'Copying library project files...'
33 # AndroidManifest.xml from template.
34 'AndroidManifest.xml',
36 for f in files_to_copy:
37 source_file = os.path.join(out_dir, LIBRARY_PROJECT_NAME, f)
38 target_file = os.path.join(out_dir, AAR_LIBRARY_NAME, f)
39 shutil.copy2(source_file, target_file)
42 def CopyBinaries(out_dir):
43 """cp out/Release/xwalk_core_library/libs/*
44 out/Release/xwalk_core_library_aar/jni/
47 print 'Copying binaries...'
48 # Copy jar files to classes.jar.
49 libs_dir = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'libs')
51 source_file = os.path.join(libs_dir, 'xwalk_core_library_java.jar')
52 target_file = os.path.join(out_dir, AAR_LIBRARY_NAME, 'classes.jar')
53 shutil.copyfile(source_file, target_file)
55 # Copy native libraries.
56 source_dir = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'libs')
57 target_dir = os.path.join(out_dir, AAR_LIBRARY_NAME, 'jni')
58 if not os.path.exists(target_dir):
59 os.makedirs(target_dir)
61 if os.path.exists(source_dir):
62 for item in os.listdir(source_dir):
63 sub_path = os.path.join(source_dir, item)
64 target_dir = os.path.join(target_dir, item)
65 if os.path.isdir(sub_path):
66 shutil.copytree(sub_path, target_dir)
69 r_source_dir = os.path.join(out_dir, 'gen', 'xwalk_core_internal_java')
70 r_source_file = os.path.join(r_source_dir, 'java_R', 'R.txt')
71 r_target_file = os.path.join(out_dir, AAR_LIBRARY_NAME, 'R.txt')
72 shutil.copyfile(r_source_file, r_target_file)
75 def CopyResources(out_dir):
76 print 'Copying resources...'
77 source_dir = os.path.join(out_dir, LIBRARY_PROJECT_NAME, 'res')
78 target_dir = os.path.join(out_dir, AAR_LIBRARY_NAME, 'res')
79 shutil.copytree(source_dir, target_dir)
82 def GenerateAAR(aar_path, aar_dir):
83 zfile = zipfile.ZipFile(aar_path, 'w')
84 abs_src = os.path.abspath(aar_dir)
85 for dirname, _, files in os.walk(aar_dir):
86 for filename in files:
87 absname = os.path.abspath(os.path.join(dirname, filename))
88 relativename = absname[len(abs_src) + 1:]
89 zfile.write(absname, relativename)
92 shutil.rmtree(aar_dir)
96 print 'Generating XWalkCore AAR Library...'
97 option_parser = optparse.OptionParser()
98 AddGeneratorOptions(option_parser)
99 options, _ = option_parser.parse_args(argv)
101 if not os.path.exists(options.source):
102 print 'Source project does not exist, please provide correct directory.'
104 out_dir = options.target
106 # Clean the aar library.
107 aar_path = os.path.join(out_dir, 'xwalk_core_library.aar')
108 if os.path.exists(aar_path):
111 aar_dir = os.path.join(out_dir, AAR_LIBRARY_NAME)
112 if os.path.exists(aar_dir):
113 shutil.rmtree(aar_dir)
116 # Copy Eclipse project files of library project.
117 CopyProjectFiles(out_dir)
118 # Copy binaries and resuorces.
119 CopyResources(out_dir)
120 CopyBinaries(out_dir)
121 GenerateAAR(aar_path, aar_dir)
124 if __name__ == '__main__':
125 sys.exit(main(sys.argv))