Snap for 8512216 from d74b74010472ba957f4125b676a41c23ca91e549 to tm-frc-adbd-release

Change-Id: I7ec9e6db63600d0aa2a365997ea853615eea9f1c
diff --git a/split/manifest_split.py b/split/manifest_split.py
index d5f9b95..5114f24 100644
--- a/split/manifest_split.py
+++ b/split/manifest_split.py
@@ -121,10 +121,12 @@
       this project, for projects that should be added to the resulting manifest.
     path_mappings: A list of PathMappingConfigs to modify a path in the build
       sandbox to the path in the manifest.
+    ignore_paths: Set of paths to ignore when parsing module_info_file
   """
   remove_projects: Dict[str, str]
   add_projects: Dict[str, str]
   path_mappings: List[PathMappingConfig]
+  ignore_paths: Set[str]
 
   @classmethod
   def from_config_files(cls, config_files: List[str]):
@@ -139,6 +141,8 @@
     remove_projects: Dict[str, str] = {}
     add_projects: Dict[str, str] = {}
     path_mappings = []
+    """ Always ignore paths in out/ directory. """
+    ignore_paths = set(["out/"])
     for config_file in config_files:
       root = ET.parse(config_file).getroot()
 
@@ -155,7 +159,10 @@
           for child in root.findall("path_mapping")
       ])
 
-    return cls(remove_projects, add_projects, path_mappings)
+      ignore_paths.update(
+          {c.attrib["name"]: config_file for c in root.findall("ignore_path")})
+
+    return cls(remove_projects, add_projects, path_mappings, ignore_paths)
 
 
 def get_repo_projects(repo_list_file, manifest, path_mappings):
@@ -195,7 +202,7 @@
 class ModuleInfo:
   """Contains various mappings to/from module/project"""
 
-  def __init__(self, module_info_file, repo_projects):
+  def __init__(self, module_info_file, repo_projects, ignore_paths):
     """Initialize a module info instance.
 
     Builds various maps related to platform build system modules and how they
@@ -204,6 +211,7 @@
     Args:
       module_info_file: The path to a module-info.json file from a build.
       repo_projects: The output of the get_repo_projects function.
+      ignore_paths: Set of paths to ignore from module_info_file data
 
     Raises:
       ValueError: A module from module-info.json belongs to a path not
@@ -221,14 +229,18 @@
     with open(module_info_file) as module_info_file:
       module_info = json.load(module_info_file)
 
+    # Check that module contains a path and the path is not in set of
+    # ignore paths
     def module_has_valid_path(module):
-      return ("path" in module_info[module] and module_info[module]["path"] and
-              not module_info[module]["path"][0].startswith("out/"))
+      paths = module.get("path")
+      if not paths:
+        return False
+      return all(not paths[0].startswith(p) for p in ignore_paths)
 
     module_paths = {
         module: module_info[module]["path"][0]
         for module in module_info
-        if module_has_valid_path(module)
+        if module_has_valid_path(module_info[module])
     }
     module_project_paths = {
         module: scan_repo_projects(repo_projects, module_paths[module])
@@ -519,7 +531,8 @@
 
   # While we still have projects whose modules we haven't checked yet,
   if module_info_file:
-    module_info = ModuleInfo(module_info_file, repo_projects)
+    module_info = ModuleInfo(module_info_file, repo_projects,
+                             config.ignore_paths)
     checked_projects = set()
     projects_to_check = input_projects.difference(checked_projects)
     logger.info("Checking module-info dependencies for direct and adjacent modules...")
diff --git a/split/manifest_split_test.py b/split/manifest_split_test.py
index 73976cc..d9c6f76 100644
--- a/split/manifest_split_test.py
+++ b/split/manifest_split_test.py
@@ -121,8 +121,9 @@
           'system/project4': 'platform/project4',
           'vendor/google/project3': 'vendor/project3',
       }
