From 14757980225f30c2086a07c365c8c42f21f838af Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Wed, 6 Nov 2024 10:15:28 +0100 Subject: [PATCH] Add more aliases for `--systems` flag --- README.md | 19 ++++++++++++++----- nixpkgs_review/review.py | 40 +++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 18b6140..5fa7372 100644 --- a/README.md +++ b/README.md @@ -351,11 +351,20 @@ since the architecture/operating system mismatches. By default, `nixpkgs-review` targets only the current system (`--systems current`). You can also explicitly provide one or several systems to -target (`--systems "x86_64-linux aarch64-darwin"`). The `--systems all` value -will build for the four major platforms supported by hydra (`--x86_64-linux`, -`aarch64-linux`, `x86_64-darwin` and `aarch64-darwin`). Ensure that your system -is capable of building for the specified architectures, either locally or -through the remote builder protocol. +target (`--systems "x86_64-linux aarch64-darwin"`). We also provide aliases for +the flag: + +| Alias | Transforms to | +| ---------------------------------------------------- | --------------------------------------------------------- | +| `current` | Your current system | +| `all` | `aarch64-darwin aarch64-linux x86_64-darwin x86_64-linux` | +| `linux` | `aarch64-linux x86_64-linux` | +| `darwin`, `macos` | `aarch64-darwin x86_64-darwin` | +| `x64`, `x86`, `x86_64`, `x86-64`, `x64_86`, `x64-86` | `x86_64-darwin x86_64-linux` | +| `aarch64`, `arm64` | `aarch64-darwin aarch64-linux` | + +Ensure that your system is capable of building for the specified architectures, +either locally or through the remote builder protocol. ```console $ nixpkgs-review pr --system aarch64-linux 98734 diff --git a/nixpkgs_review/review.py b/nixpkgs_review/review.py index 1248f8b..f0a68bb 100644 --- a/nixpkgs_review/review.py +++ b/nixpkgs_review/review.py @@ -21,14 +21,11 @@ # keep up to date with `supportedPlatforms` # https://github.com/NixOS/ofborg/blob/cf2c6712bd7342406e799110e7cd465aa250cdca/ofborg/src/outpaths.nix#L12 -OFBORG_PLATFORMS: set[str] = set( - [ - "aarch64-darwin", - "aarch64-linux", - "x86_64-darwin", - "x86_64-linux", - ] -) +OFBORG_PLATFORMS_LINUX: set[str] = {"aarch64-linux", "x86_64-linux"} +OFBORG_PLATFORMS_DARWIN: set[str] = {"aarch64-darwin", "x86_64-darwin"} +OFBORG_PLATFORMS_AARCH64: set[str] = {"aarch64-darwin", "aarch64-darwin"} +OFBORG_PLATFORMS_X64: set[str] = {"x86_64-darwin", "x86_64-darwin"} +OFBORG_PLATFORMS: set[str] = OFBORG_PLATFORMS_LINUX.union(OFBORG_PLATFORMS_DARWIN) class CheckoutOption(Enum): @@ -127,13 +124,9 @@ def __init__( case 0: raise NixpkgsReviewError("Systems is empty") case 1: - system = list(systems)[0] - if system == "current": - self.systems = set([current_system()]) - elif system == "all": - self.systems = OFBORG_PLATFORMS - else: - self.systems = set([system]) + self.systems = self._process_aliases_for_systems( + list(systems)[0].lower() + ) case _: self.systems = set(systems) self.allow = allow @@ -143,6 +136,23 @@ def __init__( self.extra_nixpkgs_config = extra_nixpkgs_config self.num_parallel_evals = num_parallel_evals + def _process_aliases_for_systems(self, system: str) -> set[str]: + match system: + case "current": + return set([current_system()]) + case "all": + return OFBORG_PLATFORMS + case "linux": + return OFBORG_PLATFORMS_LINUX + case "darwin" | "macos": + return OFBORG_PLATFORMS_DARWIN + case "x64" | "x86" | "x86_64" | "x86-64" | "x64_86" | "x64-86": + return OFBORG_PLATFORMS_X64 + case "aarch64" | "arm64": + return OFBORG_PLATFORMS_AARCH64 + case _: + return set([system]) + def worktree_dir(self) -> str: return str(self.builddir.worktree_dir)