Pack file_contexts into target_files zip.

file_contexts (specified by SELINUX_FC) is needed both when building
and (re)packaging. We used to use the copy in out/ when building, and
looked for the copy in BOOT/RAMDISK/ when packaging from target_files
zip. With system_root_image enabled, the file_contexts needed for
building and packaging might be different from the one on device. So
we explicitly pack the file as META/file_contexts in target_files zip.

Also refactor out the overriding of selinux_fc property into
common.LoadInfoDict().

Change-Id: I0781a147319148c76d989d8f29d5ef766a502dbd
This commit is contained in:
Tao Bao
2015-07-09 11:51:16 -07:00
parent 85a26d5a61
commit aa7318c384
5 changed files with 28 additions and 38 deletions

View File

@@ -97,7 +97,7 @@ def CloseInheritedPipes():
pass
def LoadInfoDict(input_file):
def LoadInfoDict(input_file, input_dir=None):
"""Read and parse the META/misc_info.txt key/value pairs from the
input target files and return a dict."""
@@ -148,6 +148,23 @@ def LoadInfoDict(input_file):
if "fstab_version" not in d:
d["fstab_version"] = "1"
# During building, we use the "file_contexts" in the out/ directory tree.
# It is no longer available when (re)generating from target_files zip. So
# when generating from target_files zip, we look for a copy under META/
# first, if not available search under BOOT/RAMDISK/. Note that we may need
# a different file_contexts to build images than the one running on device,
# such as when enabling system_root_image. In that case, we must have the
# one for building copied to META/.
if input_dir is not None:
fc_config = os.path.join(input_dir, "META", "file_contexts")
if not os.path.exists(fc_config):
fc_config = os.path.join(input_dir, "BOOT", "RAMDISK", "file_contexts")
if not os.path.exists(fc_config):
fc_config = None
if fc_config:
d["selinux_fc"] = fc_config
try:
data = read_helper("META/imagesizes.txt")
for line in data.split("\n"):