Skip to content

Commit

Permalink
Add action to extract library names and versions
Browse files Browse the repository at this point in the history
Issue: 268355217
Reviewed-on: #3490
  • Loading branch information
dahlstrom-g authored Jun 21, 2024
1 parent 5609f23 commit 05fd383
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions cobalt/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ static_library("browser") {
"//cobalt/browser/metrics",
"//cobalt/build:cobalt_build_id",
"//cobalt/build:cobalt_build_info",
"//cobalt/build:cobalt_libraries",
"//cobalt/cache",
"//cobalt/configuration",
"//cobalt/css_parser",
Expand Down
9 changes: 9 additions & 0 deletions cobalt/build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ action("cobalt_build_info") {
outputs = [ "$root_gen_dir/build_info.json" ]
args = [ rebase_path(outputs[0], root_build_dir) ]
}

action("cobalt_libraries") {
script = "libraries.py"
outputs = [ "$root_gen_dir/libraries.tsv" ]
args = [
rebase_path(outputs[0], root_build_dir),
rebase_path("//", root_build_dir), # source root
]
}
29 changes: 29 additions & 0 deletions cobalt/build/libraries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
"""Extract names and versions of imported libraries."""

import os
import subprocess
import sys

output_path = sys.argv[1]
source_root = sys.argv[2]

with open(output_path, 'w', encoding='utf-8') as out:
print('name\tversion', file=out) # header
os.chdir(source_root)
args = ['git', 'ls-files', '--', '*/README.*']
p = subprocess.run(args, capture_output=True, text=True, check=True)
for f in [f for f in p.stdout.splitlines() if not f.endswith('template')]:
try:
with open(f, encoding='utf-8') as file:
name = None
version = None
for line in file.readlines():
if line.startswith('Name: '):
name = line[len('Name: '):].strip()
if line.startswith('Version: '):
version = line[len('Version: '):].strip()
if name and version:
print(name + '\t' + version, file=out) # row
except UnicodeDecodeError:
pass

0 comments on commit 05fd383

Please sign in to comment.