Skip to content

Commit baeadd5

Browse files
authored
Merge pull request #93 from getsolus/sccache-workaround
Start sccache server when ccache is enabled
2 parents 4d9d8e2 + efcff7b commit baeadd5

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION := 1.6.1
1+
VERSION := 1.6.2
22
BINNAME := solbuild
33

44
.PHONY: build

builder/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ func (p *Package) BuildYpkg(notif PidNotifier, usr *UserInfo, pman *EopkgManager
335335
cmd += fmt.Sprintf(" -t %v", h.GetLastVersionTimestamp())
336336
}
337337

338+
if p.CanCCache {
339+
// Start an sccache server to work around #87
340+
StartSccache(overlay.MountPoint)
341+
}
342+
338343
slog.Info("Now starting build", "package", p.Name)
339344

340345
if err := ChrootExec(notif, overlay.MountPoint, cmd); err != nil {

builder/eopkg.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ func readURIFile(path string) (string, error) {
279279
if err != nil {
280280
return "", err
281281
}
282-
283282
defer fi.Close()
284283

285284
contents, err := io.ReadAll(fi)

builder/pkg.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Package struct {
6262
Path string // Path to the build spec
6363
Sources []source.Source // Each package has 0 or more sources that we fetch
6464
CanNetwork bool // Only applicable to ypkg builds
65+
CanCCache bool // Flag to enable (s)ccache
6566
}
6667

6768
// YmlPackage is a parsed ypkg build file.
@@ -71,6 +72,9 @@ type YmlPackage struct {
7172
Release int `yaml:"release"`
7273
Networking bool `yaml:"networking"` // If set to false (default) we disable networking in the build
7374
Source []map[string]string `yaml:"source"`
75+
76+
// Disable (s)ccache for this build.
77+
CCache bool `yaml:"ccache"`
7478
}
7579

7680
// XMLUpdate represents an update in the package history.
@@ -209,7 +213,7 @@ func NewYmlPackage(path string) (*Package, error) {
209213
func NewYmlPackageFromBytes(by []byte) (*Package, error) {
210214
var err error
211215

212-
ypkg := &YmlPackage{Networking: false}
216+
ypkg := &YmlPackage{Networking: false, CCache: true}
213217
if err = yaml.Unmarshal(by, ypkg); err != nil {
214218
return nil, err
215219
}
@@ -220,6 +224,7 @@ func NewYmlPackageFromBytes(by []byte) (*Package, error) {
220224
Release: ypkg.Release,
221225
Type: PackageTypeYpkg,
222226
CanNetwork: ypkg.Networking,
227+
CanCCache: ypkg.CCache,
223228
}
224229

225230
for _, row := range ypkg.Source {

builder/util.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package builder
1818

1919
import (
20+
"bytes"
2021
"crypto/sha256"
2122
"encoding/hex"
2223
"fmt"
2324
"log/slog"
2425
"os"
2526
"os/exec"
2627
"path/filepath"
28+
"slices"
2729
"strconv"
2830
"strings"
2931
"syscall"
@@ -225,6 +227,23 @@ func ChrootExecStdin(notif PidNotifier, dir, command string) error {
225227
return c.Wait()
226228
}
227229

230+
func StartSccache(dir string) {
231+
var buf bytes.Buffer
232+
233+
c := exec.Command("chroot", dir, "/bin/su", BuildUser, "-c", "sccache --start-server")
234+
c.Stdout = &buf
235+
c.Stderr = &buf
236+
c.Env = slices.Clone(ChrootEnvironment)
237+
c.Env = append(c.Env, "SCCACHE_IDLE_TIMEOUT=0")
238+
c.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
239+
240+
slog.Debug("Starting sccache server")
241+
242+
if err := c.Run(); err != nil {
243+
slog.Warn("Unable to start sccache server", "err", err, "output", buf.String())
244+
}
245+
}
246+
228247
// AddBuildUser will attempt to add the solbuild user & group if they've not
229248
// previously been added
230249
// Note this should be changed when Solus goes fully stateless for /etc/passwd.

0 commit comments

Comments
 (0)