Skip to content

Commit

Permalink
Windows Fixes
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
Pigweed-Auto-Submit: Anthony DiGirolamo <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
AnthonyDiGirolamo authored and CQ Bot Account committed Apr 25, 2022
1 parent 3d2ffee commit e8131f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
24 changes: 13 additions & 11 deletions pw_build/py/pw_build/generate_modules_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 11 additions & 7 deletions pw_doctor/py/pw_doctor/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e8131f4

Please sign in to comment.