aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-03-16 23:10:33 -0700
committerRuss Cox <rsc@golang.org>2010-03-16 23:10:33 -0700
commit0c3a93ceb7e2167104cdc4a34ed62e7d9e39ce8c (patch)
tree67f79cf7c459b780316ad0f7134fe0867492f0f3
parent5e6203d28b5106a445dd606ee25ca56f5460e12f (diff)
downloadgo-0c3a93ceb7e2167104cdc4a34ed62e7d9e39ce8c.tar.gz
go-0c3a93ceb7e2167104cdc4a34ed62e7d9e39ce8c.zip
runtime: add GOROOT and Version
R=r CC=golang-dev https://golang.org/cl/608041
-rw-r--r--.hgignore6
-rw-r--r--src/pkg/runtime/Makefile9
-rw-r--r--src/pkg/runtime/extern.go20
-rw-r--r--src/pkg/runtime/mkversion.c15
-rw-r--r--src/pkg/runtime/runtime.c9
5 files changed, 57 insertions, 2 deletions
diff --git a/.hgignore b/.hgignore
index 323c81e81d..0ac82faaa8 100644
--- a/.hgignore
+++ b/.hgignore
@@ -26,9 +26,13 @@ src/cmd/gc/yerr.h
src/pkg/Make.deps
src/pkg/exp/ogle/ogle
src/pkg/os/signal/unix.go
-src/pkg/runtime/cgo2c
src/pkg/runtime/*/asm.h
+src/pkg/runtime/cgo2c
+src/pkg/runtime/mkversion
src/pkg/runtime/runtime.acid.*
+src/pkg/runtime/version.go
+src/pkg/github.com/
+src/pkg/*.googlecode.com/
test/pass.out
test/run.out
test/times.out
diff --git a/src/pkg/runtime/Makefile b/src/pkg/runtime/Makefile
index bc8a2d8bfa..f44de25d41 100644
--- a/src/pkg/runtime/Makefile
+++ b/src/pkg/runtime/Makefile
@@ -23,6 +23,7 @@ CFLAGS=-I$(GOOS) -I$(GOOS)/$(GOARCH) -wF $(CFLAGS_$(SIZE)) $(CFLAGS_$(GOARCH)) $
GOFILES=\
extern.go\
type.go\
+ version.go\
GOFILES_pchw=\
pchw/io.go\
@@ -111,7 +112,7 @@ $(pkgdir)/%.h: %.h
clean: clean-local
clean-local:
- rm -f cgo2c */asm.h runtime.acid.*
+ rm -f cgo2c mkversion version.go */asm.h runtime.acid.*
$(GOARCH)/asm.h: mkasmh.sh runtime.acid.$(GOARCH)
./mkasmh.sh >$@.x
@@ -120,6 +121,12 @@ $(GOARCH)/asm.h: mkasmh.sh runtime.acid.$(GOARCH)
cgo2c: cgo2c.c
$(QUOTED_GOBIN)/quietgcc -o $@ $<
+mkversion: mkversion.c
+ $(QUOTED_GOBIN)/quietgcc -o $@ -I "$(GOROOT)/include" $< "$(GOROOT)/lib/lib9.a"
+
+version.go: mkversion
+ mkversion >version.go
+
%.c: %.cgo cgo2c
./cgo2c $< > $@.tmp
mv -f $@.tmp $@
diff --git a/src/pkg/runtime/extern.go b/src/pkg/runtime/extern.go
index f34bb2256c..b4d903c30c 100644
--- a/src/pkg/runtime/extern.go
+++ b/src/pkg/runtime/extern.go
@@ -150,3 +150,23 @@ func GC()
// TODO(rsc): allow f to have (ignored) return values
//
func SetFinalizer(x, f interface{})
+
+func getgoroot() string
+
+// GOROOT returns the root of the Go tree.
+// It uses the GOROOT environment variable, if set,
+// or else the root used during the Go build.
+func GOROOT() string {
+ s := getgoroot()
+ if s != "" {
+ return s
+ }
+ return defaultGoroot
+}
+
+// Version returns the Go tree's version string.
+// It is either a sequence number or, when possible,
+// a release tag like "release.2010-03-04".
+// A trailing + indicates that the tree had local modifications
+// at the time of the build.
+func Version() string { return defaultVersion }
diff --git a/src/pkg/runtime/mkversion.c b/src/pkg/runtime/mkversion.c
new file mode 100644
index 0000000000..bf33c0f85b
--- /dev/null
+++ b/src/pkg/runtime/mkversion.c
@@ -0,0 +1,15 @@
+#include <u.h>
+#include <libc.h>
+
+char *template =
+ "// generated by mkversion.c; do not edit.\n"
+ "package runtime\n"
+ "const defaultGoroot = \"%s\"\n"
+ "const defaultVersion = \"%s\"\n";
+
+void
+main(void)
+{
+ print(template, getgoroot(), getgoversion());
+ exits(0);
+}
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c
index 3a94c8bce2..ed1bdcab8a 100644
--- a/src/pkg/runtime/runtime.c
+++ b/src/pkg/runtime/runtime.c
@@ -206,6 +206,15 @@ getenv(int8 *s)
return nil;
}
+void
+·getgoroot(String out)
+{
+ byte *p;
+
+ p = getenv("GOROOT");
+ out = gostring(p);
+ FLUSH(&out);
+}
int32
atoi(byte *p)