aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-07-21 11:54:11 +0200
committerTaras Madan <tarasmadan@google.com>2023-07-24 09:12:13 +0000
commit7549a7e1b57831cf6b08ce4700fc6e53417919f9 (patch)
tree8e027cdaf7abbc52a5fb29c37c7137dfd2122e7a /pkg/build
parentf7eecac8b446ef11cff4122de6f496ad5eaba3a9 (diff)
all: use special placeholder for errors
Diffstat (limited to 'pkg/build')
-rw-r--r--pkg/build/akaros.go8
-rw-r--r--pkg/build/android.go26
-rw-r--r--pkg/build/build.go4
-rw-r--r--pkg/build/cuttlefish.go14
-rw-r--r--pkg/build/freebsd.go4
-rw-r--r--pkg/build/fuchsia.go2
-rw-r--r--pkg/build/linux.go14
-rw-r--r--pkg/build/linux_linux.go14
-rw-r--r--pkg/build/netbsd.go14
-rw-r--r--pkg/build/openbsd.go2
10 files changed, 51 insertions, 51 deletions
diff --git a/pkg/build/akaros.go b/pkg/build/akaros.go
index 9e1ecc66f..67b044f04 100644
--- a/pkg/build/akaros.go
+++ b/pkg/build/akaros.go
@@ -19,7 +19,7 @@ type akaros struct{}
func (ctx akaros) build(params Params) (ImageDetails, error) {
configFile := filepath.Join(params.KernelDir, ".config")
if err := osutil.WriteFile(configFile, params.Config); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to write config file: %v", err)
+ return ImageDetails{}, fmt.Errorf("failed to write config file: %w", err)
}
if err := osutil.SandboxChown(configFile); err != nil {
return ImageDetails{}, err
@@ -61,7 +61,7 @@ bash
`
initFile := filepath.Join(params.KernelDir, "kern", "kfs", "init.sh")
if err := osutil.WriteFile(initFile, []byte(init)); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to write init script: %v", err)
+ return ImageDetails{}, fmt.Errorf("failed to write init script: %w", err)
}
if err := osutil.SandboxChown(initFile); err != nil {
return ImageDetails{}, err
@@ -82,7 +82,7 @@ bash
return ImageDetails{}, err
}
if err := osutil.WriteFile(filepath.Join(params.OutputDir, "image"), nil); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to write image file: %v", err)
+ return ImageDetails{}, fmt.Errorf("failed to write image file: %w", err)
}
for src, dst := range map[string]string{
".config": "kernel.config",
@@ -93,7 +93,7 @@ bash
fullSrc := filepath.Join(params.KernelDir, filepath.FromSlash(src))
fullDst := filepath.Join(params.OutputDir, filepath.FromSlash(dst))
if err := osutil.CopyFile(fullSrc, fullDst); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to copy %v: %v", src, err)
+ return ImageDetails{}, fmt.Errorf("failed to copy %v: %w", src, err)
}
}
return ImageDetails{}, nil
diff --git a/pkg/build/android.go b/pkg/build/android.go
index bade7142f..13a7de2e6 100644
--- a/pkg/build/android.go
+++ b/pkg/build/android.go
@@ -86,7 +86,7 @@ func (a android) build(params Params) (ImageDetails, error) {
buildCfg.DefconfigFragment), fmt.Sprintf("BUILD_TARGET=%v", buildCfg.BuildTarget))
if _, err := osutil.Run(time.Hour, cmd); err != nil {
- return details, fmt.Errorf("failed to build kernel: %s", err)
+ return details, fmt.Errorf("failed to build kernel: %w", err)
}
buildDistDir := filepath.Join(params.KernelDir, "dist")
@@ -96,30 +96,30 @@ func (a android) build(params Params) (ImageDetails, error) {
details.CompilerID, err = a.readCompiler(params.KernelDir)
if err != nil {
- return details, fmt.Errorf("failed to read compiler: %v", err)
+ return details, fmt.Errorf("failed to read compiler: %w", err)
}
if err := osutil.CopyFile(vmlinux, filepath.Join(params.OutputDir, "obj", "vmlinux")); err != nil {
- return details, fmt.Errorf("failed to copy vmlinux: %v", err)
+ return details, fmt.Errorf("failed to copy vmlinux: %w", err)
}
if err := osutil.CopyFile(config, filepath.Join(params.OutputDir, "obj", "kernel.config")); err != nil {
- return details, fmt.Errorf("failed to copy kernel config: %v", err)
+ return details, fmt.Errorf("failed to copy kernel config: %w", err)
}
imageFile, err := os.Create(filepath.Join(params.OutputDir, "image"))
if err != nil {
- return details, fmt.Errorf("failed to create output file: %v", err)
+ return details, fmt.Errorf("failed to create output file: %w", err)
}
defer imageFile.Close()
if err := a.embedImages(imageFile, buildDistDir, "boot.img", "dtbo.img", buildCfg.VendorBootImage,
"vendor_dlkm.img"); err != nil {
- return details, fmt.Errorf("failed to embed images: %v", err)
+ return details, fmt.Errorf("failed to embed images: %w", err)
}
details.Signature, err = elfBinarySignature(vmlinux, params.Tracer)
if err != nil {
- return details, fmt.Errorf("failed to generate signature: %s", err)
+ return details, fmt.Errorf("failed to generate signature: %w", err)
}
return details, nil
@@ -133,7 +133,7 @@ func (a android) embedImages(w io.Writer, srcDir string, imageNames ...string) e
path := filepath.Join(srcDir, name)
data, err := os.ReadFile(path)
if err != nil {
- return fmt.Errorf("failed to read %q: %v", name, err)
+ return fmt.Errorf("failed to read %q: %w", name, err)
}
if err := tw.WriteHeader(&tar.Header{
@@ -141,16 +141,16 @@ func (a android) embedImages(w io.Writer, srcDir string, imageNames ...string) e
Mode: 0600,
Size: int64(len(data)),
}); err != nil {
- return fmt.Errorf("failed to write header for %q: %v", name, err)
+ return fmt.Errorf("failed to write header for %q: %w", name, err)
}
if _, err := tw.Write(data); err != nil {
- return fmt.Errorf("failed to write data for %q: %v", name, err)
+ return fmt.Errorf("failed to write data for %q: %w", name, err)
}
}
if err := tw.Close(); err != nil {
- return fmt.Errorf("close archive: %v", err)
+ return fmt.Errorf("close archive: %w", err)
}
return nil
@@ -158,10 +158,10 @@ func (a android) embedImages(w io.Writer, srcDir string, imageNames ...string) e
func (a android) clean(kernelDir, targetArch string) error {
if err := osutil.RemoveAll(filepath.Join(kernelDir, "out")); err != nil {
- return fmt.Errorf("failed to clean 'out' directory: %v", err)
+ return fmt.Errorf("failed to clean 'out' directory: %w", err)
}
if err := osutil.RemoveAll(filepath.Join(kernelDir, "dist")); err != nil {
- return fmt.Errorf("failed to clean 'dist' directory: %v", err)
+ return fmt.Errorf("failed to clean 'dist' directory: %w", err)
}
return nil
}
diff --git a/pkg/build/build.go b/pkg/build/build.go
index f4cee5d88..9bcacbd90 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -81,7 +81,7 @@ func Image(params Params) (details ImageDetails, err error) {
if len(params.Config) != 0 {
// Write kernel config early, so that it's captured on build failures.
if err = osutil.WriteFile(filepath.Join(params.OutputDir, "kernel.config"), params.Config); err != nil {
- err = fmt.Errorf("failed to write config file: %v", err)
+ err = fmt.Errorf("failed to write config file: %w", err)
return
}
}
@@ -100,7 +100,7 @@ func Image(params Params) (details ImageDetails, err error) {
}
if key := filepath.Join(params.OutputDir, "key"); osutil.IsExist(key) {
if err := os.Chmod(key, 0600); err != nil {
- return details, fmt.Errorf("failed to chmod 0600 %v: %v", key, err)
+ return details, fmt.Errorf("failed to chmod 0600 %v: %w", key, err)
}
}
return
diff --git a/pkg/build/cuttlefish.go b/pkg/build/cuttlefish.go
index 8580aeba1..377f14222 100644
--- a/pkg/build/cuttlefish.go
+++ b/pkg/build/cuttlefish.go
@@ -125,7 +125,7 @@ func (c cuttlefish) build(params Params) (ImageDetails, error) {
var err error
// Clean output directory if it exists.
if err := osutil.RemoveAll(filepath.Join(params.KernelDir, "out")); err != nil {
- return details, fmt.Errorf("failed to clean before kernel build: %v", err)
+ return details, fmt.Errorf("failed to clean before kernel build: %w", err)
}
// Default to build.sh if compiler is not specified.
if params.Compiler == "bazel" {
@@ -133,25 +133,25 @@ func (c cuttlefish) build(params Params) (ImageDetails, error) {
return details, errors.New("kernel config was not provided for build")
}
if err := c.createDefconfig(filepath.Join(params.KernelDir, "common"), params.Config); err != nil {
- return details, fmt.Errorf("failed to create defconfig file: %v", err)
+ return details, fmt.Errorf("failed to create defconfig file: %w", err)
}
if err := c.runBazel(params.KernelDir); err != nil {
- return details, fmt.Errorf("failed to build kernel: %s", err)
+ return details, fmt.Errorf("failed to build kernel: %w", err)
}
// Find the .config file; it is placed in a temporary output directory during the build.
cmd := osutil.Command("find", ".", "-regex", ".*virtual_device_x86_64_config.*/\\.config")
cmd.Dir = params.KernelDir
configBytes, err := osutil.Run(time.Minute, cmd)
if err != nil {
- return details, fmt.Errorf("failed to find build config: %v", err)
+ return details, fmt.Errorf("failed to find build config: %w", err)
}
config = filepath.Join(params.KernelDir, strings.TrimSpace(string(configBytes)))
} else {
if err := c.runBuild(params.KernelDir, kernelConfig); err != nil {
- return details, fmt.Errorf("failed to build kernel: %s", err)
+ return details, fmt.Errorf("failed to build kernel: %w", err)
}
if err := c.runBuild(params.KernelDir, moduleConfig); err != nil {
- return details, fmt.Errorf("failed to build modules: %s", err)
+ return details, fmt.Errorf("failed to build modules: %w", err)
}
config = filepath.Join(params.KernelDir, "out", "common", ".config")
}
@@ -196,7 +196,7 @@ func (c cuttlefish) build(params Params) (ImageDetails, error) {
details.Signature, err = elfBinarySignature(vmlinux, params.Tracer)
if err != nil {
- return details, fmt.Errorf("failed to generate signature: %s", err)
+ return details, fmt.Errorf("failed to generate signature: %w", err)
}
return details, nil
diff --git a/pkg/build/freebsd.go b/pkg/build/freebsd.go
index c4cae75d0..2f4aa1313 100644
--- a/pkg/build/freebsd.go
+++ b/pkg/build/freebsd.go
@@ -68,7 +68,7 @@ options DIAGNOSTIC
fullSrc := filepath.Join(s.dir, s.src)
fullDst := filepath.Join(params.OutputDir, s.dst)
if err := osutil.CopyFile(fullSrc, fullDst); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to copy %v -> %v: %v", fullSrc, fullDst, err)
+ return ImageDetails{}, fmt.Errorf("failed to copy %v -> %v: %w", fullSrc, fullDst, err)
}
}
@@ -114,7 +114,7 @@ sudo mdconfig -d -u ${md#md}
`, objPrefix, params.KernelDir, confFile)
if debugOut, err := osutil.RunCmd(10*time.Minute, params.OutputDir, "/bin/sh", "-c", script); err != nil {
- return ImageDetails{}, fmt.Errorf("error copying kernel: %v\n%v", err, debugOut)
+ return ImageDetails{}, fmt.Errorf("error copying kernel: %w\n%v", err, debugOut)
}
return ImageDetails{}, nil
}
diff --git a/pkg/build/fuchsia.go b/pkg/build/fuchsia.go
index 22efc3de7..5a7c4fd82 100644
--- a/pkg/build/fuchsia.go
+++ b/pkg/build/fuchsia.go
@@ -87,7 +87,7 @@ func (fu fuchsia) build(params Params) (ImageDetails, error) {
fullSrc := filepath.Join(params.KernelDir, filepath.FromSlash(src))
fullDst := filepath.Join(params.OutputDir, filepath.FromSlash(dst))
if err := osutil.CopyFile(fullSrc, fullDst); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to copy %v: %v", src, err)
+ return ImageDetails{}, fmt.Errorf("failed to copy %v: %w", src, err)
}
}
return ImageDetails{}, nil
diff --git a/pkg/build/linux.go b/pkg/build/linux.go
index 112e2dfab..4069e0202 100644
--- a/pkg/build/linux.go
+++ b/pkg/build/linux.go
@@ -70,7 +70,7 @@ func (linux linux) build(params Params) (ImageDetails, error) {
func (linux linux) buildKernel(params Params) error {
configFile := filepath.Join(params.KernelDir, ".config")
if err := linux.writeFile(configFile, params.Config); err != nil {
- return fmt.Errorf("failed to write config file: %v", err)
+ return fmt.Errorf("failed to write config file: %w", err)
}
// One would expect olddefconfig here, but olddefconfig is not present in v3.6 and below.
// oldconfig is the same as olddefconfig if stdin is not set.
@@ -107,7 +107,7 @@ func (linux linux) buildKernel(params Params) error {
vmlinux := filepath.Join(params.KernelDir, "vmlinux")
outputVmlinux := filepath.Join(params.OutputDir, "obj", "vmlinux")
if err := osutil.Rename(vmlinux, outputVmlinux); err != nil {
- return fmt.Errorf("failed to rename vmlinux: %v", err)
+ return fmt.Errorf("failed to rename vmlinux: %w", err)
}
return nil
}
@@ -120,7 +120,7 @@ func (linux) createImage(params Params, kernelPath string) error {
defer os.RemoveAll(tempDir)
scriptFile := filepath.Join(tempDir, "create.sh")
if err := osutil.WriteExecFile(scriptFile, []byte(createImageScript)); err != nil {
- return fmt.Errorf("failed to write script file: %v", err)
+ return fmt.Errorf("failed to write script file: %w", err)
}
cmd := osutil.Command(scriptFile, params.UserspaceDir, kernelPath, params.TargetArch)
cmd.Dir = tempDir
@@ -131,7 +131,7 @@ func (linux) createImage(params Params, kernelPath string) error {
"SYZ_SYSCTL_FILE="+osutil.Abs(params.SysctlFile),
)
if _, err = osutil.Run(time.Hour, cmd); err != nil {
- return fmt.Errorf("image build failed: %v", err)
+ return fmt.Errorf("image build failed: %w", err)
}
// Note: we use CopyFile instead of Rename because src and dst can be on different filesystems.
imageFile := filepath.Join(params.OutputDir, "image")
@@ -254,11 +254,11 @@ func queryLinuxCompiler(kernelDir string) (string, error) {
func elfBinarySignature(bin string, tracer debugtracer.DebugTracer) (string, error) {
f, err := os.Open(bin)
if err != nil {
- return "", fmt.Errorf("failed to open binary for signature: %v", err)
+ return "", fmt.Errorf("failed to open binary for signature: %w", err)
}
ef, err := elf.NewFile(f)
if err != nil {
- return "", fmt.Errorf("failed to open elf binary: %v", err)
+ return "", fmt.Errorf("failed to open elf binary: %w", err)
}
hasher := sha256.New()
for _, sec := range ef.Sections {
@@ -272,7 +272,7 @@ func elfBinarySignature(bin string, tracer debugtracer.DebugTracer) (string, err
}
data, err := sec.Data()
if err != nil {
- return "", fmt.Errorf("failed to read ELF section %v: %v", sec.Name, err)
+ return "", fmt.Errorf("failed to read ELF section %v: %w", sec.Name, err)
}
hasher1 := sha256.New()
hasher1.Write(data)
diff --git a/pkg/build/linux_linux.go b/pkg/build/linux_linux.go
index d22fea678..c81ccf28e 100644
--- a/pkg/build/linux_linux.go
+++ b/pkg/build/linux_linux.go
@@ -58,7 +58,7 @@ func embedFiles(params Params, callback func(mountDir string) error) error {
return err
}
if err := tryMount(loopFile+"p1", mountDir); err != nil {
- return fmt.Errorf("mount(%vp1, %v) failed: %v", loopFile, mountDir, err)
+ return fmt.Errorf("mount(%vp1, %v) failed: %w", loopFile, mountDir, err)
}
defer unix.Unmount(mountDir, 0)
if err := callback(mountDir); err != nil {
@@ -122,26 +122,26 @@ func copyKernel(mountDir, kernelPath string) error {
func linuxSetupLoop(imageFile string) (int, string, error) {
image, err := unix.Open(imageFile, unix.O_RDWR, 0)
if err != nil {
- return 0, "", fmt.Errorf("failed to open %v: %v", imageFile, err)
+ return 0, "", fmt.Errorf("failed to open %v: %w", imageFile, err)
}
defer unix.Close(image)
loopControl, err := unix.Open("/dev/loop-control", unix.O_RDWR, 0)
if err != nil {
- return 0, "", fmt.Errorf("failed to open /dev/loop-control: %v", err)
+ return 0, "", fmt.Errorf("failed to open /dev/loop-control: %w", err)
}
defer unix.Close(loopControl)
loopIndex, err := unix.IoctlRetInt(loopControl, unix.LOOP_CTL_GET_FREE)
if err != nil {
- return 0, "", fmt.Errorf("LOOP_CTL_GET_FREE failed: %v", err)
+ return 0, "", fmt.Errorf("LOOP_CTL_GET_FREE failed: %w", err)
}
loopFile := fmt.Sprintf("/dev/loop%v", loopIndex)
loop, err := unix.Open(loopFile, unix.O_RDWR, 0)
if err != nil {
- return 0, "", fmt.Errorf("failed to open %v: %v", loopFile, err)
+ return 0, "", fmt.Errorf("failed to open %v: %w", loopFile, err)
}
if err := unix.IoctlSetInt(loop, unix.LOOP_SET_FD, image); err != nil {
unix.Close(loop)
- return 0, "", fmt.Errorf("LOOP_SET_FD failed: %v", err)
+ return 0, "", fmt.Errorf("LOOP_SET_FD failed: %w", err)
}
info := &unix.LoopInfo64{
Flags: unix.LO_FLAGS_PARTSCAN,
@@ -152,7 +152,7 @@ func linuxSetupLoop(imageFile string) (int, string, error) {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(loop), unix.LOOP_SET_STATUS64,
uintptr(unsafe.Pointer(info))); err != 0 {
unix.Close(loop)
- return 0, "", fmt.Errorf("LOOP_SET_STATUS64 failed: %v", err)
+ return 0, "", fmt.Errorf("LOOP_SET_STATUS64 failed: %w", err)
}
return loop, loopFile, nil
}
diff --git a/pkg/build/netbsd.go b/pkg/build/netbsd.go
index b569b9833..8717b8105 100644
--- a/pkg/build/netbsd.go
+++ b/pkg/build/netbsd.go
@@ -75,12 +75,12 @@ func (ctx netbsd) build(params Params) (ImageDetails, error) {
fullSrc := filepath.Join(s.dir, s.src)
fullDst := filepath.Join(params.OutputDir, s.dst)
if err := osutil.CopyFile(fullSrc, fullDst); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to copy %v -> %v: %v", fullSrc, fullDst, err)
+ return ImageDetails{}, fmt.Errorf("failed to copy %v -> %v: %w", fullSrc, fullDst, err)
}
}
keyFile := filepath.Join(params.OutputDir, "key")
if err := os.Chmod(keyFile, 0600); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to chmod 0600 %v: %v", keyFile, err)
+ return ImageDetails{}, fmt.Errorf("failed to chmod 0600 %v: %w", keyFile, err)
}
return ImageDetails{}, ctx.copyKernelToDisk(params.TargetArch, params.VMType, params.OutputDir,
filepath.Join(compileDir, "netbsd"))
@@ -117,23 +117,23 @@ func (ctx netbsd) copyKernelToDisk(targetArch, vmType, outputDir, kernel string)
// Create a VM pool.
pool, err := vm.Create(cfg, false)
if err != nil {
- return fmt.Errorf("failed to create a VM Pool: %v", err)
+ return fmt.Errorf("failed to create a VM Pool: %w", err)
}
// Create a new reporter instance.
reporter, err := report.NewReporter(cfg)
if err != nil {
- return fmt.Errorf("failed to create a Reporter: %v", err)
+ return fmt.Errorf("failed to create a Reporter: %w", err)
}
// Create a VM instance (we need only one).
inst, err := pool.Create(0)
if err != nil {
- return fmt.Errorf("failed to create the VM Instance: %v", err)
+ return fmt.Errorf("failed to create the VM Instance: %w", err)
}
defer inst.Close()
// Copy the kernel into the disk image and replace it.
kernel, err = inst.Copy(kernel)
if err != nil {
- return fmt.Errorf("error copying the kernel: %v", err)
+ return fmt.Errorf("error copying the kernel: %w", err)
}
if kernel != "/netbsd" {
return fmt.Errorf("kernel is copied into wrong location: %v", kernel)
@@ -153,7 +153,7 @@ func (ctx netbsd) copyKernelToDisk(targetArch, vmType, outputDir, kernel string)
commands = append(commands, "sync") // Run sync so that the copied image is stored properly.
outc, errc, err := inst.Run(time.Minute, nil, strings.Join(commands, ";"))
if err != nil {
- return fmt.Errorf("error syncing the instance %v", err)
+ return fmt.Errorf("error syncing the instance %w", err)
}
// Make sure that the command has executed properly.
rep := inst.MonitorExecution(outc, errc, reporter, vm.ExitNormal)
diff --git a/pkg/build/openbsd.go b/pkg/build/openbsd.go
index 60a35d190..97f7c6a8f 100644
--- a/pkg/build/openbsd.go
+++ b/pkg/build/openbsd.go
@@ -45,7 +45,7 @@ func (ctx openbsd) build(params Params) (ImageDetails, error) {
fullSrc := filepath.Join(s.dir, s.src)
fullDst := filepath.Join(params.OutputDir, s.dst)
if err := osutil.CopyFile(fullSrc, fullDst); err != nil {
- return ImageDetails{}, fmt.Errorf("failed to copy %v -> %v: %v", fullSrc, fullDst, err)
+ return ImageDetails{}, fmt.Errorf("failed to copy %v -> %v: %w", fullSrc, fullDst, err)
}
}
if params.VMType == "gce" {