blob: 1c55d7e4fcbd668b756a0d7b9819d68341da902a [file] [log] [blame]
Michael Thvedt828a4be2015-08-12 17:45:36 +00001#!/usr/bin/python2.7
2
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Michael Thvedt828a4be2015-08-12 17:45:36 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http:#www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""A wrapper script for J2ObjC transpiler.
18
19This script wraps around J2ObjC transpiler to also output a dependency mapping
20file by scanning the import and include directives of the J2ObjC-translated
21files.
22"""
23
24import argparse
Rumou Duana1a13ae2016-07-26 17:23:26 +000025import errno
Michael Thvedt828a4be2015-08-12 17:45:36 +000026import multiprocessing
27import os
28import Queue
29import re
Rumou Duana1a13ae2016-07-26 17:23:26 +000030import shutil
Michael Thvedt828a4be2015-08-12 17:45:36 +000031import subprocess
Rumou Duan18742ad2015-09-02 23:45:03 +000032import tempfile
Michael Thvedt828a4be2015-08-12 17:45:36 +000033import threading
Rumou Duana1a13ae2016-07-26 17:23:26 +000034import zipfile
Michael Thvedt828a4be2015-08-12 17:45:36 +000035
Rumou Duana1a13ae2016-07-26 17:23:26 +000036_INCLUDE_RE = re.compile('#(include|import) "([^"]+)"')
37_CONST_DATE_TIME = [1980, 1, 1, 0, 0, 0]
Michael Thvedt828a4be2015-08-12 17:45:36 +000038
39
Rumou Duana1a13ae2016-07-26 17:23:26 +000040def RunJ2ObjC(java, jvm_flags, j2objc, main_class, output_file_path,
41 j2objc_args, source_paths, files_to_translate):
Michael Thvedt828a4be2015-08-12 17:45:36 +000042 """Runs J2ObjC transpiler to translate Java source files to ObjC.
43
44 Args:
45 java: The path of the Java executable.
46 jvm_flags: A comma-separated list of flags to pass to JVM.
47 j2objc: The deploy jar of J2ObjC.
48 main_class: The J2ObjC main class to invoke.
Rumou Duana1a13ae2016-07-26 17:23:26 +000049 output_file_path: The output file directory.
Rumou Duan18742ad2015-09-02 23:45:03 +000050 j2objc_args: A list of args to pass to J2ObjC transpiler.
Rumou Duana1a13ae2016-07-26 17:23:26 +000051 source_paths: A list of directories that contain sources to translate.
52 files_to_translate: A list of relative paths (relative to source_paths) that
53 point to sources to translate.
Michael Thvedt828a4be2015-08-12 17:45:36 +000054 Returns:
55 None.
56 """
Rumou Duana1a13ae2016-07-26 17:23:26 +000057 source_file_manifest_content = ' '.join(files_to_translate)
Rumou Duan18742ad2015-09-02 23:45:03 +000058 fd = None
59 param_filename = None
60 try:
61 fd, param_filename = tempfile.mkstemp(text=True)
62 os.write(fd, source_file_manifest_content)
63 finally:
64 if fd:
65 os.close(fd)
66 try:
67 j2objc_cmd = [java]
68 j2objc_cmd.extend(filter(None, jvm_flags.split(',')))
69 j2objc_cmd.extend(['-cp', j2objc, main_class])
Rumou Duana1a13ae2016-07-26 17:23:26 +000070 j2objc_cmd.extend(j2objc_args)
71 j2objc_cmd.extend(['-sourcepath', ':'.join(source_paths)])
72 j2objc_cmd.extend(['-d', output_file_path])
Rumou Duan18742ad2015-09-02 23:45:03 +000073 j2objc_cmd.extend(['@%s' % param_filename])
74 subprocess.check_call(j2objc_cmd, stderr=subprocess.STDOUT)
75 finally:
76 if param_filename:
77 os.remove(param_filename)
Michael Thvedt828a4be2015-08-12 17:45:36 +000078
79
Rumou Duana1a13ae2016-07-26 17:23:26 +000080def WriteDepMappingFile(objc_files,
81 objc_file_root,
Michael Thvedt828a4be2015-08-12 17:45:36 +000082 output_dependency_mapping_file,
83 file_open=open):
84 """Scans J2ObjC-translated files and outputs a dependency mapping file.
85
86 The mapping file contains mappings between translated source files and their
87 imported source files scanned from the import and include directives.
88
89 Args:
Rumou Duana1a13ae2016-07-26 17:23:26 +000090 objc_files: A list of ObjC files translated by J2ObjC.
91 objc_file_root: The file path which represents a directory where the
Michael Thvedt828a4be2015-08-12 17:45:36 +000092 generated ObjC files reside.
93 output_dependency_mapping_file: The path of the dependency mapping file to
94 write to.
95 file_open: Reference to the builtin open function so it may be
96 overridden for testing.
Rumou Duan49cdb4b2015-12-04 18:03:44 +000097 Raises:
98 RuntimeError: If spawned threads throw errors during processing.
Michael Thvedt828a4be2015-08-12 17:45:36 +000099 Returns:
100 None.
101 """
102 dep_mapping = dict()
103 input_file_queue = Queue.Queue()
104 output_dep_mapping_queue = Queue.Queue()
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000105 error_message_queue = Queue.Queue()
Rumou Duana1a13ae2016-07-26 17:23:26 +0000106 for objc_file in objc_files:
107 input_file_queue.put(os.path.join(objc_file_root, objc_file))
Michael Thvedt828a4be2015-08-12 17:45:36 +0000108
109 for _ in xrange(multiprocessing.cpu_count()):
110 t = threading.Thread(target=_ReadDepMapping, args=(input_file_queue,
111 output_dep_mapping_queue,
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000112 error_message_queue,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000113 objc_file_root,
Michael Thvedt828a4be2015-08-12 17:45:36 +0000114 file_open))
115 t.start()
116
117 input_file_queue.join()
118
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000119 if not error_message_queue.empty():
120 error_messages = [error_message for error_message in
121 error_message_queue.queue]
122 raise RuntimeError('\n'.join(error_messages))
123
Michael Thvedt828a4be2015-08-12 17:45:36 +0000124 while not output_dep_mapping_queue.empty():
125 entry_file, deps = output_dep_mapping_queue.get()
126 dep_mapping[entry_file] = deps
127
128 f = file_open(output_dependency_mapping_file, 'w')
129 for entry in sorted(dep_mapping):
130 for dep in dep_mapping[entry]:
131 f.write(entry + ':' + dep + '\n')
132 f.close()
133
134
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000135def _ReadDepMapping(input_file_queue, output_dep_mapping_queue,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000136 error_message_queue, output_root, file_open=open):
Michael Thvedt828a4be2015-08-12 17:45:36 +0000137 while True:
138 try:
139 input_file = input_file_queue.get_nowait()
140 except Queue.Empty:
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000141 # No more work left in the queue.
Michael Thvedt828a4be2015-08-12 17:45:36 +0000142 return
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000143
144 try:
145 deps = []
Rumou Duana1a13ae2016-07-26 17:23:26 +0000146 entry = os.path.relpath(os.path.splitext(input_file)[0], output_root)
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000147 with file_open(input_file, 'r') as f:
148 for line in f:
Rumou Duana1a13ae2016-07-26 17:23:26 +0000149 include = _INCLUDE_RE.match(line)
Rumou Duan49cdb4b2015-12-04 18:03:44 +0000150 if include:
151 include_path = include.group(2)
152 dep = os.path.splitext(include_path)[0]
153 if dep != entry:
154 deps.append(dep)
155 output_dep_mapping_queue.put((entry, deps))
156 except Exception as e: # pylint: disable=broad-except
157 error_message_queue.put(str(e))
158 finally:
159 # We need to mark the task done to prevent blocking the main process
160 # indefinitely.
161 input_file_queue.task_done()
Michael Thvedt828a4be2015-08-12 17:45:36 +0000162
Rumou Duan18742ad2015-09-02 23:45:03 +0000163
Rumou Duan123e1c32016-02-01 16:16:15 +0000164def WriteArchiveSourceMappingFile(compiled_archive_file_path,
165 output_archive_source_mapping_file,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000166 objc_files,
Rumou Duan123e1c32016-02-01 16:16:15 +0000167 file_open=open):
168 """Writes a mapping file between archive file to associated ObjC source files.
169
170 Args:
171 compiled_archive_file_path: The path of the archive file.
172 output_archive_source_mapping_file: A path of the mapping file to write to.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000173 objc_files: A list of ObjC files translated by J2ObjC.
Rumou Duan123e1c32016-02-01 16:16:15 +0000174 file_open: Reference to the builtin open function so it may be
175 overridden for testing.
176 Returns:
177 None.
178 """
179 with file_open(output_archive_source_mapping_file, 'w') as f:
Rumou Duana1a13ae2016-07-26 17:23:26 +0000180 for objc_file in objc_files:
181 f.write(compiled_archive_file_path + ':' + objc_file + '\n')
182
183
Rumou Duan18742ad2015-09-02 23:45:03 +0000184def _ParseArgs(j2objc_args):
185 """Separate arguments passed to J2ObjC into source files and J2ObjC flags.
186
187 Args:
188 j2objc_args: A list of args to pass to J2ObjC transpiler.
189 Returns:
190 A tuple containing source files and J2ObjC flags
191 """
192 source_files = []
193 flags = []
194 is_next_flag_value = False
195 for j2objc_arg in j2objc_args:
196 if j2objc_arg.startswith('-'):
197 flags.append(j2objc_arg)
198 is_next_flag_value = True
199 elif is_next_flag_value:
200 flags.append(j2objc_arg)
201 is_next_flag_value = False
202 else:
203 source_files.append(j2objc_arg)
204 return (source_files, flags)
205
206
Rumou Duana1a13ae2016-07-26 17:23:26 +0000207def _J2ObjcOutputObjcFiles(java_files):
208 """Returns the relative paths of the associated output ObjC source files.
209
210 Args:
211 java_files: The list of Java files to translate.
212 Returns:
213 A list of associated output ObjC source files.
214 """
215 return [os.path.splitext(java_file)[0] + '.m' for java_file in java_files]
216
217
Rumou Duane7fd5392017-01-09 20:33:33 +0000218def UnzipSourceJarSources(source_jars):
219 """Unzips the source jars containing Java source files.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000220
221 Args:
Rumou Duane7fd5392017-01-09 20:33:33 +0000222 source_jars: The list of input Java source jars.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000223 Returns:
224 A tuple of the temporary output root and a list of root-relative paths of
225 unzipped Java files
226 """
Rumou Duane7fd5392017-01-09 20:33:33 +0000227 srcjar_java_files = []
228 if source_jars:
Rumou Duana1a13ae2016-07-26 17:23:26 +0000229 tmp_input_root = tempfile.mkdtemp()
Rumou Duane7fd5392017-01-09 20:33:33 +0000230 for source_jar in source_jars:
231 zip_ref = zipfile.ZipFile(source_jar, 'r')
232 zip_entries = []
Rumou Duana1a13ae2016-07-26 17:23:26 +0000233
Rumou Duane7fd5392017-01-09 20:33:33 +0000234 for file_entry in zip_ref.namelist():
235 # We only care about Java source files.
236 if file_entry.endswith('.java'):
237 zip_entries.append(file_entry)
Rumou Duana1a13ae2016-07-26 17:23:26 +0000238
Rumou Duane7fd5392017-01-09 20:33:33 +0000239 zip_ref.extractall(tmp_input_root, zip_entries)
240 zip_ref.close()
241 srcjar_java_files.extend(zip_entries)
242
243 return (tmp_input_root, srcjar_java_files)
Rumou Duana1a13ae2016-07-26 17:23:26 +0000244 else:
245 return None
246
247
248def RenameGenJarObjcFileRootInFileContent(tmp_objc_file_root,
249 j2objc_source_paths,
250 gen_src_jar, genjar_objc_files,
251 execute=subprocess.check_call):
252 """Renames references to temporary root inside ObjC sources from gen srcjar.
253
254 Args:
255 tmp_objc_file_root: The temporary output root containing ObjC sources.
256 j2objc_source_paths: The source paths used by J2ObjC.
257 gen_src_jar: The path of the gen srcjar.
258 genjar_objc_files: The list of ObjC sources translated from the gen srcjar.
259 execute: The function used to execute shell commands.
260 Returns:
261 None.
262 """
263 if genjar_objc_files:
264 abs_genjar_objc_source_files = [
265 os.path.join(tmp_objc_file_root, genjar_objc_file)
266 for genjar_objc_file in genjar_objc_files
267 ]
268 abs_genjar_objc_header_files = [
269 os.path.join(tmp_objc_file_root,
270 os.path.splitext(genjar_objc_file)[0] + '.h')
271 for genjar_objc_file in genjar_objc_files
272 ]
273
274 # We execute a command to change all references of the temporary Java root
275 # where we unzipped the gen srcjar sources, to the actual gen srcjar that
276 # contains the original Java sources.
277 cmd = [
278 'sed',
279 '-i',
280 '-e',
281 's|%s/|%s::|g' % (j2objc_source_paths[1], gen_src_jar)
282 ]
283 cmd.extend(abs_genjar_objc_source_files)
284 cmd.extend(abs_genjar_objc_header_files)
285 execute(cmd, stderr=subprocess.STDOUT)
286
287
Rumou Duand7cdc552016-11-03 19:42:48 +0000288def MoveObjcFileToFinalOutputRoot(objc_files,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000289 tmp_objc_file_root,
290 final_objc_file_root,
291 suffix,
292 os_module=os,
293 shutil_module=shutil):
Rumou Duand7cdc552016-11-03 19:42:48 +0000294 """Moves ObjC files from temporary location to the final output location.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000295
296 Args:
Rumou Duand7cdc552016-11-03 19:42:48 +0000297 objc_files: The list of objc files to move.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000298 tmp_objc_file_root: The temporary output root containing ObjC sources.
299 final_objc_file_root: The final output root.
Rumou Duand7cdc552016-11-03 19:42:48 +0000300 suffix: The suffix of the files to move.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000301 os_module: The os python module.
302 shutil_module: The shutil python module.
303 Returns:
304 None.
305 """
306 for objc_file in objc_files:
307 file_with_suffix = os_module.path.splitext(objc_file)[0] + suffix
308 dest_path = os_module.path.join(
309 final_objc_file_root, file_with_suffix)
310 dest_path_dir = os_module.path.dirname(dest_path)
311
312 if not os_module.path.isdir(dest_path_dir):
313 try:
314 os_module.makedirs(dest_path_dir)
315 except OSError as e:
316 if e.errno != errno.EEXIST or not os_module.path.isdir(dest_path_dir):
317 raise
318
Rumou Duand7cdc552016-11-03 19:42:48 +0000319 shutil_module.move(
Rumou Duana1a13ae2016-07-26 17:23:26 +0000320 os_module.path.join(tmp_objc_file_root, file_with_suffix),
321 dest_path)
322
323
324def PostJ2ObjcFileProcessing(normal_objc_files, genjar_objc_files,
325 tmp_objc_file_root, final_objc_file_root,
326 j2objc_source_paths, gen_src_jar,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000327 output_gen_source_dir, output_gen_header_dir):
328 """Performs cleanups on ObjC files and moves them to final output location.
329
330 Args:
331 normal_objc_files: The list of objc files translated from normal Java files.
332 genjar_objc_files: The list of ObjC sources translated from the gen srcjar.
333 tmp_objc_file_root: The temporary output root containing ObjC sources.
334 final_objc_file_root: The final output root.
335 j2objc_source_paths: The source paths used by J2ObjC.
336 gen_src_jar: The path of the gen srcjar.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000337 output_gen_source_dir: The final output directory of ObjC source files
338 translated from gen srcjar. Maybe null.
339 output_gen_header_dir: The final output directory of ObjC header files
340 translated from gen srcjar. Maybe null.
341 Returns:
342 None.
343 """
344 RenameGenJarObjcFileRootInFileContent(tmp_objc_file_root,
345 j2objc_source_paths,
346 gen_src_jar,
347 genjar_objc_files)
Rumou Duand7cdc552016-11-03 19:42:48 +0000348 MoveObjcFileToFinalOutputRoot(normal_objc_files,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000349 tmp_objc_file_root,
350 final_objc_file_root,
351 '.m')
Rumou Duand7cdc552016-11-03 19:42:48 +0000352 MoveObjcFileToFinalOutputRoot(normal_objc_files,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000353 tmp_objc_file_root,
354 final_objc_file_root,
355 '.h')
356
Rumou Duana1a13ae2016-07-26 17:23:26 +0000357 if output_gen_source_dir:
Rumou Duand7cdc552016-11-03 19:42:48 +0000358 MoveObjcFileToFinalOutputRoot(
Rumou Duana1a13ae2016-07-26 17:23:26 +0000359 genjar_objc_files,
360 tmp_objc_file_root,
361 output_gen_source_dir,
362 '.m')
363
364 if output_gen_header_dir:
Rumou Duand7cdc552016-11-03 19:42:48 +0000365 MoveObjcFileToFinalOutputRoot(
Rumou Duana1a13ae2016-07-26 17:23:26 +0000366 genjar_objc_files,
367 tmp_objc_file_root,
368 output_gen_header_dir,
369 '.h')
370
371
372def GenerateJ2objcMappingFiles(normal_objc_files,
373 genjar_objc_files,
374 tmp_objc_file_root,
375 output_dependency_mapping_file,
376 output_archive_source_mapping_file,
377 compiled_archive_file_path):
378 """Generates J2ObjC mapping files.
379
380 Args:
381 normal_objc_files: The list of objc files translated from normal Java files.
382 genjar_objc_files: The list of ObjC sources translated from the gen srcjar.
383 tmp_objc_file_root: The temporary output root containing ObjC sources.
384 output_dependency_mapping_file: The path of the dependency mapping file to
385 write to.
386 output_archive_source_mapping_file: A path of the mapping file to write to.
387 compiled_archive_file_path: The path of the archive file.
388 Returns:
389 None.
390 """
391 WriteDepMappingFile(normal_objc_files + genjar_objc_files,
392 tmp_objc_file_root,
393 output_dependency_mapping_file)
394
395 if output_archive_source_mapping_file:
396 WriteArchiveSourceMappingFile(compiled_archive_file_path,
397 output_archive_source_mapping_file,
398 normal_objc_files + genjar_objc_files)
399
400
401def main():
Rumou Duanab16dd62015-08-18 21:52:08 +0000402 parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
Michael Thvedt828a4be2015-08-12 17:45:36 +0000403 parser.add_argument(
404 '--java',
405 required=True,
406 help='The path to the Java executable.')
407 parser.add_argument(
408 '--jvm_flags',
Googler1672c762016-12-21 16:15:02 +0000409 default='-Xss4m',
Michael Thvedt828a4be2015-08-12 17:45:36 +0000410 help='A comma-separated list of flags to pass to the JVM.')
411 parser.add_argument(
412 '--j2objc',
413 required=True,
414 help='The path to the J2ObjC deploy jar.')
415 parser.add_argument(
416 '--main_class',
417 required=True,
418 help='The main class of the J2ObjC deploy jar to execute.')
Rumou Duana1a13ae2016-07-26 17:23:26 +0000419 # TODO(rduan): Remove, no longer needed.
Michael Thvedt828a4be2015-08-12 17:45:36 +0000420 parser.add_argument(
421 '--translated_source_files',
Rumou Duand7cdc552016-11-03 19:42:48 +0000422 required=False,
Michael Thvedt828a4be2015-08-12 17:45:36 +0000423 help=('A comma-separated list of file paths where J2ObjC will write the '
424 'translated files to.'))
425 parser.add_argument(
426 '--output_dependency_mapping_file',
427 required=True,
428 help='The file path of the dependency mapping file to write to.')
429 parser.add_argument(
Rumou Duana1a13ae2016-07-26 17:23:26 +0000430 '--objc_file_path', '-d',
Michael Thvedt828a4be2015-08-12 17:45:36 +0000431 required=True,
432 help=('The file path which represents a directory where the generated '
433 'ObjC files reside.'))
Rumou Duan123e1c32016-02-01 16:16:15 +0000434 parser.add_argument(
435 '--output_archive_source_mapping_file',
436 help='The file path of the mapping file containing mappings between the '
437 'translated source files and the to-be-generated archive file '
438 'compiled from those source files. --compile_archive_file_path must '
439 'be specified if this option is specified.')
440 parser.add_argument(
441 '--compiled_archive_file_path',
442 required=False,
443 help=('The archive file path that will be produced by ObjC compile action'
444 ' later'))
Rumou Duane7fd5392017-01-09 20:33:33 +0000445 # TODO(rduan): Remove this flag once it is fully replaced by flag --src_jars.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000446 parser.add_argument(
447 '--gen_src_jar',
448 required=False,
449 help='The jar containing Java sources generated by annotation processor.')
450 parser.add_argument(
Rumou Duane7fd5392017-01-09 20:33:33 +0000451 '--src_jars',
452 required=False,
453 help='The list of Java source jars containg Java sources to translate.')
454 parser.add_argument(
Rumou Duana1a13ae2016-07-26 17:23:26 +0000455 '--output_gen_source_dir',
456 required=False,
457 help='The output directory of ObjC source files translated from the gen'
458 ' srcjar')
459 parser.add_argument(
460 '--output_gen_header_dir',
461 required=False,
462 help='The output directory of ObjC header files translated from the gen'
463 ' srcjar')
Michael Thvedt828a4be2015-08-12 17:45:36 +0000464
Rumou Duana1a13ae2016-07-26 17:23:26 +0000465 args, pass_through_args = parser.parse_known_args()
466 normal_java_files, j2objc_flags = _ParseArgs(pass_through_args)
Rumou Duane7fd5392017-01-09 20:33:33 +0000467 srcjar_java_files = []
Rumou Duana1a13ae2016-07-26 17:23:26 +0000468 j2objc_source_paths = [os.getcwd()]
469
Rumou Duane7fd5392017-01-09 20:33:33 +0000470 # Unzip the source jars, so J2ObjC can translate the contained sources.
Rumou Duana1a13ae2016-07-26 17:23:26 +0000471 # Also add the temporary directory containing the unzipped sources as a source
472 # path for J2ObjC, so it can find these sources.
Rumou Duane7fd5392017-01-09 20:33:33 +0000473 source_jars = []
474 if args.gen_src_jar:
475 source_jars.append(args.gen_src_jar)
476 if args.src_jars:
477 source_jars.extend(args.src_jars.split(','))
478
479 srcjar_source_tuple = UnzipSourceJarSources(source_jars)
480 if srcjar_source_tuple:
481 j2objc_source_paths.append(srcjar_source_tuple[0])
482 srcjar_java_files = srcjar_source_tuple[1]
Rumou Duana1a13ae2016-07-26 17:23:26 +0000483
484 # Run J2ObjC over the normal input Java files and unzipped gen jar Java files.
485 # The output is stored in a temporary directory.
486 tmp_objc_file_root = tempfile.mkdtemp()
Michael Thvedt828a4be2015-08-12 17:45:36 +0000487 RunJ2ObjC(args.java,
488 args.jvm_flags,
489 args.j2objc,
490 args.main_class,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000491 tmp_objc_file_root,
492 j2objc_flags,
493 j2objc_source_paths,
Rumou Duane7fd5392017-01-09 20:33:33 +0000494 normal_java_files + srcjar_java_files)
Rumou Duan123e1c32016-02-01 16:16:15 +0000495
Rumou Duana1a13ae2016-07-26 17:23:26 +0000496 # Calculate the relative paths of generated objc files.
497 normal_objc_files = _J2ObjcOutputObjcFiles(normal_java_files)
Rumou Duane7fd5392017-01-09 20:33:33 +0000498 genjar_objc_files = _J2ObjcOutputObjcFiles(srcjar_java_files)
Rumou Duana1a13ae2016-07-26 17:23:26 +0000499
500 # Generate J2ObjC mapping files needed for distributed builds.
501 GenerateJ2objcMappingFiles(normal_objc_files,
502 genjar_objc_files,
503 tmp_objc_file_root,
504 args.output_dependency_mapping_file,
505 args.output_archive_source_mapping_file,
506 args.compiled_archive_file_path)
507
Rumou Duand7cdc552016-11-03 19:42:48 +0000508 # Post J2ObjC-run processing, involving file editing, zipping and moving
Rumou Duana1a13ae2016-07-26 17:23:26 +0000509 # files to their final output locations.
510 PostJ2ObjcFileProcessing(
511 normal_objc_files,
512 genjar_objc_files,
513 tmp_objc_file_root,
514 args.objc_file_path,
515 j2objc_source_paths,
516 args.gen_src_jar,
Rumou Duana1a13ae2016-07-26 17:23:26 +0000517 args.output_gen_source_dir,
518 args.output_gen_header_dir)
519
520if __name__ == '__main__':
521 main()