Skip to content

Commit

Permalink
remove build options
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <jason@chainguard.dev>
  • Loading branch information
imjasonh committed Jan 31, 2025
1 parent 6c1d51c commit 318f0fe
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 170 deletions.
3 changes: 1 addition & 2 deletions docs/md/melange_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ melange build [flags]
--apk-cache-dir string directory used for cached apk packages (default is system-defined cache directory)
--arch strings architectures to build for (e.g., x86_64,ppc64le,arm64) -- default is all, unless specified in config
--build-date string date used for the timestamps of the files inside the image
--build-option strings build options to enable
--cache-dir string directory used for cached inputs (default "./melange-cache/")
--cache-source string directory or bucket used for preloading the cache
--cleanup when enabled, the temp dir used for the guest will be cleaned up after completion (default true)
Expand All @@ -54,7 +53,7 @@ melange build [flags]
-k, --keyring-append strings path to extra keys to include in the build environment keyring
--license string license to use for the build config file itself (default "NOASSERTION")
--lint-require strings linters that must pass (default [dev,infodir,tempdir,varempty])
--lint-warn strings linters that will generate warnings (default [object,opt,pkgconf,python/docs,python/multiple,python/test,setuidgid,srv,strip,usrlocal,usrmerge,worldwrite])
--lint-warn strings linters that will generate warnings (default [empty,object,opt,pkgconf,python/docs,python/multiple,python/test,setuidgid,srv,strip,usrlocal,usrmerge,worldwrite])
--memory string default memory resources to use for builds
--namespace string namespace to use in package URLs in SBOM (eg wolfi, alpine) (default "unknown")
--out-dir string directory where packages will be output (default "./packages/")
Expand Down
1 change: 0 additions & 1 deletion docs/md/melange_compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ melange compile [flags]
--apk-cache-dir string directory used for cached apk packages (default is system-defined cache directory)
--arch string architectures to compile for
--build-date string date used for the timestamps of the files inside the image
--build-option strings build options to enable
--cache-dir string directory used for cached inputs (default "./melange-cache/")
--cache-source string directory or bucket used for preloading the cache
--cpu string default CPU resources to use for builds
Expand Down
2 changes: 1 addition & 1 deletion docs/md/melange_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ melange lint [flags]
```
-h, --help help for lint
--lint-require strings linters that must pass (default [dev,infodir,tempdir,varempty])
--lint-warn strings linters that will generate warnings (default [object,opt,pkgconf,python/docs,python/multiple,python/test,setuidgid,srv,strip,usrlocal,usrmerge,worldwrite])
--lint-warn strings linters that will generate warnings (default [empty,object,opt,pkgconf,python/docs,python/multiple,python/test,setuidgid,srv,strip,usrlocal,usrmerge,worldwrite])
```

### Options inherited from parent commands
Expand Down
44 changes: 0 additions & 44 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ type Build struct {
Auth map[string]options.Auth
IgnoreSignatures bool

EnabledBuildOptions []string

// Initialized in New and mutated throughout the build process as we gain
// visibility into our packages' (including subpackages') composition. This is
// how we get "build-time" SBOMs!
Expand Down Expand Up @@ -257,17 +255,6 @@ func New(ctx context.Context, opts ...Option) (*Build, error) {
return nil, fmt.Errorf("unable to run containers using %s, specify --runner and one of %s", b.Runner.Name(), GetAllRunners())
}

// Apply build options to the context.
for _, optName := range b.EnabledBuildOptions {
log.Infof("applying configuration patches for build option %s", optName)

if opt, ok := b.Configuration.Options[optName]; ok {
if err := b.applyBuildOption(opt); err != nil {
return nil, err
}
}
}

return &b, nil
}

Expand Down Expand Up @@ -412,37 +399,6 @@ func copyFile(base, src, dest string, perm fs.FileMode) error {
return nil
}

// applyBuildOption applies a patch described by a BuildOption to a package build.
func (b *Build) applyBuildOption(bo config.BuildOption) error {
// Patch the variables block.
if b.Configuration.Vars == nil {
b.Configuration.Vars = make(map[string]string)
}

for k, v := range bo.Vars {
b.Configuration.Vars[k] = v
}

// Patch the build environment configuration.
lo := bo.Environment.Contents.Packages
b.Configuration.Environment.Contents.Packages = append(b.Configuration.Environment.Contents.Packages, lo.Add...)

for _, pkg := range lo.Remove {
pkgList := b.Configuration.Environment.Contents.Packages

for pos, ppkg := range pkgList {
if pkg == ppkg {
pkgList[pos] = pkgList[len(pkgList)-1]
pkgList = pkgList[:len(pkgList)-1]
}
}

b.Configuration.Environment.Contents.Packages = pkgList
}

return nil
}

