From e8131f48cfa8fc78813feff1f246eded934d6f3c Mon Sep 17 00:00:00 2001 From: AnthonyDiGirolamo Date: Sat, 23 Apr 2022 14:30:31 -0700 Subject: [PATCH] Windows Fixes - Fixes a pw doctor error where it expects to fing gn.cipd_version but the file in that location is gn.exe.cipd_version ERR no version file for gn at C:\...\environment\cipd\packages\pigweed\.versions\gn.cipd_version - Fix generate_modules_lists to check the line diff instead of the file bytes. The file may have CRLF line endings on windows but the stdout will have just LF. Change-Id: Ia6c0f12e138c320993c218d9d06734fb47661070 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/92322 Reviewed-by: Armando Montanez Pigweed-Auto-Submit: Anthony DiGirolamo Commit-Queue: Auto-Submit --- .../py/pw_build/generate_modules_lists.py | 24 ++++++++++--------- pw_doctor/py/pw_doctor/doctor.py | 18 ++++++++------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/pw_build/py/pw_build/generate_modules_lists.py b/pw_build/py/pw_build/generate_modules_lists.py index 041b148fe0..38a0b386d0 100644 --- a/pw_build/py/pw_build/generate_modules_lists.py +++ b/pw_build/py/pw_build/generate_modules_lists.py @@ -216,17 +216,19 @@ def _main(root: Path, modules_list: Path, modules_gni_file: Path, stdout=subprocess.PIPE) if process.returncode != 0: errors.append(_FORMAT_FAILED_WARNING) - elif modules_gni_file.read_bytes() != process.stdout: - # Make a diff of required changes - modules_gni_relpath = os.path.relpath(modules_gni_file, root) - diff = difflib.unified_diff( - modules_gni_file.read_text().splitlines(), - process.stdout.decode('utf-8', errors='replace').splitlines(), - fromfile=os.path.join('a', modules_gni_relpath), - tofile=os.path.join('b', modules_gni_relpath), - lineterm='', - n=1, - ) + + # Make a diff of required changes + modules_gni_relpath = os.path.relpath(modules_gni_file, root) + diff = difflib.unified_diff( + modules_gni_file.read_text().splitlines(), + process.stdout.decode('utf-8', errors='replace').splitlines(), + fromfile=os.path.join('a', modules_gni_relpath), + tofile=os.path.join('b', modules_gni_relpath), + lineterm='', + n=1, + ) + # If any differences were found, print the error and the diff. + if len(list(diff)) > 0: errors.append( _OUT_OF_DATE_WARNING.format( out_dir=os.path.relpath(os.curdir, root), diff --git a/pw_doctor/py/pw_doctor/doctor.py b/pw_doctor/py/pw_doctor/doctor.py index 437cc522e2..d3a735c0a2 100755 --- a/pw_doctor/py/pw_doctor/doctor.py +++ b/pw_doctor/py/pw_doctor/doctor.py @@ -333,17 +333,21 @@ def check_cipd(package, install_path): # 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 - + notify_method = ctx.error # 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 + notify_method = ctx.debug + + # Check if a .exe cipd_version exists on Windows. + path_windows = install_path / '.versions' / f'{name}.exe.cipd_version' + if os.name == 'nt' and path_windows.is_file(): + path = path_windows + + if not path.is_file(): + notify_method(f'no version file for {name} at {path}') + return with path.open() as ins: installed = json.load(ins)