You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
import os
|
|
import subprocess
|
|
|
|
from android_java.stage import Stage
|
|
|
|
|
|
class CompilerStage(Stage):
|
|
def __init__(self, source_root):
|
|
super().__init__(source_root)
|
|
self.make_droid_dir()
|
|
|
|
def create_ecj_command(self):
|
|
cmdline = ["ecj", "-cp", "."]
|
|
cmdline += ["-d", self.droid_dir]
|
|
return cmdline
|
|
|
|
def compile(self, class_file):
|
|
command = self.create_ecj_command()
|
|
command.append(class_file)
|
|
subprocess.check_call(command)
|
|
|
|
def dx_command_batches(self):
|
|
i = 0
|
|
current_batch_template = [
|
|
"dx",
|
|
"--dex",
|
|
"--output={}".format(os.path.join(self.droid_dir, "classes.dex")),
|
|
]
|
|
current_batch = current_batch_template.copy()
|
|
for root, _, files in os.walk(self.droid_dir):
|
|
for file in (os.path.join(root, file) for file in files):
|
|
if file.endswith(".class"):
|
|
current_batch.append(file)
|
|
i += 1
|
|
if i == 100:
|
|
yield current_batch
|
|
current_batch = current_batch_template.copy()
|
|
i = 0
|
|
if i != 100:
|
|
yield current_batch
|
|
|
|
def compile_dex(self):
|
|
for batch in self.dx_command_batches():
|
|
subprocess.check_call(batch)
|