diff mbox

libgo patch committed: Add Go tool sources

Message ID CAOyqgcXubPA4DqMs+S_Kw-u8LCbHw0inkCUkC83520ZwNP-+2g@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 6, 2015, 11:26 p.m. UTC
I've committed a patch to libgo to add the sources for three standard
Go tools: go, cgo, and gofmt.  The go tool is used by most Go
programmers to build, test, and install Go programs, as well as to
fetch Go code from the Internet.  It more or less replaces make.  The
cgo tool is invoked by the go tool, and supports calling back and
forth between Go and C.  The gofmt tool formats Go code in a standard
way.  These tools all have full support for gccgo already.

This patch was originally prepared by Lynn A. Boger before I made some changes.

As yet nothing builds these tools.  It doesn't make sense to build
them as part of libgo, because they logically need to be built for the
host, not the target.  I'm thinking that we will add something like
gnattools, a top-level directory that builds code that lives
elsewhere.

I haven't included a complete patch because it is slightly too large.
Most of the files are exact copies of the same files in the external
gc tree.  They have been changed for better support as part of the
gccgo tree; I've attached a file of those changes.  I've also attached
a file of the patches to files already present in libgo to support
these changes.

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

diff -r e69aeba5ad07 libgo/Makefile.am
--- a/libgo/Makefile.am	Mon Jan 05 18:26:01 2015 -0800
+++ b/libgo/Makefile.am	Tue Jan 06 15:11:39 2015 -0800
@@ -26,6 +26,7 @@
 toolexecdir = $(glibgo_toolexecdir)
 toolexeclibdir = $(glibgo_toolexeclibdir)
 toolexeclibgodir = $(nover_glibgo_toolexeclibdir)/go/$(gcc_version)/$(target_alias)
+libexecsubdir = $(libexecdir)/gcc/$(target_alias)/$(gcc_version)
 
 LIBFFI = @LIBFFI@
 LIBFFIINCS = @LIBFFIINCS@
@@ -1007,6 +1008,7 @@
 	echo 'const theVersion = "'`$(GOC) --version | sed 1q`'"' >> version.go.tmp
 	echo 'const theGoarch = "'$(GOARCH)'"' >> version.go.tmp
 	echo 'const theGoos = "'$(GOOS)'"' >> version.go.tmp
+	echo 'const theGccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
 	$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
 	$(STAMP) $@
 
diff -r e69aeba5ad07 libgo/go/go/build/build.go
--- a/libgo/go/go/build/build.go	Mon Jan 05 18:26:01 2015 -0800
+++ b/libgo/go/go/build/build.go	Tue Jan 06 15:11:39 2015 -0800
@@ -268,6 +268,8 @@
 	"linux/386":       true,
 	"linux/amd64":     true,
 	"linux/arm":       true,
+	"linux/ppc64":     true,
+	"linux/ppc64le":   true,
 	"linux/s390":      true,
 	"linux/s390x":     true,
 	"netbsd/386":      true,
@@ -1196,8 +1198,15 @@
 	}
 }
 
-// ToolDir is the directory containing build tools.
-var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+func getToolDir() string {
+	if runtime.Compiler == "gccgo" {
+		return runtime.GCCGOTOOLDIR
+	} else {
+		return filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+	}
+}
+
+var ToolDir = getToolDir()
 
 // IsLocalImport reports whether the import path is
 // a local import path, like ".", "..", "./foo", or "../foo".
@@ -1218,6 +1227,8 @@
 		return "5", nil
 	case "arm64":
 		return "7", nil
+	case "ppc64", "ppc64le":
+		return "9", nil
 	}
 	return "", errors.New("unsupported GOARCH " + goarch)
 }
diff -r e69aeba5ad07 libgo/merge.sh
--- a/libgo/merge.sh	Mon Jan 05 18:26:01 2015 -0800
+++ b/libgo/merge.sh	Tue Jan 06 15:11:39 2015 -0800
@@ -163,6 +163,36 @@
   done
 done
 
