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):
print(x)
def writeln(f, txt):
def writeln(f, txt = ''):
print(txt, file=f)
def check_exist_mk(path, mk):
ret = exists(path)
if ret:
writeln(mk, f'$(call inherit-product, {path})')
return ret
class GenerateMK():
def __init__(self, vendor):
self.config_mk_path = None
self.vendor = vendor
def write_one_dev_makefile(device, vendor):
device_path = f'{DEVICE_BASE}/{device}'
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
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_exist_mk(self, path, mk):
if self.config_mk_path is None and exists(path):
self.set_config_path(path)
def check_makefile(mk, vendor):
devices = os.listdir(DEVICE_BASE)
def set_config_path(self, path: str):
self.config_mk_path = path
log(f'Check MK => {mk}')
if exists(mk):
log(f'Check MK <= {mk} exist')
for i in devices:
def write_one_dev_makefile(self, device):
device_path = f'{DEVICE_BASE}/{device}'
vendor = self.vendor
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':
log(f'Skip entry: {i}')
continue
write_one_dev_makefile(i, vendor)
return True
return False
self.write_one_dev_makefile(i)
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():
vendors = os.listdir('vendor')
ok = False
if 'rising' in vendors:
mk = 'vendor/rising/config/rising.mk'
ok |= check_makefile(mk, 'rising')
else:
for vendor in vendors:
mk = f'vendor/{vendor}/config/common.mk'
ok |= check_makefile(mk, vendor)
if ok:
break
for vf in [RisingVF, MikuVF, TestVF]:
if vf.check():
return
for vendor in vendors:
mk = f'vendor/{vendor}/config/common.mk'
ok |= GenerateMK(vendor).check_makefile(mk)
if ok:
break
if not ok:
raise RuntimeError(EX_RUNTIME_STR)