+      ignore_paths = set(['out/'])
       module_info = manifest_split.ModuleInfo(module_info_file.name,
-                                              repo_projects)
+                                              repo_projects, ignore_paths)
       self.assertEqual(
           module_info.project_modules, {
               'platform/project1': set(['target1a', 'target1b']),
@@ -163,9 +164,11 @@
       }""")
       module_info_file.flush()
       repo_projects = {}
+      ignore_paths = set()
       with self.assertRaisesRegex(ValueError,
                                   'Unknown module path for module target1'):
-        manifest_split.ModuleInfo(module_info_file.name, repo_projects)
+        manifest_split.ModuleInfo(module_info_file.name, repo_projects,
+                                  ignore_paths)
 
   @unittest.mock.patch.object(subprocess, 'check_output', autospec=True)
   def test_get_ninja_inputs(self, mock_check_output):
diff --git a/vf/merge.sh b/vf/merge.sh
index 372bb0e..8e76241 100755
--- a/vf/merge.sh
+++ b/vf/merge.sh
@@ -11,7 +11,6 @@
     d) DIST_DIR=${OPTARG} ;;
     v) VENDOR_DIR=${OPTARG} ;;
     b) BUILD_ID=${OPTARG} ;;
-    # TODO(b/170638547) Remove the need for merge configs.
     m) MERGE_CONFIG_DIR=${OPTARG} ;;
     r) HAS_RADIO_IMG=${OPTARG} ;;
     *) echo "Unexpected argument: -${OPTARG}" >&2 ;;
@@ -34,10 +33,6 @@
   echo "error: -b build id argument not set"
   exit 1
 fi
-if [[ -z "${MERGE_CONFIG_DIR}" ]]; then
-  echo "error: -m merge config dir argument not set"
-  exit 1
-fi
 if [[ -z "${HAS_RADIO_IMG}" ]]; then
   HAS_RADIO_IMG="true"
 fi
@@ -52,16 +47,20 @@
 source build/envsetup.sh
 lunch ${TARGET}-userdebug
 
+EXTRA_FLAGS=""
+if [[ "${MERGE_CONFIG_DIR}" ]]; then
+  EXTRA_FLAGS+=" --framework-item-list ${MERGE_CONFIG_DIR}/framework_item_list.txt \
+  --framework-misc-info-keys ${MERGE_CONFIG_DIR}/framework_misc_info_keys.txt \
+  --vendor-item-list ${MERGE_CONFIG_DIR}/vendor_item_list.txt"
+fi
 out/host/linux-x86/bin/merge_target_files \
   --framework-target-files ${SYSTEM_DIR}/${TARGET}-target_files*.zip \
   --vendor-target-files ${VENDOR_DIR}/*-target_files-*.zip \
-  --framework-item-list ${MERGE_CONFIG_DIR}/framework_item_list.txt \
-  --framework-misc-info-keys ${MERGE_CONFIG_DIR}/framework_misc_info_keys.txt \
-  --vendor-item-list ${MERGE_CONFIG_DIR}/vendor_item_list.txt \
   --allow-duplicate-apkapex-keys \
   --output-target-files ${DIST_DIR}/${TARGET}-target_files-${BUILD_ID}.zip \
   --output-img  ${DIST_DIR}/${TARGET}-img-${BUILD_ID}.zip \
-  --output-ota  ${DIST_DIR}/${TARGET}-ota-${BUILD_ID}.zip
+  --output-ota  ${DIST_DIR}/${TARGET}-ota-${BUILD_ID}.zip \
+  ${EXTRA_FLAGS}
 
 # Copy bootloader.img, radio.img, and android-info.txt, needed for flashing.
 cp ${VENDOR_DIR}/bootloader.img ${DIST_DIR}/bootloader.img
@@ -70,6 +69,11 @@
   cp ${VENDOR_DIR}/radio.img ${DIST_DIR}/radio.img
 fi
 
+# Copy vendor otatools.zip, needed by sign_target_files_apks
+if [[ -f "${VENDOR_DIR}/otatools.zip" ]]; then
+  cp ${VENDOR_DIR}/otatools.zip ${DIST_DIR}/otatools_vendor.zip
+fi
+
 unzip -j -d ${DIST_DIR} \
   ${VENDOR_DIR}/*-target_files-*.zip \
-  OTA/android-info.txt
+  OTA/android-info.txt
\ No newline at end of file