diff options
Diffstat (limited to 'pw_doctor/py/pw_doctor/doctor.py')
-rwxr-xr-x | pw_doctor/py/pw_doctor/doctor.py | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/pw_doctor/py/pw_doctor/doctor.py b/pw_doctor/py/pw_doctor/doctor.py index f91800520..1d2d37345 100755 --- a/pw_doctor/py/pw_doctor/doctor.py +++ b/pw_doctor/py/pw_doctor/doctor.py @@ -27,6 +27,7 @@ import tempfile from typing import Callable, Iterable, List, Set import pw_cli.pw_command_plugins +import pw_env_setup.cipd_setup.update as cipd_update def call_stdout(*args, **kwargs): @@ -288,32 +289,52 @@ def cipd_versions(ctx: DoctorContext): if os.environ.get('PW_DOCTOR_SKIP_CIPD_CHECKS'): return - try: - root = pathlib.Path(os.environ['PW_ROOT']).resolve() - except KeyError: - return # This case is handled elsewhere. + if 'PW_CIPD_INSTALL_DIR' not in os.environ: + ctx.error('PW_CIPD_INSTALL_DIR not set') + cipd_dir = pathlib.Path(os.environ['PW_CIPD_INSTALL_DIR']) - if 'PW_PIGWEED_CIPD_INSTALL_DIR' not in os.environ: - ctx.error('PW_PIGWEED_CIPD_INSTALL_DIR not set') - cipd_dir = pathlib.Path(os.environ['PW_PIGWEED_CIPD_INSTALL_DIR']) + with open(cipd_dir / '_all_package_files.json', 'r') as ins: + json_paths = [pathlib.Path(x) for x in json.load(ins)] + + platform = cipd_update.platform() + + def check_cipd(package, install_path): + if platform not in package['platforms']: + ctx.debug("skipping %s because it doesn't apply to %s", + package['path'], platform) + return - versions_path = cipd_dir / '.versions' - # Deliberately not checking luci.json--it's not required to be up-to-date. - json_path = root.joinpath('pw_env_setup', 'py', 'pw_env_setup', - 'cipd_setup', 'pigweed.json') + tags_without_refs = [x for x in package['tags'] if ':' in x] + if not tags_without_refs: + ctx.debug('skipping %s because it tracks a ref, not a tag (%s)', + package['path'], ', '.join(package['tags'])) + return - def check_cipd(package): ctx.debug('checking version of %s', package['path']) + name = [ part for part in package['path'].split('/') if '{' not in part ][-1] - path = versions_path.joinpath(f'{name}.cipd_version') - if not path.is_file(): - ctx.debug('no version file') - return + + # If the exact path is specified in the JSON file use it, and require it + # exist. + if 'version_file' in package: + path = install_path / package['version_file'] + if not path.is_file(): + ctx.error(f'no version file for {name} at {path}') + return + + # Otherwise, follow a heuristic to find the file but don't require the + # file to exist. + else: + path = install_path / '.versions' / f'{name}.cipd_version' + if not path.is_file(): + ctx.debug(f'no version file for {name} at {path}') + return with path.open() as ins: installed = json.load(ins) + ctx.debug(f'found version file for {name} at {path}') describe = ( 'cipd', @@ -330,11 +351,19 @@ def cipd_versions(ctx: DoctorContext): for tag in package['tags']: if tag not in output: ctx.error( - 'CIPD package %s is out of date, please rerun bootstrap', - installed['package_name']) - - for package in json.loads(json_path.read_text()).get('packages', ()): - ctx.submit(check_cipd, package) + 'CIPD package %s in %s is out of date, please rerun ' + 'bootstrap', installed['package_name'], install_path) + + else: + ctx.debug('CIPD package %s in %s is current', + installed['package_name'], install_path) + + for json_path in json_paths: + ctx.debug(f'Checking packages in {json_path}') + install_path = pathlib.Path( + cipd_update.package_installation_path(cipd_dir, json_path)) + for package in json.loads(json_path.read_text()).get('packages', ()): + ctx.submit(check_cipd, package, install_path) @register_into(CHECKS) |