def as_staging(input_path, always_stage=False): """Convert an input path to a staging path. example input: android/frameworks/base/... example staging: STAGING_ROOT/android/frameworks/base/... """ if always_stage or is_in_staging(input_path): return os.path.join(build_common.get_staging_root(), input_path) else: return input_path
def get_composite_paths(staging_path): if not staging_path.startswith(build_common.get_staging_root()): return None, None rel_path = os.path.relpath(staging_path, build_common.get_staging_root()) return (os.path.join('third_party', rel_path), os.path.join('mods', rel_path))
def create_staging(): timer = build_common.SimpleTimer() timer.start('Staging source files', True) staging_root = build_common.get_staging_root() # Store where all the old staging links pointed so we can compare after. old_staging_links = _get_link_targets(staging_root) if os.path.lexists(staging_root): file_util.rmtree(staging_root) _create_symlink_tree(_MODS_DIR, _THIRD_PARTY_DIR, staging_root) # internal/ is an optional checkout if build_options.OPTIONS.internal_apks_source_is_internal(): assert build_common.has_internal_checkout() for name in os.listdir(_INTERNAL_THIRD_PARTY_PATH): if os.path.exists(os.path.join(_THIRD_PARTY_DIR, name)): raise Exception( 'Name conflict between internal/third_party and ' 'third_party: ' + name) _create_symlink_tree(_INTERNAL_MODS_PATH, _INTERNAL_THIRD_PARTY_PATH, staging_root) subprocess.check_call('internal/build/fix_staging.py') # src/ is not overlaid on any directory. _create_symlink_tree(_SRC_DIR, None, os.path.join(staging_root, 'src')) # Update modification time for files that do not point to the same location # that they pointed to in the previous tree to make sure they are built. if old_staging_links: new_staging_links = _get_link_targets(staging_root) # Every file (not directory) under staging is in either one of following # two states: # # F. The file itself is a symbolic link to a file under third_party or # mods. # D. Some ancestor directory is a symbolic link to a directory under # third_party. (It is important that we do not create symbolic links to # directories under mods) # # Let us say a file falls under "X-Y" case if it was in state X before # re-staging and now in state Y. For all 4 possible cases, we can check if # the actual destination of the file changed or not in the following way: # # F-F: We can just compare the target of the link. # F-D, D-F: The target may have changed, but it needs some complicated # computation to check. We treat them as changed to be conservative. # D-D: We can leave it as-is since both point third_party. # # So we want to visit all files in state F either in old staging or new # staging. For this purpose we can iterate through |*_staging_links| as # they contain all files in state F. # # Note that |*_staging_links| may contain directory symbolic links, but # it is okay to visit them too because directory timestamps do not matter. # Actually excluding directory symbolic links from |old_staging_links| is # difficult because link targets might be already removed. for path in set(list(old_staging_links) + list(new_staging_links)): if path in old_staging_links and path in new_staging_links: should_touch = old_staging_links[path] != new_staging_links[ path] else: should_touch = True if should_touch and os.path.exists(path): os.utime(path, None) timer.done() return True
def create_staging(): timer = build_common.SimpleTimer() timer.start('Staging source files', True) staging_root = build_common.get_staging_root() # Store where all the old staging links pointed so we can compare after. old_staging_links = _get_link_targets(staging_root) if os.path.lexists(staging_root): file_util.rmtree(staging_root) _create_symlink_tree(_MODS_DIR, _THIRD_PARTY_DIR, staging_root) # internal/ is an optional checkout if build_options.OPTIONS.internal_apks_source_is_internal(): assert build_common.has_internal_checkout() for name in os.listdir(_INTERNAL_THIRD_PARTY_PATH): if os.path.exists(os.path.join(_THIRD_PARTY_DIR, name)): raise Exception('Name conflict between internal/third_party and ' 'third_party: ' + name) _create_symlink_tree(_INTERNAL_MODS_PATH, _INTERNAL_THIRD_PARTY_PATH, staging_root) subprocess.check_call('internal/build/fix_staging.py') # src/ is not overlaid on any directory. _create_symlink_tree(_SRC_DIR, None, os.path.join(staging_root, 'src')) # Update modification time for files that do not point to the same location # that they pointed to in the previous tree to make sure they are built. if old_staging_links: new_staging_links = _get_link_targets(staging_root) # Every file (not directory) under staging is in either one of following # two states: # # F. The file itself is a symbolic link to a file under third_party or # mods. # D. Some ancestor directory is a symbolic link to a directory under # third_party. (It is important that we do not create symbolic links to # directories under mods) # # Let us say a file falls under "X-Y" case if it was in state X before # re-staging and now in state Y. For all 4 possible cases, we can check if # the actual destination of the file changed or not in the following way: # # F-F: We can just compare the target of the link. # F-D, D-F: The target may have changed, but it needs some complicated # computation to check. We treat them as changed to be conservative. # D-D: We can leave it as-is since both point third_party. # # So we want to visit all files in state F either in old staging or new # staging. For this purpose we can iterate through |*_staging_links| as # they contain all files in state F. # # Note that |*_staging_links| may contain directory symbolic links, but # it is okay to visit them too because directory timestamps do not matter. # Actually excluding directory symbolic links from |old_staging_links| is # difficult because link targets might be already removed. for path in set(list(old_staging_links) + list(new_staging_links)): if path in old_staging_links and path in new_staging_links: should_touch = old_staging_links[path] != new_staging_links[path] else: should_touch = True if should_touch and os.path.exists(path): os.utime(path, None) timer.done() return True