Skip to content

Commit b059613

Browse files
ArianK16abgcngm
authored andcommitted
extract_utils: Add support to create filegroups of proprietary files
Change-Id: I59d7995f67c7af061c59b44f3ce4aa6f169f6a9d
1 parent caf3702 commit b059613

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

extract_utils/file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class FileArgs(str, Enum):
6161
SKIPAPKCHECKS = 'SKIPAPKCHECKS'
6262
SYMLINK = 'SYMLINK'
6363
TRYSRCFIRST = 'TRYSRCFIRST'
64+
FILEGROUP = 'FILEGROUP'
6465

6566

6667
FILE_ARGS_TYPE_MAP = {
@@ -84,6 +85,7 @@ class FileArgs(str, Enum):
8485
FileArgs.SKIPAPKCHECKS: True,
8586
FileArgs.SYMLINK: list,
8687
FileArgs.TRYSRCFIRST: True,
88+
FileArgs.FILEGROUP: list,
8789
}
8890

8991
assert len(FileArgs) == len(FILE_ARGS_TYPE_MAP)
@@ -302,6 +304,10 @@ def inferred_bits(self):
302304
else:
303305
raise ValueError(f'Cannot infer bits from file path: {self.src}')
304306

307+
@property
308+
def filegroups(self):
309+
return self.args.get(FileArgs.FILEGROUP)
310+
305311

306312
T = TypeVar('T')
307313

@@ -496,6 +502,7 @@ def __init__(
496502
self.boot_jars = FileTree()
497503
self.dummy_shared_libs = FileTree()
498504
self.package_symlinks = SimpleFileList()
505+
self.filegroup_files = SimpleFileList()
499506
self.copy_files = SimpleFileList()
500507
self.all_files = SimpleFileList()
501508

@@ -541,6 +548,9 @@ def __add_file(self, file: File, section: Optional[str]):
541548
self.dummy_shared_libs.add(file)
542549
return
543550

551+
if FileArgs.FILEGROUP in file.args:
552+
self.filegroup_files.add(file)
553+
544554
if self.__section is None or (
545555
section is not None and fnmatch.fnmatch(section, self.__section)
546556
):

extract_utils/makefiles.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import os
9+
from collections import defaultdict
910
from contextlib import ExitStack, contextmanager
1011
from json import JSONEncoder
1112
from typing import Iterable, List, Optional, Protocol, TextIO
@@ -690,6 +691,33 @@ def write_symlink_packages(
690691
write_packages_inclusion(package_names, ctx.product_mk_out)
691692

692693

694+
def write_filegroups(
695+
ctx: MakefilesCtx,
696+
vendor_rel_sub_path: str,
697+
files: Iterable[File],
698+
):
699+
encoder = BpJSONEncoder(legacy=ctx.legacy)
700+
filegroup_to_files = defaultdict(list)
701+
702+
for file in files:
703+
filegroups = file.filegroups
704+
assert isinstance(filegroups, list)
705+
706+
for filegroup in filegroups:
707+
filegroup_to_files[filegroup].append(file)
708+
709+
for filegroup, files in filegroup_to_files.items():
710+
(
711+
BpBuilder(encoder)
712+
.set_rule_name('filegroup')
713+
.name(filegroup)
714+
.set(
715+
'srcs', [f'{vendor_rel_sub_path}/{file.dst}' for file in files]
716+
)
717+
.write(ctx.bp_out)
718+
)
719+
720+
693721
def write_mk_firmware_ab_partitions(files: Iterable[File], out: TextIO):
694722
has_ab = False
695723
for file in files:

extract_utils/module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
write_bp_header,
3030
write_bp_soong_namespaces,
3131
write_dummy_shared_libs,
32+
write_filegroups,
3233
write_mk_firmware,
3334
write_mk_firmware_ab_partitions,
3435
write_mk_firmware_file,
@@ -211,6 +212,12 @@ def write_makefiles(self, module: ExtractUtilsModule, ctx: MakefilesCtx):
211212
self.file_list.package_symlinks,
212213
)
213214

215+
write_filegroups(
216+
ctx,
217+
self.vendor_rel_sub_path,
218+
self.file_list.filegroup_files,
219+
)
220+
214221
write_boot_jars(
215222
ctx,
216223
self.file_list.boot_jars,

0 commit comments

Comments
 (0)