Commit ee0f02af authored by Samuel Dionne-Riel's avatar Samuel Dionne-Riel
Browse files

lib.meta: Drop incorrect `cpePatchVersionInUpdateWithVendor` and...

lib.meta: Drop incorrect `cpePatchVersionInUpdateWithVendor` and `cpePatchVersionInUpdateWithVendor`

See the previous commits for the explanation as to why this is an invalid
value. See the follow-up commits for the complete removal of the
helpers.
parent 95584fa1
Loading
Loading
Loading
Loading
+0 −128
Original line number Diff line number Diff line
@@ -633,132 +633,4 @@ rec {
    update = "*";
  };

  /**
    Alternate version of [`lib.meta.cpePatchVersionInUpdateWithVendor`](#function-library-lib.meta.cpePatchVersionInUpdateWithVendor).
    If `cpePatchVersionInUpdateWithVendor` succeeds, returns an attribute set with `success` set to `true` and `value` set to the result.
    Otherwise, `success` is set to `false` and `error` is set to the string representation of the error.

    # Inputs

    `vendor`

    : package's vendor

    `version`

    : package's version

    # Type

    ```
    tryCPEPatchVersionInUpdateWithVendor :: String -> String -> ({ success = true; value :: { update :: String; vendor :: String; version :: String; }; } | { success = false; error :: String; })
    ```

    # Examples
    :::{.example}
    ## `lib.meta.tryCPEPatchVersionInUpdateWithVendor` usage example

    ```nix
    lib.meta.tryCPEPatchVersionInUpdateWithVendor "gnu" "1.2.3"
    => {
      success = true;
      value = {
        vendor = "gnu";
        version = "1.2";
        update = "3";
      };
    }
    ```

    :::
    :::{.example}
    ## `lib.meta.cpePatchVersionInUpdateWithVendor` error example

    ```nix
    lib.meta.tryCPEPatchVersionInUpdateWithVendor "gnu" "5.3p0"
    => {
      success = false;
      error = "version 5.3p0 doesn't match regex `([0-9]+\\.[0-9]+)\\.([0-9]+)`";
    }
    ```

    :::
  */
  tryCPEPatchVersionInUpdateWithVendor =
    vendor: version:
    let
      regex = "([0-9]+\\.[0-9]+)\\.([0-9]+)";
      # we have to call toString here in case version is an attrset with __toString attribute
      versionMatch = builtins.match regex (toString version);
    in
    if versionMatch == null then
      {
        success = false;
        error = "version ${version} doesn't match regex `${regex}`";
      }
    else
      {
        success = true;
        value = {
          inherit vendor;
          version = elemAt versionMatch 0;
          update = elemAt versionMatch 1;
        };
      };

  /**
    Generate [CPE parts](#var-meta-identifiers-cpeParts) from inputs. Copies `vendor` to the result. When `version` matches `X.Y.Z` where all parts are numerical, sets `version` and `update` fields to `X.Y` and `Z`. Throws an error if the version doesn't match the expected template.

    # Inputs

    `vendor`

    : package's vendor

    `version`

    : package's version

    # Type

    ```
    cpePatchVersionInUpdateWithVendor :: String -> String -> { update :: String; vendor :: String; version :: String; }
    ```

    # Examples
    :::{.example}
    ## `lib.meta.cpePatchVersionInUpdateWithVendor` usage example

    ```nix
    lib.meta.cpePatchVersionInUpdateWithVendor "gnu" "1.2.3"
    => {
      vendor = "gnu";
      version = "1.2";
      update = "3";
    }
    ```

    :::
    :::{.example}
    ## `lib.meta.cpePatchVersionInUpdateWithVendor` usage in derivations

    ```nix
    mkDerivation rec {
      version = "1.2.3";
      # ...
      meta = {
        # ...
        identifiers.cpeParts = lib.meta.cpePatchVersionInUpdateWithVendor "gnu" version;
      };
    }
    ```

    :::
  */
  cpePatchVersionInUpdateWithVendor =
    vendor: version:
    let
      result = tryCPEPatchVersionInUpdateWithVendor vendor version;
    in
    if result.success then result.value else throw result.error;
}