+cmdlist="cgo go gofmt"
+for c in $cmdlist; do
+  (cd ${NEWDIR}/src/cmd/$c && find . -name '*.go' -print) | while read f; do
+    oldfile=${OLDDIR}/src/cmd/$c/$f
+    newfile=${NEWDIR}/src/cmd/$c/$f
+    libgofile=go/cmd/$c/$f
+    merge $f ${oldfile} ${newfile} ${libgofile}
+  done
+
+  (cd ${NEWDIR}/src/cmd/$c && find . -name testdata -print) | while read d; do
+    oldtd=${OLDDIR}/src/cmd/$c/$d
+    newtd=${NEWDIR}/src/cmd/$c/$d
+    libgotd=go/cmd/$c/$d
+    if ! test -d ${oldtd}; then
+      continue
+    fi
+    (cd ${oldtd} && hg status -A .) | while read f; do
+      if test "`basename $f`" = ".hgignore"; then
+        continue
+      fi
+      f=`echo $f | sed -e 's/^..//'`
+      name=$d/$f
+      oldfile=${oldtd}/$f
+      newfile=${newtd}/$f
+      libgofile=${libgotd}/$f
+      merge ${name} ${oldfile} ${newfile} ${libgofile}
+    done
+  done
+done
+
 runtime="chan.goc chan.h cpuprof.goc env_posix.c heapdump.c lock_futex.c lfstack.goc lock_sema.c mcache.c mcentral.c mfixalloc.c mgc0.c mgc0.h mheap.c msize.c netpoll.goc netpoll_epoll.c netpoll_kqueue.c netpoll_stub.c panic.c print.c proc.c race.h rdebug.goc runtime.c runtime.h signal_unix.c signal_unix.h malloc.h malloc.goc mprof.goc parfor.c runtime1.goc sema.goc sigqueue.goc string.goc time.goc"
 for f in $runtime; do
   merge_c $f $f
diff mbox

Patch

diff -ur /home/iant/go1.3/src/cmd/go/build.go libgo/go/cmd/go/build.go
--- /home/iant/go1.3/src/cmd/go/build.go	2014-08-12 14:07:43.297932194 -0700
+++ libgo/go/cmd/go/build.go	2014-12-23 16:06:09.768565224 -0800
@@ -131,6 +131,7 @@ 
 var buildGccgoflags []string // -gccgoflags flag
 var buildRace bool           // -race flag
 
+var reqPkgSrc bool           // req src for Imports
 var buildContext = build.Default
 var buildToolchain toolchain = noToolchain{}
 
@@ -183,6 +184,12 @@ 
 	cmd.Flag.Var((*stringsFlag)(&buildContext.BuildTags), "tags", "")
 	cmd.Flag.Var(buildCompiler{}, "compiler", "")
 	cmd.Flag.BoolVar(&buildRace, "race", false, "")