func (b *Build) loadIgnoreRules(ctx context.Context) ([]*xignore.Pattern, error) {
log := clog.FromContext(ctx)
ignorePath := filepath.Join(b.SourceDir, b.WorkspaceIgnore)
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (t *Test) Compile(ctx context.Context) error {
// TODO: Make this parameter go away when we revisit subtitutions.
flavor := "gnu"

sm, err := NewSubstitutionMap(&cfg, t.Arch, flavor, nil)
sm, err := NewSubstitutionMap(&cfg, t.Arch, flavor)
if err != nil {
return err
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (t *Test) Compile(ctx context.Context) error {
// Compile compiles all configuration, including tests, by loading any pipelines and substituting all variables.
func (b *Build) Compile(ctx context.Context) error {
cfg := b.Configuration
sm, err := NewSubstitutionMap(&cfg, b.Arch, b.buildFlavor(), b.EnabledBuildOptions)
sm, err := NewSubstitutionMap(&cfg, b.Arch, "gnu")
if err != nil {
return err
}
Expand Down
11 changes: 0 additions & 11 deletions pkg/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,6 @@ func WithNamespace(namespace string) Option {
}
}

// WithEnabledBuildOptions takes an array of strings representing enabled build
// options. These options are referenced in the options block of the Configuration,
// and represent patches to the configured build process which are optionally
// applied.
func WithEnabledBuildOptions(enabledBuildOptions []string) Option {
return func(b *Build) error {
b.EnabledBuildOptions = enabledBuildOptions
return nil
}
}

// WithCreateBuildLog indicates whether to generate a package.log file containing the
// list of packages that were built. Some packages may have been skipped
// during the build if , so it can be hard to know exactly which packages were built
Expand Down
12 changes: 1 addition & 11 deletions pkg/build/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (sm *SubstitutionMap) Subpackage(subpkg *config.Subpackage) *SubstitutionMa
return &SubstitutionMap{nw}
}

func NewSubstitutionMap(cfg *config.Configuration, arch apkoTypes.Architecture, flavor string, buildOpts []string) (*SubstitutionMap, error) {
func NewSubstitutionMap(cfg *config.Configuration, arch apkoTypes.Architecture, flavor string) (*SubstitutionMap, error) {
pkg := cfg.Package

nw := map[string]string{
Expand Down Expand Up @@ -122,16 +122,6 @@ func NewSubstitutionMap(cfg *config.Configuration, arch apkoTypes.Architecture,
nw[k] = fmt.Sprintf("/home/build/melange-out/%s", pn)
}

for k := range cfg.Options {
nk := fmt.Sprintf("${{options.%s.enabled}}", k)
nw[nk] = "false"
}

for _, opt := range buildOpts {
nk := fmt.Sprintf("${{options.%s.enabled}}", opt)
nw[nk] = "true"
}

return &SubstitutionMap{nw}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/build/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Test_substitutionMap(t *testing.T) {
},
},
}
m, err := NewSubstitutionMap(&cfg, "", "", nil)
m, err := NewSubstitutionMap(&cfg, "", "")
require.NoError(t, err)
require.Equal(t, tt.expected, m.Substitutions["${{vars.mangled-package-version}}"])
})
Expand All @@ -92,7 +92,7 @@ func Test_MutateWith(t *testing.T) {
Epoch: tc.epoch,
},
}
sm, err := NewSubstitutionMap(&cfg, "", "", nil)
sm, err := NewSubstitutionMap(&cfg, "", "")
require.NoError(t, err)
got, err := sm.MutateWith(map[string]string{})
if err != nil {
Expand Down Expand Up @@ -128,7 +128,7 @@ func Test_substitutionNeedPackages(t *testing.T) {
pipelineDirs := []string{"pipelines"}

c := &Compiled{PipelineDirs: pipelineDirs}
sm, err := NewSubstitutionMap(&cfg, "", "", nil)
sm, err := NewSubstitutionMap(&cfg, "", "")
require.NoError(t, err)

err = c.CompilePipelines(ctx, sm, cfg.Pipeline)
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/pipelines/cargo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Compile an auditable rust binary with Cargo
| modroot | false | Top directory of the rust package, this is where the target package lives. Before building, the cargo pipeline wil cd into this directory. Defaults to current working directory | . |
| opts | false | Options to pass to cargo build. Defaults to release | --release |
| output | false | Filename to use when writing the binary. The final install location inside the apk will be in prefix / install-dir / output | |
| output-dir | false | Directory where the binaris will be placed after building. Defaults to target/release | target/release |
| prefix | false | Installation prefix. Defaults to usr | usr |
| rustflags | false | Rustc flags to be passed to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances. This string is split by whitespace. | |


<!-- end:pipeline-reference-gen -->
3 changes: 0 additions & 3 deletions pkg/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func buildCmd() *cobra.Command {
var envFile string
var varsFile string
var purlNamespace string
var buildOption []string
var createBuildLog bool
var debug bool
var debugRunner bool
Expand Down Expand Up @@ -172,7 +171,6 @@ func buildCmd() *cobra.Command {
build.WithEnvFile(envFile),
build.WithVarsFile(varsFile),
build.WithNamespace(purlNamespace),
build.WithEnabledBuildOptions(buildOption),
build.WithCreateBuildLog(createBuildLog),
build.WithDebug(debug),
build.WithDebugRunner(debugRunner),
Expand Down Expand Up @@ -240,7 +238,6 @@ func buildCmd() *cobra.Command {
cmd.Flags().StringVar(&purlNamespace, "namespace", "unknown", "namespace to use in package URLs in SBOM (eg wolfi, alpine)")
cmd.Flags().StringSliceVar(&archstrs, "arch", nil, "architectures to build for (e.g., x86_64,ppc64le,arm64) -- default is all, unless specified in config")
cmd.Flags().StringVar(&libc, "override-host-triplet-libc-substitution-flavor", "gnu", "override the flavor of libc for ${{host.triplet.*}} substitutions (e.g. gnu,musl) -- default is gnu")
cmd.Flags().StringSliceVar(&buildOption, "build-option", []string{}, "build options to enable")
cmd.Flags().StringVar(&runner, "runner", "", fmt.Sprintf("which runner to use to enable running commands, default is based on your platform. Options are %q", build.GetAllRunners()))
cmd.Flags().StringSliceVarP(&extraKeys, "keyring-append", "k", []string{}, "path to extra keys to include in the build environment keyring")
cmd.Flags().StringSliceVarP(&extraRepos, "repository-append", "r", []string{}, "path to extra repositories to include in the build environment")
Expand Down
3 changes: 0 additions & 3 deletions pkg/cli/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func compile() *cobra.Command {
var envFile string
var varsFile string
var purlNamespace string
var buildOption []string
var logPolicy []string
var createBuildLog bool
var debug bool
Expand Down Expand Up @@ -128,7 +127,6 @@ func compile() *cobra.Command {
build.WithEnvFile(envFile),
build.WithVarsFile(varsFile),
build.WithNamespace(purlNamespace),
build.WithEnabledBuildOptions(buildOption),
build.WithCreateBuildLog(createBuildLog),
build.WithDebug(debug),
build.WithDebugRunner(debugRunner),
Expand Down Expand Up @@ -192,7 +190,6 @@ func compile() *cobra.Command {
cmd.Flags().StringVar(&dependencyLog, "dependency-log", "", "log dependencies to a specified file")
cmd.Flags().StringVar(&overlayBinSh, "overlay-binsh", "", "use specified file as /bin/sh overlay in build environment")
cmd.Flags().StringVar(&purlNamespace, "namespace", "unknown", "namespace to use in package URLs in SBOM (eg wolfi, alpine)")
cmd.Flags().StringSliceVar(&buildOption, "build-option", []string{}, "build options to enable")
cmd.Flags().StringSliceVar(&logPolicy, "log-policy", []string{"builtin:stderr"}, "logging policy to use")
cmd.Flags().StringVar(&runner, "runner", "", fmt.Sprintf("which runner to use to enable running commands, default is based on your platform. Options are %q", build.GetAllRunners()))
cmd.Flags().StringSliceVarP(&extraKeys, "keyring-append", "k", []string{}, "path to extra keys to include in the build environment keyring")
Expand Down
11 changes: 0 additions & 11 deletions pkg/config/build_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,3 @@ type ListOption struct {
type ContentsOption struct {
Packages ListOption `yaml:"packages,omitempty"`
}

// EnvironmentOption describes an optional deviation to an apko environment.
type EnvironmentOption struct {
Contents ContentsOption `yaml:"contents,omitempty"`
}

// BuildOption describes an optional deviation to a package build.
type BuildOption struct {
Vars map[string]string `yaml:"vars,omitempty"`
Environment EnvironmentOption `yaml:"environment,omitempty"`
}
2 changes: 0 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,6 @@ type Configuration struct {
// Optional: A list of transformations to create for the builtin template
// variables
VarTransforms []VarTransforms `json:"var-transforms,omitempty" yaml:"var-transforms,omitempty"`
// Optional: Deviations to the build
Options map[string]BuildOption `json:"options,omitempty" yaml:"options,omitempty"`

// Test section for the main package.
Test *Test `json:"test,omitempty" yaml:"test,omitempty"`
Expand Down
Loading

0 comments on commit 318f0fe

Please sign in to comment.