Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): change BuildCommand into slice #519

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions cmd/firmware-action/recipes/edk2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ package recipes

import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"runtime"

"dagger.io/dagger"
Expand All @@ -27,7 +25,7 @@ type Edk2Specific struct {
// "source ./edksetup.sh; build -t GCC5 -a IA32 -p UefiPayloadPkg/UefiPayloadPkg.dsc"
// "python UefiPayloadPkg/UniversalPayloadBuild.py"
// "Intel/AlderLakeFspPkg/BuildFv.sh"
BuildCommand string `json:"build_command" validate:"required"`
BuildCommand []string `json:"build_command" validate:"required"`
}

// ANCHOR_END: Edk2Specific
Expand All @@ -52,11 +50,6 @@ type Edk2Opts struct {
// - 'X64'
Arch string `json:"arch"`

// Gives the (relative) path to the defconfig that should be used to build the target.
// For EDK2 this is a one-line file containing the build arguments such as
// '-D BOOTLOADER=COREBOOT -D TPM_ENABLE=TRUE -D NETWORK_IPXE=TRUE'.
DefconfigPath string `json:"defconfig_path" validate:"filepath"`

// Coreboot specific options
Edk2Specific `validate:"required"`
}
Expand Down Expand Up @@ -105,32 +98,16 @@ func (opts Edk2Opts) buildFirmware(ctx context.Context, client *dagger.Client, d
myContainer = myContainer.WithEnvVariable(key, value)
}

// Assemble build arguments
// and read content of the config file at "defconfig_path"
var defconfigFileArgs []byte
if opts.DefconfigPath != "" {
if _, err := os.Stat(opts.DefconfigPath); !errors.Is(err, os.ErrNotExist) {
defconfigFileArgs, err = os.ReadFile(opts.DefconfigPath)
if err != nil {
return nil, err
}
} else {
slog.Warn(
fmt.Sprintf("Failed to read file '%s' as defconfig_path: file does not exist", opts.DefconfigPath),
slog.String("suggestion", "Double check the path for defconfig"),
slog.Any("error", err),
)
}
}

// Assemble commands to build
buildSteps := [][]string{}
if !(runtime.GOARCH == "386" || runtime.GOARCH == "amd64") {
// On all non-x86 architectures we have to also build the BaseTools
// Docs: https://go.dev/doc/install/source#environment
buildSteps = append(buildSteps, []string{"bash", "-c", "cd ${TOOLSDIR}/Edk2/; make -C BaseTools/ -j $(nproc)"})
}
buildSteps = append(buildSteps, []string{"bash", "-c", fmt.Sprintf("%s %s", opts.BuildCommand, string(defconfigFileArgs))})
for _, cmd := range opts.BuildCommand {
buildSteps = append(buildSteps, []string{"bash", "-c", cmd})
}

// Build
var myContainerPrevious *dagger.Container
Expand Down
9 changes: 2 additions & 7 deletions cmd/firmware-action/recipes/edk2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ func TestEdk2(t *testing.T) {
{
name: "normal build",
edk2Options: Edk2Opts{
CommonOpts: common,
DefconfigPath: "defconfig",
CommonOpts: common,
Edk2Specific: Edk2Specific{
BuildCommand: "source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t GCC5",
BuildCommand: []string{"source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t GCC5 -D BOOTLOADER=COREBOOT"},
},
},
version: "edk2-stable202105",
Expand Down Expand Up @@ -96,10 +95,6 @@ func TestEdk2(t *testing.T) {
assert.NoError(t, err)
defer os.Chdir(pwd) // nolint:errcheck

// Create "defconfig_path" file
err = os.WriteFile(tc.edk2Options.DefconfigPath, []byte("-D BOOTLOADER=COREBOOT"), 0o644)
assert.NoError(t, err)

// Artifacts
outputPath := filepath.Join(tmpDir, tc.edk2Options.OutputDir)
err = os.MkdirAll(outputPath, os.ModePerm)
Expand Down
5 changes: 3 additions & 2 deletions tests/example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
"sdk_url": "ghcr.io/9elements/firmware-action/${EDK2_VERSION}:main",
"arch": "X64",
"repo_path": "Edk2/",
"defconfig_path": "edk2_config.cfg",
"output_dir": "output-edk2/",
"container_output_dirs": [
"Build/"
],
"container_output_files": null,
"build_command": "source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t ${GCC_TOOLCHAIN_VERSION}",
"build_command": [
"source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t ${GCC_TOOLCHAIN_VERSION}"
],
"container_input_dir": "inputs/",
"input_dirs": null,
"input_files": null
Expand Down
5 changes: 3 additions & 2 deletions tests/example_config__edk2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"sdk_url": "ghcr.io/9elements/firmware-action/${EDK2_VERSION}:main",
"arch": "X64",
"repo_path": "Edk2/",
"defconfig_path": "edk2_config.cfg",
"output_dir": "output-edk2/",
"container_output_dirs": ["Build/"],
"container_output_files": null,
"build_command": "source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t ${GCC_TOOLCHAIN_VERSION}",
"build_command": [
"source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t ${GCC_TOOLCHAIN_VERSION}"
],
"container_input_dir": "inputs/",
"input_dirs": null,
"input_files": null
Expand Down
Loading