From 484e362fcff09b8b74162eefd0c3bfd67e829d94 Mon Sep 17 00:00:00 2001 From: Florent Revest Date: Wed, 2 Oct 2024 16:02:12 +0200 Subject: pkg/build: use the build environment in clean() calls This unifies the build() and clean() interfaces such that if a custom compiler or make binary is provided in the manager or bisection config, they can be taken into account by the clean() interface. --- pkg/build/linux.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'pkg/build/linux.go') diff --git a/pkg/build/linux.go b/pkg/build/linux.go index 5728005da..73baed5d8 100644 --- a/pkg/build/linux.go +++ b/pkg/build/linux.go @@ -14,7 +14,6 @@ import ( "path" "path/filepath" "regexp" - "runtime" "time" "github.com/google/syzkaller/pkg/debugtracer" @@ -141,8 +140,8 @@ func (linux) createImage(params Params, kernelPath string) error { return nil } -func (linux) clean(kernelDir, targetArch string) error { - return runMakeImpl(targetArch, "", "", "", "", kernelDir, runtime.NumCPU(), []string{"distclean"}) +func (linux) clean(params Params) error { + return runMake(params, "distclean") } func (linux) writeFile(file string, data []byte) error { @@ -152,10 +151,11 @@ func (linux) writeFile(file string, data []byte) error { return osutil.SandboxChown(file) } -func runMakeImpl(arch, compiler, linker, ccache, makeBin, kernelDir string, jobs int, extraArgs []string) error { - target := targets.Get(targets.Linux, arch) - args := LinuxMakeArgs(target, compiler, linker, ccache, "", jobs) +func runMake(params Params, extraArgs ...string) error { + target := targets.Get(targets.Linux, params.TargetArch) + args := LinuxMakeArgs(target, params.Compiler, params.Linker, params.Ccache, "", params.BuildCPUs) args = append(args, extraArgs...) + makeBin := params.Make if makeBin == "" { makeBin = "make" } @@ -163,7 +163,7 @@ func runMakeImpl(arch, compiler, linker, ccache, makeBin, kernelDir string, jobs if err := osutil.Sandbox(cmd, true, true); err != nil { return err } - cmd.Dir = kernelDir + cmd.Dir = params.KernelDir cmd.Env = append([]string{}, os.Environ()...) // This makes the build [more] deterministic: // 2 builds from the same sources should result in the same vmlinux binary. @@ -181,11 +181,6 @@ func runMakeImpl(arch, compiler, linker, ccache, makeBin, kernelDir string, jobs return err } -func runMake(params Params, extraArgs ...string) error { - return runMakeImpl(params.TargetArch, params.Compiler, params.Linker, - params.Ccache, params.Make, params.KernelDir, params.BuildCPUs, extraArgs) -} - func LinuxMakeArgs(target *targets.Target, compiler, linker, ccache, buildDir string, jobs int) []string { args := []string{ "-j", fmt.Sprint(jobs), -- cgit mrf-deployment