aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-10-26 10:51:06 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-10-26 15:44:28 +0100
commite6e35dba937599d098fc034eff2686e5ddc409e9 (patch)
tree802be708d0bc84dee01b9285639690a53f1f6f94 /pkg/build
parentd46bc75207fea1d7671c1277dd660cf1a4d7847b (diff)
sys/targets: add OS/Arch name consts
We use strings to identify OS/Arch. These strings are duplicated throughout the code base massively. golangci-lint points to possiblity of typos and duplication. We already had to define these names in pkg/csource and disable checking for prog package. A future change triggers such warnings in another package. Add OS/Arch name consts to sys/targets so that they can be used to refer to OS/Arch. Use the consts everywhere.
Diffstat (limited to 'pkg/build')
-rw-r--r--pkg/build/build.go25
-rw-r--r--pkg/build/fuchsia.go2
-rw-r--r--pkg/build/linux.go11
-rw-r--r--pkg/build/netbsd.go3
4 files changed, 22 insertions, 19 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go
index 149d8729c..9931ce0ea 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -16,6 +16,7 @@ import (
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
"github.com/google/syzkaller/pkg/vcs"
+ "github.com/google/syzkaller/sys/targets"
)
// Params is input arguments for the Image function.
@@ -118,17 +119,17 @@ func getBuilder(targetOS, targetArch, vmType string) (builder, error) {
vms []string
b builder
}{
- {"linux", "amd64", []string{"gvisor"}, gvisor{}},
- {"linux", "amd64", []string{"gce", "qemu"}, linux{}},
- {"linux", "ppc64le", []string{"qemu"}, linux{}},
- {"linux", "s390x", []string{"qemu"}, linux{}},
- {"fuchsia", "amd64", []string{"qemu"}, fuchsia{}},
- {"fuchsia", "arm64", []string{"qemu"}, fuchsia{}},
- {"akaros", "amd64", []string{"qemu"}, akaros{}},
- {"openbsd", "amd64", []string{"gce", "vmm"}, openbsd{}},
- {"netbsd", "amd64", []string{"gce", "qemu"}, netbsd{}},
- {"freebsd", "amd64", []string{"gce", "qemu"}, freebsd{}},
- {"test", "64", []string{"qemu"}, test{}},
+ {targets.Linux, targets.AMD64, []string{"gvisor"}, gvisor{}},
+ {targets.Linux, targets.AMD64, []string{"gce", "qemu"}, linux{}},
+ {targets.Linux, targets.PPC64LE, []string{"qemu"}, linux{}},
+ {targets.Linux, targets.S390x, []string{"qemu"}, linux{}},
+ {targets.Fuchsia, targets.AMD64, []string{"qemu"}, fuchsia{}},
+ {targets.Fuchsia, targets.ARM64, []string{"qemu"}, fuchsia{}},
+ {targets.Akaros, targets.AMD64, []string{"qemu"}, akaros{}},
+ {targets.OpenBSD, targets.AMD64, []string{"gce", "vmm"}, openbsd{}},
+ {targets.NetBSD, targets.AMD64, []string{"gce", "qemu"}, netbsd{}},
+ {targets.FreeBSD, targets.AMD64, []string{"gce", "qemu"}, freebsd{}},
+ {targets.TestOS, targets.TestArch64, []string{"qemu"}, test{}},
}
for _, s := range supported {
if targetOS == s.OS && targetArch == s.arch {
@@ -193,7 +194,7 @@ func extractRootCause(err error, OS, kernelSrc string) error {
Output: verr.Output,
guiltyFile: file,
}
- if file != "" && OS == "linux" {
+ if file != "" && OS == targets.Linux {
maintainers, err := report.GetLinuxMaintainers(kernelSrc, file)
if err != nil {
kernelErr.Output = append(kernelErr.Output, err.Error()...)
diff --git a/pkg/build/fuchsia.go b/pkg/build/fuchsia.go
index f4bb2c8b4..ea1e2dccb 100644
--- a/pkg/build/fuchsia.go
+++ b/pkg/build/fuchsia.go
@@ -33,7 +33,7 @@ func (fu fuchsia) build(params *Params) error {
return err
}
- sysTarget := targets.Get("fuchsia", params.TargetArch)
+ sysTarget := targets.Get(targets.Fuchsia, params.TargetArch)
if sysTarget == nil {
return fmt.Errorf("unsupported fuchsia arch %v", params.TargetArch)
}
diff --git a/pkg/build/linux.go b/pkg/build/linux.go
index 36f18b84f..7566eca21 100644
--- a/pkg/build/linux.go
+++ b/pkg/build/linux.go
@@ -18,6 +18,7 @@ import (
"time"
"github.com/google/syzkaller/pkg/osutil"
+ "github.com/google/syzkaller/sys/targets"
)
type linux struct{}
@@ -57,9 +58,9 @@ func (linux linux) buildKernel(params *Params) error {
// We build only zImage/bzImage as we currently don't use modules.
var target string
switch params.TargetArch {
- case "386", "amd64", "s390x":
+ case targets.I386, targets.AMD64, targets.S390x:
target = "bzImage"
- case "ppc64le":
+ case targets.PPC64LE:
target = "zImage"
}
@@ -110,11 +111,11 @@ func (linux) createImage(params *Params) error {
var kernelImage string
switch params.TargetArch {
- case "386", "amd64":
+ case targets.I386, targets.AMD64:
kernelImage = "arch/x86/boot/bzImage"
- case "ppc64le":
+ case targets.PPC64LE:
kernelImage = "arch/powerpc/boot/zImage.pseries"
- case "s390x":
+ case targets.S390x:
kernelImage = "arch/s390/boot/bzImage"
}
kernelImagePath := filepath.Join(params.KernelDir, filepath.FromSlash(kernelImage))
diff --git a/pkg/build/netbsd.go b/pkg/build/netbsd.go
index 43620c9cf..e0f4bcea0 100644
--- a/pkg/build/netbsd.go
+++ b/pkg/build/netbsd.go
@@ -16,6 +16,7 @@ import (
"github.com/google/syzkaller/pkg/mgrconfig"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
+ "github.com/google/syzkaller/sys/targets"
"github.com/google/syzkaller/vm"
)
@@ -104,7 +105,7 @@ func (ctx netbsd) copyKernelToDisk(targetArch, vmType, outputDir, kernel string)
Image: filepath.Join(outputDir, "image"),
SSHKey: filepath.Join(outputDir, "key"),
SSHUser: "root",
- TargetOS: "netbsd",
+ TargetOS: targets.NetBSD,
TargetArch: targetArch,
TargetVMArch: targetArch,
Type: "qemu",