Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Become a Go module (fixes #5148) #5384

Merged
merged 6 commits into from Dec 18, 2018
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -23,3 +23,4 @@ parts/
stage/
*.snap
*.bz2
/repos
160 changes: 26 additions & 134 deletions build.go
Expand Up @@ -42,7 +42,6 @@ var (
goVersion float64
race bool
debug = os.Getenv("BUILDDEBUG") != ""
noBuildGopath bool
extraTags string
installSuffix string
pkgdir string
Expand Down Expand Up @@ -188,6 +187,19 @@ var targets = map[string]target{
},
}

// These are repos we need to clone to run "go generate"

type dependencyRepo struct {
path string
repo string
commit string
}

var dependencyRepos = []dependencyRepo{
{path: "protobuf", repo: "https://github.com/gogo/protobuf.git", commit: "v1.0.0"},
{path: "xdr", repo: "https://github.com/calmh/xdr.git", commit: "08e072f9cb16"},
}

func init() {
// The "syncthing" target includes a few more files found in the "etc"
// and "extra" dirs.
Expand Down Expand Up @@ -216,39 +228,6 @@ func main() {
}()
}

if gopath := gopath(); gopath == "" {
gopath, err := temporaryBuildDir()
if err != nil {
log.Fatal(err)
}
os.Setenv("GOPATH", gopath)
log.Println("GOPATH is", gopath)
if !noBuildGopath {
if err := buildGOPATH(gopath); err != nil {
log.Fatal(err)
}
lazyRebuildAssets()
}
} else {
inside := false
wd, _ := os.Getwd()
wd, _ = filepath.EvalSymlinks(wd)
for _, p := range filepath.SplitList(gopath) {
p, _ = filepath.EvalSymlinks(p)
if filepath.Join(p, "src/github.com/syncthing/syncthing") == wd {
inside = true
break
}
}
if !inside {
fmt.Println("You seem to have GOPATH set but the Syncthing source not placed correctly within it, which may cause problems.")
}
}

// Set path to $GOPATH/bin:$PATH so that we can for sure find tools we
// might have installed during "build.go setup".
os.Setenv("PATH", fmt.Sprintf("%s%cbin%c%s", os.Getenv("GOPATH"), os.PathSeparator, os.PathListSeparator, os.Getenv("PATH")))

// Invoking build.go with no parameters at all builds everything (incrementally),
// which is what you want for maximum error checking during development.
if flag.NArg() == 0 {
Expand Down Expand Up @@ -322,9 +301,6 @@ func runCommand(cmd string, target target) {
case "snap":
buildSnap(target)

case "clean":
clean()

case "vet":
metalintShort()

Expand All @@ -337,13 +313,6 @@ func runCommand(cmd string, target target) {
case "version":
fmt.Println(getVersion())

case "gopath":
gopath, err := temporaryBuildDir()
if err != nil {
log.Fatal(err)
}
fmt.Println(gopath)

default:
log.Fatalf("Unknown command %q", cmd)
}
Expand All @@ -355,7 +324,6 @@ func parseFlags() {
flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality")
flag.StringVar(&version, "version", getVersion(), "Set compiled in version string")
flag.BoolVar(&race, "race", race, "Use race detector")
flag.BoolVar(&noBuildGopath, "no-build-gopath", noBuildGopath, "Don't build GOPATH, assume it's OK")
flag.StringVar(&extraTags, "tags", extraTags, "Extra tags, space separated")
flag.StringVar(&installSuffix, "installsuffix", installSuffix, "Install suffix, optional")
flag.StringVar(&pkgdir, "pkgdir", "", "Set -pkgdir parameter for `go build`")
Expand Down Expand Up @@ -787,6 +755,14 @@ func shouldRebuildAssets(target, srcdir string) bool {
}

func proto() {
os.MkdirAll("repos", 0755)
for _, dep := range dependencyRepos {
path := filepath.Join("repos", dep.path)
if _, err := os.Stat(path); err != nil {
runPrintInDir("repos", "git", "clone", dep.repo, dep.path)
runPrintInDir(path, "git", "checkout", dep.commit)
}
}
runPrint("go", "generate", "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/stdiscosrv")
}

Expand All @@ -806,11 +782,6 @@ func transifex() {
runPrint("go", "run", "../../../../script/transifexdl.go")
}

func clean() {
rmr("bin")
rmr(filepath.Join(os.Getenv("GOPATH"), fmt.Sprintf("pkg/%s_%s/github.com/syncthing", goos, goarch)))
}

func ldflags() string {
sep := '='
if goVersion > 0 && goVersion < 1.5 {
Expand Down Expand Up @@ -1005,6 +976,10 @@ func runError(cmd string, args ...string) ([]byte, error) {
}

func runPrint(cmd string, args ...string) {
runPrintInDir(".", cmd, args...)
}

func runPrintInDir(dir string, cmd string, args ...string) {
if debug {
t0 := time.Now()
log.Println("runPrint:", cmd, strings.Join(args, " "))
Expand All @@ -1015,6 +990,7 @@ func runPrint(cmd string, args ...string) {
ecmd := exec.Command(cmd, args...)
ecmd.Stdout = os.Stdout
ecmd.Stderr = os.Stderr
ecmd.Dir = dir
err := ecmd.Run()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -1268,90 +1244,6 @@ func temporaryBuildDir() (string, error) {
return filepath.Join(tmpDir, base), nil
}

func buildGOPATH(gopath string) error {
pkg := filepath.Join(gopath, "src/github.com/syncthing/syncthing")
dirs := []string{"cmd", "gui", "lib", "meta", "script", "test", "vendor"}

if debug {
t0 := time.Now()
log.Println("build temporary GOPATH in", gopath)
defer func() {
log.Println("... in", time.Since(t0))
}()
}

// Walk the sources and copy the files into the temporary GOPATH.
// Remember which files are supposed to be present so we can clean
// out everything else in the next step. The copyFile() step will
// only actually copy the file if it doesn't exist or the contents
// differ.

exists := map[string]struct{}{}
for _, dir := range dirs {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}

dst := filepath.Join(pkg, path)
exists[dst] = struct{}{}

if err := copyFile(path, dst, info.Mode()); err != nil {
return err
}

return nil
})
if err != nil {
return err
}
}

// Walk the temporary GOPATH and remove any files that we wouldn't
// have copied there in the previous step.

filepath.Walk(pkg, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if _, ok := exists[path]; !ok {
os.Remove(path)
}
return nil
})

return nil
}

func gopath() string {
if gopath := os.Getenv("GOPATH"); gopath != "" {
// The env var is set, use that.
return gopath
}

// Ask Go what it thinks.
bs, err := runError("go", "env", "GOPATH")
if err != nil {
return ""
}

// We got something. Check if we are in fact available in that location.
gopath := string(bs)
if _, err := os.Stat(filepath.Join(gopath, "src/github.com/syncthing/syncthing/build.go")); err == nil {
// That seems to be the gopath.
return gopath
}

// The gopath is not valid.
return ""
}

func (t target) BinaryName() string {
if goos == "windows" {
return t.binaryName + ".exe"
Expand Down
2 changes: 1 addition & 1 deletion cmd/stdiscosrv/database.go
Expand Up @@ -5,7 +5,7 @@
// You can obtain one at https://mozilla.org/MPL/2.0/.

//go:generate go run ../../script/protofmt.go database.proto
//go:generate protoc -I ../../../../../ -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. database.proto
//go:generate protoc -I ../../ -I . --gogofast_out=. database.proto

package main

Expand Down
32 changes: 16 additions & 16 deletions cmd/stdiscosrv/database.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/stdiscosrv/database.proto
Expand Up @@ -8,7 +8,7 @@ syntax = "proto3";

package main;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "repos/protobuf/gogoproto/gogo.proto";

option (gogoproto.goproto_getters_all) = false;

Expand Down
52 changes: 52 additions & 0 deletions go.mod
@@ -0,0 +1,52 @@
module github.com/syncthing/syncthing

require (
github.com/AudriusButkevicius/cli v0.0.0-20140727204646-7f561c78b5a4
github.com/AudriusButkevicius/go-nat-pmp v0.0.0-20160522074932-452c97607362
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a // indirect
github.com/bkaradzic/go-lz4 v0.0.0-20160924222819-7224d8d8f27e
github.com/calmh/du v1.0.1
github.com/calmh/xdr v1.1.0
github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5
github.com/d4l3k/messagediff v1.2.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gobwas/glob v0.0.0-20170212200151-51eb1ee00b6d
github.com/gogo/protobuf v1.0.0
github.com/golang/groupcache v0.0.0-20171101203131-84a468cf14b4
github.com/golang/protobuf v0.0.0-20171113180720-1e59b77b52bf // indirect
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 // indirect
github.com/jackpal/gateway v0.0.0-20161225004348-5795ac81146e
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657
github.com/kr/pretty v0.1.0 // indirect
github.com/lib/pq v1.0.0
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/minio/sha256-simd v0.0.0-20171213220625-ad98a36ba0da
github.com/onsi/ginkgo v0.0.0-20171221013426-6c46eb8334b3 // indirect
github.com/onsi/gomega v0.0.0-20171227184521-ba3724c94e4d // indirect
github.com/oschwald/geoip2-golang v1.1.0
github.com/oschwald/maxminddb-golang v0.0.0-20170901134056-26fe5ace1c70 // indirect
github.com/petermattis/goid v0.0.0-20170816195418-3db12ebb2a59 // indirect
github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v0.9.0
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5 // indirect
github.com/prometheus/common v0.0.0-20171117163051-2e54d0b93cba // indirect
github.com/prometheus/procfs v0.0.0-20171226183907-b15cd069a834 // indirect
github.com/rcrowley/go-metrics v0.0.0-20171128170426-e181e095bae9
github.com/sasha-s/go-deadlock v0.2.0
github.com/stretchr/testify v1.2.2 // indirect
github.com/syncthing/notify v0.0.0-20181107104724-4e389ea6c0d8
github.com/syndtr/goleveldb v0.0.0-20171214120811-34011bf325bc
github.com/thejerf/suture v0.0.0-20180907184608-bf6ee6a0b047
github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0
golang.org/x/crypto v0.0.0-20171231215028-0fcca4842a8d
golang.org/x/net v0.0.0-20171212005608-d866cfc389ce
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 // indirect
golang.org/x/text v0.0.0-20171227012246-e19ae1496984
golang.org/x/time v0.0.0-20170927054726-6dc17368e09b
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/ldap.v2 v2.5.1
gopkg.in/yaml.v2 v2.0.0-20171116090243-287cf08546ab // indirect
)