Skip to content

Commit

Permalink
Enable libexec artifacts
Browse files Browse the repository at this point in the history
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:

 # 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 <pmengelbert@gmail.com>
  • Loading branch information
pmengelbert committed Oct 21, 2024
1 parent 0c0e338 commit f758d96
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
7 changes: 7 additions & 0 deletions docs/spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions frontend/rpm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f758d96

Please sign in to comment.