summaryrefslogtreecommitdiff
path: root/chromium/tools/licenses.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/tools/licenses.py')
-rwxr-xr-xchromium/tools/licenses.py47
1 files changed, 36 insertions, 11 deletions
diff --git a/chromium/tools/licenses.py b/chromium/tools/licenses.py
index feeaf77aaec..fb1762f5cf0 100755
--- a/chromium/tools/licenses.py
+++ b/chromium/tools/licenses.py
@@ -113,10 +113,18 @@ PRUNE_DIRS = (VCS_METADATA_DIRS +
# that contain multiple others as transitive dependencies.
ADDITIONAL_PATHS_FILENAME = 'additional_readme_paths.json'
+# A list of paths that contain license information but that would otherwise
+# not be included. Possible reasons include:
+# - Third party directories in //clank which are considered to be Google-owned
+# - Directories that are directly checked out from upstream, and thus
+# don't have a README.chromium
+# - Directories that contain example code, or build tooling.
+# - Nested third_party code inside other third_party libraries.
ADDITIONAL_PATHS = (
os.path.join('chrome', 'common', 'extensions', 'docs', 'examples'),
os.path.join('chrome', 'test', 'chromeos', 'autotest'),
os.path.join('chrome', 'test', 'data'),
+ os.path.join('clank', 'third_party', 'elements'),
os.path.join('native_client'),
os.path.join('testing', 'gmock'),
os.path.join('testing', 'gtest'),
@@ -464,6 +472,16 @@ def FilterDirsWithFiles(dirs_list, root):
return [x for x in dirs_list if ContainsFiles(x, root)]
+def ProcessAdditionalReadmePathsJson(dirname, third_party_dirs):
+ """For a given directory, process the additional readme paths, and add to
+ third_party_dirs."""
+ additional_paths_file = os.path.join(dirname, ADDITIONAL_PATHS_FILENAME)
+ if os.path.exists(additional_paths_file):
+ with open(additional_paths_file) as paths_file:
+ extra_paths = json.load(paths_file)
+ third_party_dirs.update([os.path.join(dirname, p) for p in extra_paths])
+
+
def FindThirdPartyDirs(prune_paths, root):
"""Find all third_party directories underneath the source root."""
third_party_dirs = set()
@@ -485,15 +503,11 @@ def FindThirdPartyDirs(prune_paths, root):
# Add all subdirectories that are not marked for skipping.
for dir in dirs:
dirpath = os.path.join(path, dir)
- additional_paths_file = os.path.join(root, dirpath,
- ADDITIONAL_PATHS_FILENAME)
if dirpath not in prune_paths:
third_party_dirs.add(dirpath)
- if os.path.exists(additional_paths_file):
- with open(additional_paths_file) as paths_file:
- extra_paths = json.load(paths_file)
- third_party_dirs.update(
- [os.path.join(dirpath, p) for p in extra_paths])
+
+ additional_paths_dir = os.path.join(root, dirpath)
+ ProcessAdditionalReadmePathsJson(additional_paths_dir, third_party_dirs)
# Don't recurse into any subdirs from here.
dirs[:] = []
@@ -507,6 +521,8 @@ def FindThirdPartyDirs(prune_paths, root):
for dir in ADDITIONAL_PATHS:
if dir not in prune_paths:
third_party_dirs.add(dir)
+ additional_paths_dir = os.path.join(root, dir)
+ ProcessAdditionalReadmePathsJson(additional_paths_dir, third_party_dirs)
return third_party_dirs
@@ -664,6 +680,7 @@ def GenerateCredits(
entries.append(
MetadataToTemplateEntry(chromium_license_metadata, entry_template))
+ entries_by_name = {}
for path in third_party_dirs:
try:
metadata = ParseDir(path, _REPOSITORY_ROOT)
@@ -680,7 +697,15 @@ def GenerateCredits(
# updated to provide --gn-target to this script.
if path in KNOWN_NON_IOS_LIBRARIES:
continue
- entries.append(MetadataToTemplateEntry(metadata, entry_template))
+
+ new_entry = MetadataToTemplateEntry(metadata, entry_template)
+ # Skip entries that we've already seen (it exists in multiple directories).
+ prev_entry = entries_by_name.setdefault(new_entry['name'], new_entry)
+ if prev_entry is not new_entry and (
+ prev_entry['content'] == new_entry['content']):
+ continue
+
+ entries.append(new_entry)
entries.sort(key=lambda entry: (entry['name'].lower(), entry['content']))
for entry_id, entry in enumerate(entries):
@@ -750,11 +775,11 @@ def GenerateLicenseFile(output_file, gn_out_dir, gn_target, target_os):
# Add necessary third_party.
for directory in sorted(third_party_dirs):
metadata = ParseDir(directory, _REPOSITORY_ROOT, require_license_file=True)
- content.append('-' * 20)
- content.append(directory.split(os.sep)[-1])
- content.append('-' * 20)
license_file = metadata['License File']
if license_file and license_file != NOT_SHIPPED:
+ content.append('-' * 20)
+ content.append(directory.split(os.sep)[-1])
+ content.append('-' * 20)
content.append(_ReadFile(license_file))
content_text = '\n'.join(content)