diff --git a/Makefile b/Makefile index c1d7545..2fcda09 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 1.6.1 +VERSION := 1.6.2 BINNAME := solbuild .PHONY: build diff --git a/builder/build.go b/builder/build.go index 4e3dacd..92d426f 100644 --- a/builder/build.go +++ b/builder/build.go @@ -335,6 +335,11 @@ func (p *Package) BuildYpkg(notif PidNotifier, usr *UserInfo, pman *EopkgManager cmd += fmt.Sprintf(" -t %v", h.GetLastVersionTimestamp()) } + if p.CanCCache { + // Start an sccache server to work around #87 + StartSccache(overlay.MountPoint) + } + slog.Info("Now starting build", "package", p.Name) if err := ChrootExec(notif, overlay.MountPoint, cmd); err != nil { diff --git a/builder/eopkg.go b/builder/eopkg.go index 8c4899d..1c0c887 100644 --- a/builder/eopkg.go +++ b/builder/eopkg.go @@ -279,7 +279,6 @@ func readURIFile(path string) (string, error) { if err != nil { return "", err } - defer fi.Close() contents, err := io.ReadAll(fi) diff --git a/builder/pkg.go b/builder/pkg.go index 6232eb0..b5bf0f6 100644 --- a/builder/pkg.go +++ b/builder/pkg.go @@ -62,6 +62,7 @@ type Package struct { Path string // Path to the build spec Sources []source.Source // Each package has 0 or more sources that we fetch CanNetwork bool // Only applicable to ypkg builds + CanCCache bool // Flag to enable (s)ccache } // YmlPackage is a parsed ypkg build file. @@ -71,6 +72,9 @@ type YmlPackage struct { Release int `yaml:"release"` Networking bool `yaml:"networking"` // If set to false (default) we disable networking in the build Source []map[string]string `yaml:"source"` + + // Disable (s)ccache for this build. + CCache bool `yaml:"ccache"` } // XMLUpdate represents an update in the package history. @@ -209,7 +213,7 @@ func NewYmlPackage(path string) (*Package, error) { func NewYmlPackageFromBytes(by []byte) (*Package, error) { var err error - ypkg := &YmlPackage{Networking: false} + ypkg := &YmlPackage{Networking: false, CCache: true} if err = yaml.Unmarshal(by, ypkg); err != nil { return nil, err } @@ -220,6 +224,7 @@ func NewYmlPackageFromBytes(by []byte) (*Package, error) { Release: ypkg.Release, Type: PackageTypeYpkg, CanNetwork: ypkg.Networking, + CanCCache: ypkg.CCache, } for _, row := range ypkg.Source { diff --git a/builder/util.go b/builder/util.go index ea69351..5577885 100644 --- a/builder/util.go +++ b/builder/util.go @@ -17,6 +17,7 @@ package builder import ( + "bytes" "crypto/sha256" "encoding/hex" "fmt" @@ -24,6 +25,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strconv" "strings" "syscall" @@ -225,6 +227,23 @@ func ChrootExecStdin(notif PidNotifier, dir, command string) error { return c.Wait() } +func StartSccache(dir string) { + var buf bytes.Buffer + + c := exec.Command("chroot", dir, "/bin/su", BuildUser, "-c", "sccache --start-server") + c.Stdout = &buf + c.Stderr = &buf + c.Env = slices.Clone(ChrootEnvironment) + c.Env = append(c.Env, "SCCACHE_IDLE_TIMEOUT=0") + c.SysProcAttr = &syscall.SysProcAttr{Setsid: true} + + slog.Debug("Starting sccache server") + + if err := c.Run(); err != nil { + slog.Warn("Unable to start sccache server", "err", err, "output", buf.String()) + } +} + // AddBuildUser will attempt to add the solbuild user & group if they've not // previously been added // Note this should be changed when Solus goes fully stateless for /etc/passwd.