Skip to content

Commit a0041ff

Browse files
committed
build: actually mount source dir read-only
From https://unix.stackexchange.com/a/128388/181634: To achieve the desired result one needs to run two commands […]: mount SRC DST -o bind mount DST -o remount,ro,bind
1 parent 9a794f4 commit a0041ff

15 files changed

Lines changed: 154 additions & 92 deletions

File tree

cmd/distri/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,9 @@ func (b *buildctx) build() (*pb.Meta, error) {
12491249
if err := syscall.Mount(b.SourceDir, src, "none", syscall.MS_BIND|syscall.MS_RDONLY, ""); err != nil {
12501250
return nil, xerrors.Errorf("bind mount %s %s: %v", b.SourceDir, src, err)
12511251
}
1252+
if err := syscall.Mount("", src, "", syscall.MS_REMOUNT|syscall.MS_BIND|syscall.MS_RDONLY, ""); err != nil {
1253+
return nil, xerrors.Errorf("bind remount read-only %s %s: %v", b.SourceDir, src, err)
1254+
}
12521255
b.SourceDir = strings.TrimPrefix(src, b.ChrootDir)
12531256

12541257
wrappersSrc := filepath.Join(b.PkgDir, "wrappers")

cmd/distri/buildcmake.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ import (
88
)
99

1010
func (b *buildctx) buildcmake(opts *pb.CMakeBuilder, env []string) (newSteps []*pb.BuildStep, newEnv []string, _ error) {
11-
steps := [][]string{
11+
dir := "${DISTRI_SOURCEDIR}"
12+
var steps [][]string
13+
if opts.GetCopyToBuilddir() {
14+
dir = "."
15+
steps = [][]string{
16+
[]string{"cp", "-T", "-ar", "${DISTRI_SOURCEDIR}/", "."},
17+
}
18+
}
19+
steps = append(steps, [][]string{
1220
append([]string{
1321
"/bin/cmake",
14-
"${DISTRI_SOURCEDIR}",
22+
dir,
1523
"-DCMAKE_INSTALL_PREFIX:PATH=${DISTRI_PREFIX}",
1624
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
1725
"-G", "Ninja",
@@ -25,6 +33,6 @@ func (b *buildctx) buildcmake(opts *pb.CMakeBuilder, env []string) (newSteps []*
2533
"-c",
2634
"DESTDIR=${DISTRI_DESTDIR} ninja -v -j " + strconv.Itoa(runtime.NumCPU()) + " install",
2735
},
28-
}
36+
}...)
2937
return stepsToProto(steps), env, nil
3038
}

pb/build.pb.go

Lines changed: 75 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pb/build.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ message CMakeBuilder {
3232
// Additional flag to pass to cmake(1), e.g.:
3333
// extra_cmake_flag: "-DKICAD_SCRIPTING_WXPYTHON_PHOENIX:BOOL=true"
3434
repeated string extra_cmake_flag = 1;
35+
36+
// Enable if this package does not support building from a separate directory
37+
// (sometimes called “out-of-tree build”). A bug should be reported with the
38+
// package upstream.
39+
optional bool copy_to_builddir = 2;
3540
}
3641

3742
message MesonBuilder {

pkgs/bc/build.textproto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ source: "https://ftp.gnu.org/gnu/bc/bc-1.07.1.tar.gz"
22
hash: "62adfca89b0a1c0164c2cdca59ca210c1d44c3ffc46daf9931cf4942664cb02a"
33
version: "1.07.1-3"
44

5-
cbuilder: {}
5+
cbuilder: {
6+
copy_to_builddir: true # modifies source
7+
}
68

79
# build dependencies:
810
dep: "ed"

pkgs/emacs/build.textproto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ hash: "1cf4fc240cd77c25309d15e18593789c8dbfba5c2b44d8f77c886542300fd32c"
33
version: "26.1-11"
44

55
cbuilder: {
6+
copy_to_builddir: true # modifies source
67
extra_configure_flag: "--with-gnutls=no" # TODO: why doesn’t configure locate gnutls?
78
extra_configure_flag: "--with-x-toolkit=gtk3"
89
}

pkgs/gdk-pixbuf/build.textproto

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,32 @@ build_step: {
2929
build_step: {
3030
argv: "/bin/sh"
3131
argv: "-c"
32-
argv: "meson --prefix=${DISTRI_PREFIX} . ${DISTRI_SOURCEDIR} -Dinstalled_tests=false -Dman=false"
32+
argv: "cp -T -ar ${DISTRI_SOURCEDIR}/ ."
33+
}
34+
35+
build_step: {
36+
argv: "/bin/sh"
37+
argv: "-c"
38+
argv: "mkdir build"
39+
}
40+
41+
build_step: {
42+
argv: "/bin/sh"
43+
argv: "-c"
44+
argv: "meson --prefix=${DISTRI_PREFIX} build . -Dinstalled_tests=false -Dman=false"
3345
}
3446

3547
# kludge: the LD_LIBRARY_PATH change is required because we patched rpath handling out of meson.
3648
build_step: {
3749
argv: "/bin/sh"
3850
argv: "-c"
39-
argv: "LD_LIBRARY_PATH=$PWD/gdk-pixbuf:$PWD/gobject:$PWD/glib:$LD_LIBRARY_PATH ninja -j ${DISTRI_JOBS} -v"
51+
argv: "(cd build && LD_LIBRARY_PATH=$PWD/gdk-pixbuf:$PWD/gobject:$PWD/glib:$LD_LIBRARY_PATH ninja -j ${DISTRI_JOBS} -v)"
4052
}
4153

4254
build_step: {
4355
argv: "/bin/sh"
4456
argv: "-c"
45-
argv: "DESTDIR=${DISTRI_DESTDIR} ninja -j ${DISTRI_JOBS} -v install"
57+
argv: "(cd build && DESTDIR=${DISTRI_DESTDIR} ninja -j ${DISTRI_JOBS} -v install)"
4658
}
4759

4860
build_step: {

pkgs/glew/build.textproto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ dep: "libglvnd"
1212

1313
# Debian/Ubuntu/Mint: `$ sudo apt-get install build-essential libxmu-dev libxi-dev libgl-dev libosmesa-dev`
1414

15+
build_step: {
16+
argv: "/bin/sh"
17+
argv: "-c"
18+
argv: "cp -T -ar ${DISTRI_SOURCEDIR}/ ."
19+
}
20+
1521
build_step: {
1622
argv: "/bin/cmake"
17-
argv: "${DISTRI_SOURCEDIR}/build/cmake"
23+
argv: "build/cmake"
1824
argv: "-DCMAKE_INSTALL_PREFIX:PATH=${DISTRI_PREFIX}"
1925
argv: "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
2026
argv: "-DOPENGL_opengl_LIBRARY=/ro/${DISTRI_RESOLVE:libglvnd}/out/lib/libOpenGL.so"

pkgs/groff/build.textproto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ cbuilder: {}
88
dep: "perl"
99

1010
build_step: {
11-
argv: "${DISTRI_SOURCEDIR}/configure"
11+
argv: "/bin/sh"
12+
argv: "-c"
13+
argv: "cp -T -ar ${DISTRI_SOURCEDIR}/ ."
14+
}
15+
16+
build_step: {
17+
argv: "./configure"
1218
argv: "--prefix=${DISTRI_PREFIX}"
1319
}
1420

pkgs/json-c/build.textproto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ source: "https://s3.amazonaws.com/json-c_releases/releases/json-c-0.13.1.tar.gz"
22
hash: "b87e608d4d3f7bfdd36ef78d56d53c74e66ab278d318b71e6002a369d36f4873"
33
version: "0.13.1-4"
44

5-
cbuilder: {}
5+
cbuilder: {
6+
copy_to_builddir: true # modifies source
7+
}
68

79
# build dependencies:
810
dep: "autoconf"

0 commit comments

Comments
 (0)