universal7885: generate_product_makefiles: Rework, add MikuUI VF

This commit is contained in:
roynatech2544 2024-04-04 22:03:42 +09:00
commit 36df3ce4ac

View file

@ -11,67 +11,97 @@ def log(x):
if (debug): if (debug):
print(x) print(x)
def writeln(f, txt): def writeln(f, txt = ''):
print(txt, file=f) print(txt, file=f)
def check_exist_mk(path, mk): class GenerateMK():
ret = exists(path) def __init__(self, vendor):
if ret: self.config_mk_path = None
writeln(mk, f'$(call inherit-product, {path})') self.vendor = vendor
return ret
def write_one_dev_makefile(device, vendor): def check_exist_mk(self, path, mk):
device_path = f'{DEVICE_BASE}/{device}' if self.config_mk_path is None and exists(path):
log(f'Write entry => {device_path}') self.set_config_path(path)
with open(f'{device_path}/AndroidProducts.mk', 'w') as ap:
writeln(ap, f'# Auto-Generated by {__file__}')
writeln(ap, f'PRODUCT_MAKEFILES += $(LOCAL_DIR)/{vendor}_{device}.mk')
with open(f'{device_path}/{vendor}_{device}.mk', 'w') as mk:
writeln(mk, f'# Auto-Generated by {__file__}')
writeln(mk, f'$(call inherit-product, {device_path}/full_{device}.mk)')
existed = False
existed |= check_exist_mk(f'vendor/{vendor}/config/common_full_phone.mk', mk)
existed |= check_exist_mk(f'vendor/{vendor}/config/common.mk', mk)
existed |= check_exist_mk(f'vendor/{vendor}/config/rising.mk', mk)
if not existed:
raise RuntimeError(EX_RUNTIME_STR)
writeln(mk, '')
writeln(mk, f'PRODUCT_NAME := {vendor}_{device}')
writeln(mk, '')
if device in HD_DEVICES:
writeln(mk, 'TARGET_BOOT_ANIMATION_RES := 720')
else:
writeln(mk, 'TARGET_BOOT_ANIMATION_RES := 1080')
writeln(mk, 'TARGET_USES_MINI_GAPPS := true')
log(f'Write entry <= {device_path}')
def check_makefile(mk, vendor): def set_config_path(self, path: str):
devices = os.listdir(DEVICE_BASE) self.config_mk_path = path
log(f'Check MK => {mk}') def write_one_dev_makefile(self, device):
if exists(mk): device_path = f'{DEVICE_BASE}/{device}'
log(f'Check MK <= {mk} exist') vendor = self.vendor
for i in devices: log(f'Write entry => {device_path}')
with open(f'{device_path}/AndroidProducts.mk', 'w') as ap:
writeln(ap, f'# Auto-Generated by {__file__}')
writeln(ap, f'PRODUCT_MAKEFILES += $(LOCAL_DIR)/{vendor}_{device}.mk')
with open(f'{device_path}/{vendor}_{device}.mk', 'w') as mk:
writeln(mk, f'# Auto-Generated by {__file__}')
writeln(mk, f'$(call inherit-product, {device_path}/full_{device}.mk)')
existed = False
if self.config_mk_path is None:
self.check_exist_mk(f'vendor/{vendor}/config/common_full_phone.mk', mk)
self.check_exist_mk(f'vendor/{vendor}/config/common.mk', mk)
if self.config_mk_path is None:
raise RuntimeError(EX_RUNTIME_STR)
writeln(mk, f'$(call inherit-product, {self.config_mk_path})')
writeln(mk)
writeln(mk, f'PRODUCT_NAME := {vendor}_{device}')
writeln(mk)
if device in HD_DEVICES:
writeln(mk, 'TARGET_BOOT_ANIMATION_RES := 720')
else:
writeln(mk, 'TARGET_BOOT_ANIMATION_RES := 1080')
writeln(mk, 'TARGET_USES_MINI_GAPPS := true')
log(f'Write entry <= {device_path}')
def write_makefiles(self):
devices = os.listdir(DEVICE_BASE)
for i in devices:
if not i[:1] == 'a': if not i[:1] == 'a':
log(f'Skip entry: {i}') log(f'Skip entry: {i}')
continue continue
write_one_dev_makefile(i, vendor) self.write_one_dev_makefile(i)
return True
return False def check_makefile(self, mk):
log(f'Check MK => {mk}')
if exists(mk):
log(f'Check MK <= {mk} exist')
self.write_makefiles()
return True
return False
# Hardcode paths for certain ROMs
class VendorFixer():
def __init__(self, makefile_path, vendor_folder):
self.mkpath = makefile_path
self.vfolder = vendor_folder
def check(self):
mkpath = f'vendor/{self.vfolder}/{self.mkpath}'
if exists(mkpath):
log(f'APPLY VF: Overriding to path: {mkpath}')
g_mk = GenerateMK(self.vfolder)
g_mk.set_config_path(mkpath)
g_mk.write_makefiles()
return True
return False
RisingVF = VendorFixer('config/rising.mk', 'rising')
MikuVF = VendorFixer('build/product/miku_product.mk', 'miku')
TestVF = VendorFixer('config/my_ss.mk', 'ss')
def main(): def main():
vendors = os.listdir('vendor') vendors = os.listdir('vendor')
ok = False ok = False
if 'rising' in vendors: for vf in [RisingVF, MikuVF, TestVF]:
mk = 'vendor/rising/config/rising.mk' if vf.check():
ok |= check_makefile(mk, 'rising') return
else:
for vendor in vendors: for vendor in vendors:
mk = f'vendor/{vendor}/config/common.mk' mk = f'vendor/{vendor}/config/common.mk'
ok |= check_makefile(mk, vendor) ok |= GenerateMK(vendor).check_makefile(mk)
if ok: if ok:
break break
if not ok: if not ok:
raise RuntimeError(EX_RUNTIME_STR) raise RuntimeError(EX_RUNTIME_STR)