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.
 

50 lines
1.4 KiB

import os
import subprocess
os.mkdir
def make_droid_dir(root):
droid_dir = os.path.join(root, ".droid")
os.makedirs(droid_dir, exist_ok=True)
return droid_dir
class CompilerStage:
def __init__(self, source_root):
self.source_root = source_root
self.droid_dir = make_droid_dir(source_root)
def create_ecj_command(self):
cmdline = ["ecj"]
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)