diff --git a/cmd/seb/main.go b/cmd/seb/main.go index c7fb584..fa24f72 100644 --- a/cmd/seb/main.go +++ b/cmd/seb/main.go @@ -55,8 +55,7 @@ var ( func main() { ops := buildbuild.NewGlobalOps() - // Disable BuildPlugin for now, it's too buggy on 1.8beta1 - //ops.BuildPlugin = BuildPlugin + ops.BuildPlugin = BuildPlugin flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [options] [--] []\n", os.Args[0]) flag.PrintDefaults() diff --git a/cmd/seb/plugin_dso.go b/cmd/seb/plugin_dso.go index 4a70f77..4c6d268 100644 --- a/cmd/seb/plugin_dso.go +++ b/cmd/seb/plugin_dso.go @@ -1,6 +1,4 @@ -// Copyright 2018 Schibsted - -//+build go1.8 +// Copyright 2019 Schibsted package main @@ -10,10 +8,14 @@ import ( "path" "path/filepath" "plugin" + "strings" "github.com/schibsted/sebuild/pkg/buildbuild" ) +// BuildPlugin compiles a sebuild plugin in the given directory. +// This function is in the main package primarily because early in the +// plugin support it didn't work to load plugins from non-main packages. func BuildPlugin(ops *buildbuild.GlobalOps, ppath string) error { binpath := path.Join(ops.Config.Buildpath, "obj/_plugins", ppath+".so") @@ -26,12 +28,29 @@ func BuildPlugin(ops *buildbuild.GlobalOps, ppath string) error { if err != nil { return err } - tmpdir := ops.TempDirWithPlugins([]string{ppath}) - defer os.RemoveAll(tmpdir) + cmd := exec.Command("go", "build", "-buildmode=plugin", "-o", binabs) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Dir = tmpdir + cmd.Dir = ppath + + cmd.Env = os.Environ() + for idx, str := range cmd.Env { + // Workaround weird go invocation of CC, it just picks the first word, ignoring others. + // Assume the last word not starting with - is the one we want + if strings.HasPrefix(str, "CC=") { + args := strings.Split(str[3:], " ") + var i int + for i = len(args) - 1; i > 0; i-- { + if len(args[i]) > 0 && args[i][0] != '-' { + break + } + } + cmd.Env[idx] = "CC=" + strings.Join(args[i:], " ") + break + } + } + err = cmd.Run() if err != nil { return err diff --git a/cmd/seb/plugin_nodso.go b/cmd/seb/plugin_nodso.go deleted file mode 100644 index 7119eb2..0000000 --- a/cmd/seb/plugin_nodso.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2018 Schibsted - -//+build !go1.8 - -package main - -import "github.com/schibsted/sebuild/pkg/buildbuild" - -func BuildPlugin(ops *buildbuild.GlobalOps, ppath string) error { - // Return nil is ok since the plugin still won't be found in the parent code. - return nil -} diff --git a/internal/tools/gobuild.sh b/internal/tools/gobuild.sh index 82e209a..05412d8 100755 --- a/internal/tools/gobuild.sh +++ b/internal/tools/gobuild.sh @@ -69,6 +69,13 @@ IFS="$orig_IFS" # Strip initial : GOPATH="${gopath:1}" +# If we have an explicit GOPATH then disable go modules. +# Probably will want to drop support for GOPATH quite soon, but that should be +# a major release so it will have to wait for that. +if [ -n "$GOPATH" ]; then + export GO111MODULE=off +fi + if [ -z "$mode" ]; then mode="prog" fi @@ -82,9 +89,6 @@ if [ "$mode" = "bench" ]; then exec go test $GOBUILD_FLAGS $GOBUILD_TEST_FLAGS $PKG -bench $4 fi if [ "$mode" = "cover_html" ]; then - # If we have a GOPATH then disable go modules or go 1.11 might fail - # to find the package due to assuming it to on based on $PWD. - [ -n "$GOPATH" ] && export GO111MODULE=off exec go tool cover -html=$IN -o "$OUT" fi diff --git a/pkg/buildbuild/config.go b/pkg/buildbuild/config.go index e2bb38d..5bfd884 100644 --- a/pkg/buildbuild/config.go +++ b/pkg/buildbuild/config.go @@ -308,12 +308,7 @@ func (ops *GlobalOps) StartupPlugins(srcdir string, s *Scanner, flavors []string } } if len(missingPlugins) > 0 { - ops.MaybeReExec() - if !ops.Options.Quiet { - fmt.Fprintf(os.Stderr, "Plugins not compiled: %s\n", strings.Join(missingPlugins, " ")) - } - ops.RecompileWithPlugins() - ops.ReExec() + panic("Failed to load plugins: " + strings.Join(missingPlugins, ", ")) } return ops.ParseDescriptorEnd diff --git a/pkg/buildbuild/globalops.go b/pkg/buildbuild/globalops.go index b864dab..d671934 100644 --- a/pkg/buildbuild/globalops.go +++ b/pkg/buildbuild/globalops.go @@ -8,10 +8,8 @@ package buildbuild import ( "log" "os" - "os/exec" "path/filepath" "strings" - "syscall" ) // Global build configuration. @@ -164,17 +162,6 @@ func (ops *GlobalOps) RegisterGlob(srcdir, src string) { } } -func (ops *GlobalOps) ReExec() { - if _, ok := os.LookupEnv("BUILDTOOLDIR"); !ok { - btp := BuildtoolDir() - os.Setenv("BUILDTOOLDIR", btp) - } - binpath := filepath.Join(ops.Config.Buildpath, "obj", "_build_build") - if err := syscall.Exec(binpath, os.Args, syscall.Environ()); err != nil { - panic(err) - } -} - type PluginDep struct { ppath string os.FileInfo @@ -217,46 +204,6 @@ func (ops *GlobalOps) PluginDeps() (deps []PluginDep) { return } -func (ops *GlobalOps) MaybeReExec() { - binpath := filepath.Join(ops.Config.Buildpath, "obj", "_build_build") - if binpath == os.Args[0] { - return - } - theirinfo, err := os.Stat(binpath) - if err != nil { - // If they don't exist then we proceed ourselves. - return - } - me, err := exec.LookPath(os.Args[0]) - if err != nil { - var tmp error - me, tmp = filepath.EvalSymlinks("/proc/self/exe") - if tmp != nil { - // Return the original error, /proc/self is just a fallback. - panic(err) - } - } - if me == binpath { - return - } - myinfo, err := os.Stat(me) - if err != nil { - panic(err) - } - if !theirinfo.ModTime().After(myinfo.ModTime()) { - // If we're newer than them, then we can't trust them to be up to date. - return - } - // Check plugins as well. - deps := ops.PluginDeps() - for _, pi := range deps { - if !theirinfo.ModTime().After(pi.ModTime()) { - return - } - } - ops.ReExec() -} - func NormalizePath(basedir, p string) string { if !strings.HasPrefix(p, ".") { return p diff --git a/test/exts/ext.go b/test/exts/ext.go index 8b22c97..d7d34a6 100644 --- a/test/exts/ext.go +++ b/test/exts/ext.go @@ -1,6 +1,6 @@ // Copyright 2018 Schibsted -package exts +package main import ( "strings"