Skip to content

Commit

Permalink
Add ReplacesPriroity like ProviderPriority, and allow substitutions
Browse files Browse the repository at this point in the history
This enables one to use variables, and range substitutions in the
ReplacesPriority and ProviderPriority.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@chainguard.dev>
  • Loading branch information
xnox committed Apr 23, 2024
1 parent f611e9a commit 750afdd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/build/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ replaces = {{ $dep }}
{{- if .Dependencies.ProviderPriority }}
provider_priority = {{ .Dependencies.ProviderPriority }}
{{- end }}
{{- if .Dependencies.ReplacesPriority }}
replaces_priority = {{ .Dependencies.ReplacesPriority }}
{{- end }}
{{- if .Scriptlets.Trigger.Paths }}
triggers = {{ range $item := .Scriptlets.Trigger.Paths }}{{ $item }} {{ end }}
{{- end }}
Expand Down
38 changes: 35 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,31 @@ func (cfg *Configuration) applySubstitutionsForProvides() error {
return nil
}

func (cfg *Configuration) applySubstitutionsForPriorities() error {
nw := buildConfigMap(cfg)
var err error
cfg.Package.Dependencies.ProviderPriority, err = util.MutateStringFromMap(nw, cfg.Package.Dependencies.ProviderPriority)
if err != nil {
return fmt.Errorf("failed to apply replacement to provides %q: %w", cfg.Package.Dependencies.ProviderPriority, err)
}
cfg.Package.Dependencies.ReplacesPriority, err = util.MutateStringFromMap(nw, cfg.Package.Dependencies.ReplacesPriority)
if err != nil {
return fmt.Errorf("failed to apply replacement to provides %q: %w", cfg.Package.Dependencies.ReplacesPriority, err)
}
for _, sp := range cfg.Subpackages {
sp.Dependencies.ProviderPriority, err = util.MutateStringFromMap(nw, sp.Dependencies.ProviderPriority)
if err != nil {
return fmt.Errorf("failed to apply replacement to provides %q: %w", sp.Dependencies.ProviderPriority, err)
}
sp.Dependencies.ReplacesPriority, err = util.MutateStringFromMap(nw, sp.Dependencies.ReplacesPriority)
if err != nil {
return fmt.Errorf("failed to apply replacement to provides %q: %w", sp.Dependencies.ReplacesPriority, err)
}
}
return nil
}


func (cfg *Configuration) applySubstitutionsForRuntime() error {
nw := buildConfigMap(cfg)
for i, runtime := range cfg.Package.Dependencies.Runtime {
Expand Down Expand Up @@ -515,8 +540,11 @@ type Dependencies struct {
// Optional: List of replace objectives
Replaces []string `json:"replaces,omitempty" yaml:"replaces,omitempty"`
// Optional: An integer compared against other equal package provides used to
// determine priority
ProviderPriority int `json:"provider-priority,omitempty" yaml:"provider-priority,omitempty"`
// determine priority of provides
ProviderPriority string `json:"provider-priority,omitempty" yaml:"provider-priority,omitempty"`
// Optional: An integer compared against other equal package provides used to
// determine priority of file replacements
ReplacesPriority string `json:"replaces-priority,omitempty" yaml:"replaces-priority,omitempty"`

// List of self-provided dependencies found outside of lib directories
// ("lib", "usr/lib", "lib64", or "usr/lib64").
Expand Down Expand Up @@ -762,7 +790,8 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts
Runtime: replaceAll(replacer, sp.Dependencies.Runtime),
Provides: replaceAll(replacer, sp.Dependencies.Provides),
Replaces: replaceAll(replacer, sp.Dependencies.Replaces),
ProviderPriority: sp.Dependencies.ProviderPriority,
ProviderPriority: replacer.Replace(sp.Dependencies.ProviderPriority),
ReplacesPriority: replacer.Replace(sp.Dependencies.ReplacesPriority),
},
Options: sp.Options,
Scriptlets: Scriptlets{
Expand Down Expand Up @@ -935,6 +964,9 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts
if err := cfg.applySubstitutionsForPackages(); err != nil {
return nil, err
}
if err := cfg.applySubstitutionsForPriorities(); err != nil {
return nil, err
}

// Propagate all child pipelines
cfg.propagatePipelines()
Expand Down
8 changes: 6 additions & 2 deletions pkg/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@
"description": "Optional: List of replace objectives"
},
"provider-priority": {
"type": "integer",
"description": "Optional: An integer compared against other equal package provides used to\ndetermine priority"
"type": "string",
"description": "Optional: An integer compared against other equal package provides used to\ndetermine priority of provides"
},
"replaces-priority": {
"type": "string",
"description": "Optional: An integer compared against other equal package provides used to\ndetermine priority of file replacements"
}
},
"additionalProperties": false,
Expand Down

0 comments on commit 750afdd

Please sign in to comment.