From baa3fc37dfafed8879bd0d39262673920f214904 Mon Sep 17 00:00:00 2001 From: Peter Engelbert Date: Mon, 21 Oct 2024 16:29:47 -0400 Subject: [PATCH] Enable libexec artifacts This commit allows the user to specify artifacts to be installed under `usr/libexec`. I used the following documentation as a guide: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s07.html#:~:text=Purpose,subdirectory%20under%20%2Fusr%2Flibexec%20. Below, you can see at a glance what the behavior of various settings will be. The following examples assume we are building a spec with top-level `name: docker`. The subpath field defaults to the package name. ```yaml # goes to /usr/libexec/docker/docker-compose libexec: bin/docker-compose: name: hello # goes to /usr/libexec/docker/cli-plugins/docker-compose libexec: bin/docker-compose: subPath: docker/cli-plugins # goes to /usr/libexec/something_else/cli-plugins/docker-compose libexec: bin/docker-compose: subPath: something_else/cli-plugins # goes to /usr/libexec/docker/cli-plugins/hello libexec: bin/docker-compose: subPath: docker/cli-plugins name: hello # goes to /usr/libexec/docker/hello libexec: bin/docker-compose: name: hello ``` Signed-off-by: Peter Engelbert --- artifacts.go | 2 ++ docs/spec.schema.json | 7 +++++++ frontend/rpm/template.go | 8 ++++++++ load.go | 7 +++++++ 4 files changed, 24 insertions(+) diff --git a/artifacts.go b/artifacts.go index f19b8677a..93592a487 100644 --- a/artifacts.go +++ b/artifacts.go @@ -12,6 +12,8 @@ import ( type Artifacts struct { // Binaries is the list of binaries to include in the package. Binaries map[string]ArtifactConfig `yaml:"binaries,omitempty" json:"binaries,omitempty"` + // Libexec is the list of additional binaries that may be invoked by the main package binary. + Libexec map[string]ArtifactConfig `yaml:"libexec,omitempty" json:"libexec,omitempty"` // Manpages is the list of manpages to include in the package. Manpages map[string]ArtifactConfig `yaml:"manpages,omitempty" json:"manpages,omitempty"` // DataDirs is a list of read-only architecture-independent data files, to be placed in /usr/share/ diff --git a/docs/spec.schema.json b/docs/spec.schema.json index 26ac5b994..71dbf8898 100644 --- a/docs/spec.schema.json +++ b/docs/spec.schema.json @@ -76,6 +76,13 @@ "type": "object", "description": "Binaries is the list of binaries to include in the package." }, + "libexec": { + "additionalProperties": { + "$ref": "#/$defs/ArtifactConfig" + }, + "type": "object", + "description": "Libexec is the list of additional binaries that may be invoked by the main package binary." + }, "manpages": { "additionalProperties": { "$ref": "#/$defs/ArtifactConfig" diff --git a/frontend/rpm/template.go b/frontend/rpm/template.go index a446308d5..e63efe8ca 100644 --- a/frontend/rpm/template.go +++ b/frontend/rpm/template.go @@ -499,6 +499,14 @@ func (w *specWrapper) Install() fmt.Stringer { } } + if w.Spec.Artifacts.Libexec != nil { + libexecFileKeys := dalec.SortMapKeys(w.Spec.Artifacts.Libexec) + for _, k := range libexecFileKeys { + le := w.Spec.Artifacts.Libexec[k] + copyArtifact(`%{buildroot}/%{_libexecdir}`, k, &le) + } + } + configKeys := dalec.SortMapKeys(w.Spec.Artifacts.ConfigFiles) for _, c := range configKeys { cfg := w.Spec.Artifacts.ConfigFiles[c] diff --git a/load.go b/load.go index 0ccccbe6c..ad6749dfe 100644 --- a/load.go +++ b/load.go @@ -445,6 +445,13 @@ func (s *Spec) FillDefaults() { s.Patches[k][i].Strip = &strip } } + + for k, ac := range s.Artifacts.Libexec { + if s.Artifacts.Libexec[k].SubPath == "" { + ac.SubPath = s.Name + s.Artifacts.Libexec[k] = ac + } + } } func (s Spec) Validate() error {