Skip to content

Commit

Permalink
Merge pull request #93 from getsolus/sccache-workaround
Browse files Browse the repository at this point in the history
Start sccache server when ccache is enabled
  • Loading branch information
GZGavinZhao authored Apr 1, 2024
2 parents 4d9d8e2 + efcff7b commit baeadd5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 1.6.1
VERSION := 1.6.2
BINNAME := solbuild

.PHONY: build
Expand Down
5 changes: 5 additions & 0 deletions builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion builder/eopkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ func readURIFile(path string) (string, error) {
if err != nil {
return "", err
}

defer fi.Close()

contents, err := io.ReadAll(fi)
Expand Down
7 changes: 6 additions & 1 deletion builder/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions builder/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package builder

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"log/slog"
"os"
"os/exec"
"path/filepath"
"slices"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit baeadd5

Please sign in to comment.