+	switch build.Default.Compiler {
+	case "gc":
+		reqPkgSrc = true
+	case "gccgo":
+		reqPkgSrc = false
+	}
 }
 
 func addBuildFlagsNX(cmd *Command) {
@@ -562,15 +569,18 @@ 
 	// using cgo, to make sure we do not overwrite the binary while
 	// a package is using it.  If this is a cross-build, then the cgo we
 	// are writing is not the cgo we need to use.
+
 	if goos == runtime.GOOS && goarch == runtime.GOARCH && !buildRace {
-		if len(p.CgoFiles) > 0 || p.Standard && p.ImportPath == "runtime/cgo" {
-			var stk importStack
-			p1 := loadPackage("cmd/cgo", &stk)
-			if p1.Error != nil {
-				fatalf("load cmd/cgo: %v", p1.Error)
+		if reqPkgSrc {
+			if len(p.CgoFiles) > 0 || p.Standard && p.ImportPath == "runtime/cgo" {
+				var stk importStack
+				p1 := loadPackage("cmd/cgo", &stk)
+				if p1.Error != nil {
+					fatalf("load cmd/cgo: %v", p1.Error)
+				}
+				a.cgo = b.action(depMode, depMode, p1)
+				a.deps = append(a.deps, a.cgo)
 			}
-			a.cgo = b.action(depMode, depMode, p1)
-			a.deps = append(a.deps, a.cgo)
 		}
 	}
 
diff -ur /home/iant/go1.3/src/cmd/go/pkg.go libgo/go/cmd/go/pkg.go
--- /home/iant/go1.3/src/cmd/go/pkg.go	2014-08-12 14:07:43.301932155 -0700
+++ libgo/go/cmd/go/pkg.go	2014-12-23 16:06:09.772565214 -0800
@@ -488,6 +488,9 @@ 
 			continue
 		}
 		p1 := loadImport(path, p.Dir, stk, p.build.ImportPos[path])
+		if !reqPkgSrc && p1.Root == "" {
+			continue
+		}
 		if p1.local {
 			if !p.local && p.Error == nil {
 				p.Error = &PackageError{
diff -ur /home/iant/go1.3/src/cmd/go/test.go libgo/go/cmd/go/test.go
--- /home/iant/go1.3/src/cmd/go/test.go	2014-08-12 14:07:43.301932155 -0700
+++ libgo/go/cmd/go/test.go	2014-12-23 16:06:09.772565214 -0800
@@ -371,9 +371,11 @@ 
 		delete(deps, "unsafe")
 
 		all := []string{}
-		for path := range deps {
-			if !build.IsLocalImport(path) {
-				all = append(all, path)
+		if reqPkgSrc {
+			for path := range deps {
+				if !build.IsLocalImport(path) {
+					all = append(all, path)
+				}
 			}
 		}
 		sort.Strings(all)
@@ -541,6 +543,9 @@ 
 	stk.push(p.ImportPath + " (test)")
 	for _, path := range p.TestImports {
 		p1 := loadImport(path, p.Dir, &stk, p.build.TestImportPos[path])
+		if !reqPkgSrc && p1.Root == "" {
+			continue
+		}
 		if p1.Error != nil {
 			return nil, nil, nil, p1.Error
 		}
@@ -566,6 +571,9 @@ 
 			continue
 		}
 		p1 := loadImport(path, p.Dir, &stk, p.build.XTestImportPos[path])
+		if !reqPkgSrc && p1.Root == "" {
+			continue
+		}
 		if p1.Error != nil {
 			return nil, nil, nil, p1.Error
 		}
@@ -694,6 +702,9 @@ 
 			pmain.imports = append(pmain.imports, ptest)
 		} else {
 			p1 := loadImport(dep, "", &stk, nil)
+			if !reqPkgSrc && p1.Root == "" {
+				continue
+			}
 			if p1.Error != nil {
 				return nil, nil, nil, p1.Error
 			}
Only in /home/iant/go1.3/src/cmd/go: zdefaultcc.go
diff -ur /home/iant/go1.3/src/cmd/cgo/main.go libgo/go/cmd/cgo/main.go
--- /home/iant/go1.3/src/cmd/cgo/main.go	2014-08-12 14:06:39.782556016 -0700
+++ libgo/go/cmd/cgo/main.go	2014-12-23 16:06:09.768565224 -0800
@@ -133,12 +133,18 @@ 
 	"386":   4,
 	"amd64": 8,
 	"arm":   4,
+	"ppc64": 8,
+	"ppc64le": 8,
+	"s390x": 8,
 }
 
 var intSizeMap = map[string]int64{
 	"386":   4,
 	"amd64": 8,
 	"arm":   4,
+	"ppc64": 8,
+	"ppc64le": 8,
+	"s390x": 8,
 }
 
 var cPrefix string