Skip to content

Commit

Permalink
Add archlinux packaging to nfpm backend (#21299)
Browse files Browse the repository at this point in the history
This adds archlinux packaging to the nfpm backend introduced in #19308.

New target (and related fields):

- `nfpm_archlinux_package`
  • Loading branch information
cognifloyd authored Aug 14, 2024
1 parent 0d43b27 commit 219cb02
Show file tree
Hide file tree
Showing 13 changed files with 500 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/notes/2.23.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ A new experimental `pants.backend.experimental.nfpm` backend was added to suppor

> **nFPM is Not FPM** - a zero dependencies, simple `deb`, `rpm`, `apk`, `ipk`, and arch linux packager written in Go.
This backend adds experimental support for building these package types: `deb`, `rpm`, and `apk`. This plugin does not (yet) support building `archlinux` packages as well as `ipk` which is a recent addition to `nFPM`, though `ipk` support should be fairly straight forward to add if someone wants to work on it.
This backend adds experimental support for building these package types: `deb`, `rpm`, `apk`, and `archlinux`. This plugin does not (yet) support building `ipk` packages (a recent addition to `nFPM`), though it support should be fairly straight forward to add if someone wants to work on it.

To use the `nFPM` backend, enable `pants.backend.experimental.nfpm` in your `pants.toml`, and create an `nfpm_*_package` target that depends on `nfpm_content_*` targets. This backend constructs the `nfpm.yaml` file that `nFPM` relies on to build packages. All `nfpm.yaml` fields (that make sense within pants) can be configured via the `nfpm_*_package` and `nfpm_content_*` targets.

Expand All @@ -86,6 +86,7 @@ $ pants help targets | grep -A1 nfpm_
Learn about the nFPM package targets and their fields:
```
$ pants help nfpm_apk_package
$ pants help nfpm_archlinux_package
$ pants help nfpm_deb_package
$ pants help nfpm_rpm_package
```
Expand Down
10 changes: 9 additions & 1 deletion src/python/pants/backend/nfpm/dependency_inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
)
from pants.backend.nfpm.dependency_inference import rules as nfpm_dep_rules
from pants.backend.nfpm.fields.apk import NfpmApkScriptsField
from pants.backend.nfpm.fields.archlinux import NfpmArchlinuxScriptsField
from pants.backend.nfpm.fields.deb import NfpmDebScriptsField
from pants.backend.nfpm.fields.rpm import NfpmRpmScriptsField
from pants.backend.nfpm.fields.scripts import NfpmPackageScriptsField
from pants.backend.nfpm.target_types import NfpmApkPackage, NfpmDebPackage, NfpmRpmPackage
from pants.backend.nfpm.target_types import (
NfpmApkPackage,
NfpmArchlinuxPackage,
NfpmDebPackage,
NfpmRpmPackage,
)
from pants.core.target_types import FilesGeneratorTarget, FileTarget
from pants.core.target_types import rules as core_target_type_rules
from pants.engine.addresses import Address
Expand All @@ -32,6 +38,7 @@ def rule_runner() -> RuleRunner:
FileTarget,
FilesGeneratorTarget,
NfpmApkPackage,
NfpmArchlinuxPackage,
NfpmDebPackage,
NfpmRpmPackage,
],
Expand All @@ -52,6 +59,7 @@ def rule_runner() -> RuleRunner:
"packager,scripts_field_type",
(
("apk", NfpmApkScriptsField),
("archlinux", NfpmArchlinuxScriptsField),
("deb", NfpmDebScriptsField),
("rpm", NfpmRpmScriptsField),
),
Expand Down
12 changes: 11 additions & 1 deletion src/python/pants/backend/nfpm/field_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
from pants.backend.nfpm.fields.rpm import NfpmRpmGhostContents
from pants.backend.nfpm.fields.scripts import NfpmPackageScriptsField
from pants.backend.nfpm.target_types import APK_FIELDS, DEB_FIELDS, RPM_FIELDS
from pants.backend.nfpm.target_types import APK_FIELDS, ARCHLINUX_FIELDS, DEB_FIELDS, RPM_FIELDS
from pants.core.goals.package import PackageFieldSet
from pants.engine.fs import FileEntry
from pants.engine.rules import collect_rules
Expand Down Expand Up @@ -112,6 +112,15 @@ class NfpmApkPackageFieldSet(NfpmPackageFieldSet):
required_fields = APK_FIELDS


# noinspection DuplicatedCode
@dataclass(frozen=True)
class NfpmArchlinuxPackageFieldSet(NfpmPackageFieldSet):
packager = "archlinux"
# NB: uses *.tar.zst (unlike the other packagers where packager == file extension)
extension = ".tar.zst"
required_fields = ARCHLINUX_FIELDS


