def test_get_default_tracking_path(self): self.assertEquals( 'third_party/android/frameworks/base', staging.get_default_tracking_path('mods/android/frameworks/base')) self.assertEquals( 'internal/third_party/internal_component', staging.get_default_tracking_path('internal/mods/internal_component')) self.assertEquals( 'src/build/tests/analyze_diffs/third_party/AndroidManifest.xml', staging.get_default_tracking_path( 'src/build/tests/analyze_diffs/mods/AndroidManifest.xml'))
def test_get_default_tracking_path(self): self.assertEquals( 'third_party/android/frameworks/base', staging.get_default_tracking_path('mods/android/frameworks/base')) self.assertEquals( 'internal/third_party/internal_component', staging.get_default_tracking_path( 'internal/mods/internal_component')) self.assertEquals( 'src/build/tests/analyze_diffs/third_party/AndroidManifest.xml', staging.get_default_tracking_path( 'src/build/tests/analyze_diffs/mods/AndroidManifest.xml'))
def _find_new_mod_path(self, force_new_mod_path, android_sources): if force_new_mod_path: self._new_mod_path = force_new_mod_path self._new_android_path = staging.get_default_tracking_path( force_new_mod_path) if os.path.exists(self._android_path): self._new_mod_path = self._mod_path self._new_android_path = self._android_path elif android_sources: if self._uses_mod_track: self._status = constants.RESULT_REBASE_RESULT_NO_UPSTREAM return # TODO(crbug.com/464948): While this basic search might work most of the # time, it needs to be improved further to handle finding renamed files, # and files moved to other subprojects (possibly renamed in the process). new_android_path = internal.find_new_android_path( android_sources, self._android_path) if not new_android_path: self._status = constants.RESULT_REBASE_RESULT_NO_UPSTREAM return self._new_mod_path = internal.get_mod_path_for_android_path( new_android_path) self._new_android_path = new_android_path else: self._status = constants.RESULT_REBASE_RESULT_NO_UPSTREAM
def compute_tracking_path(stats, our_path, our_lines, do_lint_check=False, check_exist=True, check_uses_tags=False): """Find the tracking file for the given file. Returns the last path mentioned in the file via a tracking tag or the equivalent third-party path given the file's path. If there is no file in the default path and no files mentioned within the file exist, returns None. Normally the third-party path must exist. Passing |check_exist|=False will bypass this check when it is not desired. An additional check is enabled by passing |check_uses_tag|=True. In this case the given file MUST use either a file track tag or another modification tag, before a tracking_path is returned. stats is a variable for keeping track of the status of the analyzer, which can be None.""" tracking_path = staging.get_default_tracking_path(our_path) base_matcher = re.compile(re.escape(FILE_TRACK_TAG) + r' "([^\"]+)"') tag_matcher = re.compile(re.escape(REGION_START_TAG)) uses_any_tags = False next_lineno = 1 for line in our_lines: if stats: stats['lineno'] = next_lineno match = base_matcher.search(line) if match: tracking_path = match.group(1) if not os.path.exists(tracking_path) and stats: show_error(stats, 'Mod tracking path does not exist:\n' + line) if next_lineno > MAX_ARC_TRACK_SEARCH_LINES: show_error( stats, 'Tracking not allowed on line > %d' % MAX_ARC_TRACK_SEARCH_LINES) uses_any_tags = True break elif not uses_any_tags and tag_matcher.search(line): uses_any_tags = True next_lineno += 1 if (not do_lint_check and (uses_any_tags or not check_uses_tags) and next_lineno > MAX_ARC_TRACK_SEARCH_LINES): break if not tracking_path: return None if check_uses_tags and not uses_any_tags: return None if check_exist and not os.path.exists(tracking_path): return None return tracking_path
def compute_tracking_path(stats, our_path, our_lines, do_lint_check=False, check_exist=True, check_uses_tags=False): """Find the tracking file for the given file. Returns the last path mentioned in the file via a tracking tag or the equivalent third-party path given the file's path. If there is no file in the default path and no files mentioned within the file exist, returns None. Normally the third-party path must exist. Passing |check_exist|=False will bypass this check when it is not desired. An additional check is enabled by passing |check_uses_tag|=True. In this case the given file MUST use either a file track tag or another modification tag, before a tracking_path is returned. stats is a variable for keeping track of the status of the analyzer, which can be None.""" tracking_path = staging.get_default_tracking_path(our_path) base_matcher = re.compile(re.escape(FILE_TRACK_TAG) + r' "([^\"]+)"') tag_matcher = re.compile(re.escape(REGION_START_TAG)) uses_any_tags = False next_lineno = 1 for line in our_lines: if stats: stats['lineno'] = next_lineno match = base_matcher.search(line) if match: tracking_path = match.group(1) if not os.path.exists(tracking_path) and stats: show_error(stats, 'Mod tracking path does not exist:\n' + line) if next_lineno > MAX_ARC_TRACK_SEARCH_LINES: show_error(stats, 'Tracking not allowed on line > %d' % MAX_ARC_TRACK_SEARCH_LINES) uses_any_tags = True break elif not uses_any_tags and tag_matcher.search(line): uses_any_tags = True next_lineno += 1 if (not do_lint_check and (uses_any_tags or not check_uses_tags) and next_lineno > MAX_ARC_TRACK_SEARCH_LINES): break if not tracking_path: return None if check_uses_tags and not uses_any_tags: return None if check_exist and not os.path.exists(tracking_path): return None return tracking_path
def get_arc_android_mod(mod_path, submodules=None): submodules = internal.ensure_android_submodule_paths(submodules) mod_path = internal.relpath(mod_path, constants.ARC_ROOT) android_path = internal.get_android_path_for_mod(mod_path) if not android_path: return None android_module_path = internal.identify_containing_submodule( android_path, submodules=submodules) uses_mod_track = android_path != staging.get_default_tracking_path(mod_path) return _ModState(mod_path, android_path, android_module_path, uses_mod_track)
def get_arc_android_mod(mod_path, submodules=None): submodules = internal.ensure_android_submodule_paths(submodules) mod_path = internal.relpath(mod_path, constants.ARC_ROOT) android_path = internal.get_android_path_for_mod(mod_path) if not android_path: return None android_module_path = internal.identify_containing_submodule( android_path, submodules=submodules) uses_mod_track = android_path != staging.get_default_tracking_path( mod_path) return _ModState(mod_path, android_path, android_module_path, uses_mod_track)
def _check_notices(stats, our_path, tracking_path): # No need to require notices for other metadata files. basename = os.path.basename(our_path) if (basename in ['OWNERS', 'NOTICE'] or basename.startswith('MODULE_LICENSE_') or any(our_path.startswith(p) for p in IGNORE_SUBDIRECORIES)): return default_tracking = staging.get_default_tracking_path(our_path) _check_any_license(stats, our_path, tracking_path, default_tracking) # If this file tracks a file, make sure the file it tracks is no more # restrictive than this file. See tests/analyze_diffs/mods/mpl-license/foo.c # for an example. if tracking_path and (not default_tracking or tracking_path != default_tracking): _check_less_restrictive_tracking_license(stats, our_path, tracking_path, default_tracking)
def _analyze_file(path, reporter): if os.path.abspath(path) == os.path.abspath(__file__): return tracking_path = staging.get_default_tracking_path(path) metadata = AnalyzeFileLevelMetadata() Analyzer(metadata).parse(path) if metadata.has_file_ignore_tag: reporter.report_skipping(path) return if metadata.has_file_track_tag: tracking_path = metadata.file_track_path has_tracked_file = tracking_path and os.path.exists(tracking_path) analyzer = AnalyzeTodos(reporter) if has_tracked_file: analyzer = AnalyzeCodeInMODRegions(analyzer) Analyzer(analyzer).parse(path)