-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build configurations to latest
- Loading branch information
Showing
322 changed files
with
19,555 additions
and
14,008 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[style] | ||
based_on_style = pep8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 3pp_util | ||
|
||
Contains helper scripts for 3pp configs. | ||
|
||
See [`//docs/docs/cipd_and_3pp.md`](/docs/cipd_and_3pp.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import argparse | ||
import hashlib | ||
import json | ||
import os | ||
import pathlib | ||
import re | ||
import urllib.request | ||
|
||
|
||
def _fetch_json(url): | ||
return json.load(urllib.request.urlopen(url)) | ||
|
||
|
||
def _latest(api_url, install_scripts=None): | ||
# Make the version change every time this file changes. | ||
md5 = hashlib.md5() | ||
md5.update(pathlib.Path(__file__).read_bytes()) | ||
import __main__ | ||
md5.update(pathlib.Path(__main__.__file__).read_bytes()) | ||
|
||
if install_scripts: | ||
for path in install_scripts: | ||
md5.update(pathlib.Path(path).read_bytes()) | ||
file_hash = md5.hexdigest()[:10] | ||
|
||
release = _fetch_json(f'{api_url}/releases/latest')['tag_name'] | ||
print('{}.{}'.format(release, file_hash)) | ||
|
||
|
||
def _get_url(api_url, | ||
artifact_filename=None, | ||
artifact_extension=None, | ||
artifact_regex=None): | ||
# Split off our md5 hash. | ||
version = os.environ['_3PP_VERSION'].rsplit('.', 1)[0] | ||
json_dict = _fetch_json(f'{api_url}/releases/tags/{version}') | ||
urls = [x['browser_download_url'] for x in json_dict['assets']] | ||
|
||
if artifact_regex: | ||
urls = [x for x in urls if re.search(artifact_regex, x)] | ||
|
||
if len(urls) != 1: | ||
raise Exception('len(urls) != 1: \n' + '\n'.join(urls)) | ||
|
||
partial_manifest = { | ||
'url': urls, | ||
'ext': artifact_extension or '', | ||
} | ||
if artifact_filename: | ||
partial_manifest['name'] = [artifact_filename] | ||
|
||
print(json.dumps(partial_manifest)) | ||
|
||
|
||
def main(*, | ||
project, | ||
artifact_filename=None, | ||
artifact_extension=None, | ||
artifact_regex=None, | ||
install_scripts=None, | ||
extract_extension=None): | ||
"""The fetch.py script for a 3pp module. | ||
Args: | ||
project: GitHub username for the repo. e.g. "google/protobuf". | ||
artifact_filename: The name for the downloaded file. Required when not | ||
setting "unpack_archive: true" in 3pp.pb. | ||
artifact_extension: File extension of file being downloaded. Required when | ||
setting "unpack_archive: true" in 3pp.pb. | ||
artifact_regex: A regex to use to identify the desired artifact from the | ||
list of artifacts on the release. | ||
install_scripts: List of script to add to the md5 of the version. The main | ||
module and this module are always included. | ||
""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('action', choices=('latest', 'get_url')) | ||
args = parser.parse_args() | ||
|
||
api_url = f'https://api.github.com/repos/{project}' | ||
if args.action == 'latest': | ||
_latest(api_url, install_scripts=install_scripts) | ||
else: | ||
_get_url(api_url, | ||
artifact_filename=artifact_filename, | ||
artifact_extension=artifact_extension, | ||
artifact_regex=artifact_regex) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import argparse | ||
import pathlib | ||
import re | ||
import subprocess | ||
|
||
_DIR_SOURCE_ROOT = str(pathlib.Path(__file__).absolute().parents[2]) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
# Hide args set by wrappers so that using --help with the wrappers does not | ||
# show them. | ||
parser.add_argument('--subdir', required=True, help=argparse.SUPPRESS) | ||
parser.add_argument('--cipd-package', | ||
required=True, | ||
help=argparse.SUPPRESS) | ||
parser.add_argument('--git-log-url', help=argparse.SUPPRESS) | ||
parser.add_argument('--cipd-instance', | ||
help='Uses value from DEPS by default') | ||
args = parser.parse_args() | ||
|
||
if not args.cipd_instance: | ||
cmd = [ | ||
'gclient', 'getdep', '-r', f'src/{args.subdir}:{args.cipd_package}' | ||
] | ||
args.cipd_instance = subprocess.check_output(cmd, | ||
cwd=_DIR_SOURCE_ROOT, | ||
text=True) | ||
|
||
cmd = [ | ||
'cipd', 'describe', args.cipd_package, '-version', args.cipd_instance | ||
] | ||
print(' '.join(cmd)) | ||
output = subprocess.check_output(cmd, text=True) | ||
print(output, end='') | ||
if args.git_log_url: | ||
git_hashes = re.findall(r'version:.*?@(\w+)', output) | ||
if not git_hashes: | ||
print('Could not find git hash from output.') | ||
else: | ||
# Multiple version tags exist when multiple versions have the same sha1. | ||
last_version = git_hashes[-1] | ||
print() | ||
print('Recent commits:', args.git_log_url.format(last_version)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Copyright 2023 The Chromium Authors | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
"""Helper functions useful when writing scripts used by action() targets.""" | ||
|
||
import contextlib | ||
import filecmp | ||
import os | ||
import pathlib | ||
import posixpath | ||
import shutil | ||
import tempfile | ||
|
||
import gn_helpers | ||
|
||
|
||
@contextlib.contextmanager | ||
def atomic_output(path, mode='w+b', only_if_changed=True): | ||
"""Prevent half-written files and dirty mtimes for unchanged files. | ||
Args: | ||
path: Path to the final output file, which will be written atomically. | ||
mode: The mode to open the file in (str). | ||
only_if_changed: Whether to maintain the mtime if the file has not changed. | ||
Returns: | ||
A Context Manager that yields a NamedTemporaryFile instance. On exit, the | ||
manager will check if the file contents is different from the destination | ||
and if so, move it into place. | ||
Example: | ||
with action_helpers.atomic_output(output_path) as tmp_file: | ||
subprocess.check_call(['prog', '--output', tmp_file.name]) | ||
""" | ||
# Create in same directory to ensure same filesystem when moving. | ||
dirname = os.path.dirname(path) or '.' | ||
os.makedirs(dirname, exist_ok=True) | ||
with tempfile.NamedTemporaryFile(mode, | ||
suffix=os.path.basename(path), | ||
dir=dirname, | ||
delete=False) as f: | ||
try: | ||
yield f | ||
|
||
# File should be closed before comparison/move. | ||
f.close() | ||
if not (only_if_changed and os.path.exists(path) | ||
and filecmp.cmp(f.name, path)): | ||
shutil.move(f.name, path) | ||
finally: | ||
f.close() | ||
if os.path.exists(f.name): | ||
os.unlink(f.name) | ||
|
||
|
||
def add_depfile_arg(parser): | ||
if hasattr(parser, 'add_option'): | ||
func = parser.add_option | ||
else: | ||
func = parser.add_argument | ||
func('--depfile', help='Path to depfile (refer to "gn help depfile")') | ||
|
||
|
||
def write_depfile(depfile_path, first_gn_output, inputs=None): | ||
"""Writes a ninja depfile. | ||
See notes about how to use depfiles in //build/docs/writing_gn_templates.md. | ||
Args: | ||
depfile_path: Path to file to write. | ||
first_gn_output: Path of first entry in action's outputs. | ||
inputs: List of inputs to add to depfile. | ||
""" | ||
assert depfile_path != first_gn_output # http://crbug.com/646165 | ||
assert not isinstance(inputs, str) # Easy mistake to make | ||
|
||
def _process_path(path): | ||
assert not os.path.isabs(path), f'Found abs path in depfile: {path}' | ||
if os.path.sep != posixpath.sep: | ||
path = str(pathlib.Path(path).as_posix()) | ||
assert '\\' not in path, f'Found \\ in depfile: {path}' | ||
return path.replace(' ', '\\ ') | ||
|
||
sb = [] | ||
sb.append(_process_path(first_gn_output)) | ||
if inputs: | ||
# Sort and uniquify to ensure file is hermetic. | ||
# One path per line to keep it human readable. | ||
sb.append(': \\\n ') | ||
sb.append(' \\\n '.join(sorted(_process_path(p) for p in set(inputs)))) | ||
else: | ||
sb.append(': ') | ||
sb.append('\n') | ||
|
||
path = pathlib.Path(depfile_path) | ||
path.parent.mkdir(parents=True, exist_ok=True) | ||
path.write_text(''.join(sb)) | ||
|
||
|
||
def parse_gn_list(value): | ||
"""Converts a "GN-list" command-line parameter into a list. | ||
Conversions handled: | ||
* None -> [] | ||
* '' -> [] | ||
* 'asdf' -> ['asdf'] | ||
* '["a", "b"]' -> ['a', 'b'] | ||
* ['["a", "b"]', 'c'] -> ['a', 'b', 'c'] (action='append') | ||
This allows passing args like: | ||
gn_list = [ "one", "two", "three" ] | ||
args = [ "--items=$gn_list" ] | ||
""" | ||
# Convert None to []. | ||
if not value: | ||
return [] | ||
# Convert a list of GN lists to a flattened list. | ||
if isinstance(value, list): | ||
ret = [] | ||
for arg in value: | ||
ret.extend(parse_gn_list(arg)) | ||
return ret | ||
# Convert normal GN list. | ||
if value.startswith('['): | ||
return gn_helpers.GNValueParser(value).ParseList() | ||
# Convert a single string value to a list. | ||
return [value] |
Oops, something went wrong.