Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Go 1.13 support #26

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/seb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] [--] [<ninja-args>]\n", os.Args[0])
flag.PrintDefaults()
Expand Down
31 changes: 25 additions & 6 deletions cmd/seb/plugin_dso.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright 2018 Schibsted

//+build go1.8
// Copyright 2019 Schibsted

package main

Expand All @@ -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")

Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions cmd/seb/plugin_nodso.go

This file was deleted.

10 changes: 7 additions & 3 deletions internal/tools/gobuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 1 addition & 6 deletions pkg/buildbuild/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 0 additions & 53 deletions pkg/buildbuild/globalops.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ package buildbuild
import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
)

// Global build configuration.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/exts/ext.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018 Schibsted

package exts
package main

import (
"strings"
Expand Down