# noinspection DuplicatedCode
@dataclass(frozen=True)
class NfpmDebPackageFieldSet(NfpmPackageFieldSet):
Expand All @@ -137,6 +146,7 @@ def nfpm_config(self, tgt: Target, *, default_mtime: str | None) -> dict[str, An
NFPM_PACKAGE_FIELD_SET_TYPES: FrozenOrderedSet[type[NfpmPackageFieldSet]] = FrozenOrderedSet(
(
NfpmApkPackageFieldSet,
NfpmArchlinuxPackageFieldSet,
NfpmDebPackageFieldSet,
NfpmRpmPackageFieldSet,
)
Expand Down
59 changes: 58 additions & 1 deletion src/python/pants/backend/nfpm/field_sets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from pants.backend.nfpm.field_sets import (
NfpmApkPackageFieldSet,
NfpmArchlinuxPackageFieldSet,
NfpmDebPackageFieldSet,
NfpmRpmPackageFieldSet,
)
Expand All @@ -15,6 +16,10 @@
NfpmPackageNameField,
)
from pants.backend.nfpm.fields.apk import NfpmApkDependsField, NfpmApkMaintainerField
from pants.backend.nfpm.fields.archlinux import (
NfpmArchlinuxDependsField,
NfpmArchlinuxPackagerField,
)
from pants.backend.nfpm.fields.deb import (
NfpmDebDependsField,
NfpmDebFieldsField,
Expand All @@ -30,7 +35,12 @@
)
from pants.backend.nfpm.fields.scripts import NfpmPackageScriptsField
from pants.backend.nfpm.fields.version import NfpmVersionField
from pants.backend.nfpm.target_types import NfpmApkPackage, NfpmDebPackage, NfpmRpmPackage
from pants.backend.nfpm.target_types import (
NfpmApkPackage,
NfpmArchlinuxPackage,
NfpmDebPackage,
NfpmRpmPackage,
)
from pants.engine.addresses import Address
from pants.engine.target import DescriptionField

Expand Down Expand Up @@ -84,6 +94,53 @@ def test_generate_nfpm_config_for_apk():
assert nfpm_config == expected_nfpm_config


def test_generate_nfpm_config_for_archlinux():
depends = [
"git",
"tcpdump<5",
"foobar>=1.8.0",
]
tgt = NfpmArchlinuxPackage(
{
NfpmPackageNameField.alias: "treasure",
NfpmVersionField.alias: "3.2.1",
DescriptionField.alias: "Black Beard's buried treasure.",
NfpmPackageScriptsField.alias: {
"preinstall": "hornswaggle",
"preupgrade": "plunder",
},
NfpmArchlinuxPackagerField.alias: "Black Beard <[email protected]",
NfpmHomepageField.alias: "https://jolly.roger.example.com",
NfpmLicenseField.alias: "MIT",
NfpmArchlinuxDependsField.alias: depends,
},
Address("", target_name="t"),
)
expected_nfpm_config = {
"disable_globbing": True,
"contents": [],
"mtime": MTIME,
"name": "treasure",
"arch": "amd64", # default
"version": "3.2.1",
"version_schema": "semver", # default
"release": 1, # default
"homepage": "https://jolly.roger.example.com",
"license": "MIT",
"depends": tuple(depends),
"scripts": {"preinstall": "hornswaggle"},
"archlinux": {
"packager": "Black Beard <[email protected]",
"scripts": {"preupgrade": "plunder"},
},
"description": "Black Beard's buried treasure.",
}

field_set = NfpmArchlinuxPackageFieldSet.create(tgt)
nfpm_config = field_set.nfpm_config(tgt, default_mtime=MTIME)
assert nfpm_config == expected_nfpm_config


def test_generate_nfpm_config_for_deb():
depends = [
"git",
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/nfpm/fields/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class NfpmPlatformField(StringField):
with the assumption that this is a GOOS value (since nFPM is part of the
"goreleaser" project). But, nFPM does not do much with it.
For apk, the only valid value is 'linux'.
For archlinux and apk, the only valid value is 'linux'.
For deb, this can be used as part of the 'Architecture' entry.
For rpm, this populates the "OS" tag.
"""
Expand All @@ -140,7 +140,7 @@ class NfpmHomepageField(StringField):
This field is named "{NfpmHomepageField.alias}" instead of "url" because
that is the term used by nFPM, which adopted the term from deb packaging.
The term "url" is used by apk and rpm packaging.
The term "url" is used by apk, archlinux, and rpm packaging.
"""
)

Expand Down
Loading

0 comments on commit 219cb02

Please sign in to comment.