aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build
diff options
context:
space:
mode:
authorFlorent Revest <revest@chromium.org>2024-10-15 09:32:22 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-10-15 08:24:09 +0000
commit601564862a81ea5b1de0ab287c56a2735f8788f1 (patch)
tree95e9da94d2457f14e007adcfdc91ae19d9e1f305 /pkg/build
parentb01b66617e506413d4af9a64ffdfd5d2508010d7 (diff)
pkg/build: share parameters sanitization between builds and cleans
When refactoring the Clean() function to share more code with Image(), there is logic I forgot to replicate, like setting a default number of CPUs to build/clean with. I imagine that not setting the default tracer could end up being a subtle issue in the future too. To avoid missing these cases in the future, refactor the parameters sanitization into a helper function called by both.
Diffstat (limited to 'pkg/build')
-rw-r--r--pkg/build/build.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go
index b84adb20b..c9a5b038f 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -49,6 +49,15 @@ type ImageDetails struct {
CompilerID string
}
+func sanitize(params *Params) {
+ if params.Tracer == nil {
+ params.Tracer = &debugtracer.NullTracer{}
+ }
+ if params.BuildCPUs == 0 {
+ params.BuildCPUs = runtime.NumCPU()
+ }
+}
+
// Image creates a disk image for the specified OS/ARCH/VM.
// Kernel is taken from KernelDir, userspace system is taken from UserspaceDir.
// If CmdlineFile is not empty, contents of the file are appended to the kernel command line.
@@ -71,12 +80,7 @@ type ImageDetails struct {
// the version of the compiler/toolchain that was used to build the kernel.
// The CompilerID field is not guaranteed to be non-empty.
func Image(params Params) (details ImageDetails, err error) {
- if params.Tracer == nil {
- params.Tracer = &debugtracer.NullTracer{}
- }
- if params.BuildCPUs == 0 {
- params.BuildCPUs = runtime.NumCPU()
- }
+ sanitize(&params)
var builder builder
builder, err = getBuilder(params.TargetOS, params.TargetArch, params.VMType)
if err != nil {
@@ -114,6 +118,7 @@ func Image(params Params) (details ImageDetails, err error) {
}
func Clean(params Params) error {
+ sanitize(&params)
builder, err := getBuilder(params.TargetOS, params.TargetArch, params.VMType)
if err != nil {
return err