From 1d0d9801861138705e655de691d7bb9c8b3aac4b Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 20 Jul 2021 09:51:49 +0000 Subject: pkg/build: modify builder interface Modify the `builder` interface in such a way that build method also returns a struct containing extra information about the build process. This allows to fetch compiler ID from individual builders. Also, this makes the `signer` interface obsolete, as this information can also go into that structure. --- pkg/build/linux.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'pkg/build/linux.go') diff --git a/pkg/build/linux.go b/pkg/build/linux.go index 7aedaef16..7632712f2 100644 --- a/pkg/build/linux.go +++ b/pkg/build/linux.go @@ -24,31 +24,36 @@ import ( type linux struct{} -var _ signer = linux{} - -func (linux linux) build(params Params) error { +func (linux linux) build(params Params) (ImageDetails, error) { if err := linux.buildKernel(params); err != nil { - return err + return ImageDetails{}, err } kernelPath := filepath.Join(params.KernelDir, filepath.FromSlash(kernelBin(params.TargetArch))) if fileInfo, err := os.Stat(params.UserspaceDir); err == nil && fileInfo.IsDir() { // The old way of assembling the image from userspace dir. // It should be removed once all syzbot instances are switched. - return linux.createImage(params, kernelPath) - } - if params.VMType == "qemu" { + if err := linux.createImage(params, kernelPath); err != nil { + return ImageDetails{}, err + } + } else if params.VMType == "qemu" { // If UserspaceDir is a file (image) and we use qemu, we just copy image and kernel to the output dir // assuming that qemu will use injected kernel boot. In this mode we also assume password/key-less ssh. if err := osutil.CopyFile(kernelPath, filepath.Join(params.OutputDir, "kernel")); err != nil { - return err + return ImageDetails{}, err } - return osutil.CopyFile(params.UserspaceDir, filepath.Join(params.OutputDir, "image")) + if err := osutil.CopyFile(params.UserspaceDir, filepath.Join(params.OutputDir, "image")); err != nil { + return ImageDetails{}, err + } + } else if err := embedLinuxKernel(params, kernelPath); err != nil { + return ImageDetails{}, err } - return embedLinuxKernel(params, kernelPath) -} - -func (linux linux) sign(params Params) (string, error) { - return elfBinarySignature(filepath.Join(params.OutputDir, "obj", "vmlinux")) + signature, err := elfBinarySignature(filepath.Join(params.OutputDir, "obj", "vmlinux")) + if err != nil { + return ImageDetails{}, err + } + return ImageDetails{ + Signature: signature, + }, nil } func (linux linux) buildKernel(params Params) error { -- cgit mrf-deployment