Commit 54f1e1b1 authored by Gustavo Niemeyer's avatar Gustavo Niemeyer

cmd/dist: fix GOROOT_FINAL

R=rsc, gustavo
CC=golang-dev
https://golang.org/cl/5642045
parent eb02b9cf
...@@ -62,7 +62,6 @@ void splitlines(Vec*, char*); ...@@ -62,7 +62,6 @@ void splitlines(Vec*, char*);
void splitfields(Vec*, char*); void splitfields(Vec*, char*);
// build.c // build.c
extern char *default_goroot;
extern char *goarch; extern char *goarch;
extern char *gobin; extern char *gobin;
extern char *gochar; extern char *gochar;
...@@ -70,6 +69,7 @@ extern char *gohostarch; ...@@ -70,6 +69,7 @@ extern char *gohostarch;
extern char *gohostos; extern char *gohostos;
extern char *goos; extern char *goos;
extern char *goroot; extern char *goroot;
extern char *goroot_final;
extern char *goversion; extern char *goversion;
extern char *workdir; extern char *workdir;
extern char *slash; extern char *slash;
......
...@@ -15,13 +15,12 @@ char *gobin; ...@@ -15,13 +15,12 @@ char *gobin;
char *gohostarch; char *gohostarch;
char *gohostos; char *gohostos;
char *goos; char *goos;
char *goroot; char *goroot = GOROOT_FINAL;
char *goroot_final = GOROOT_FINAL;
char *workdir; char *workdir;
char *gochar; char *gochar;
char *goroot_final;
char *goversion; char *goversion;
char *slash; // / for unix, \ for windows char *slash; // / for unix, \ for windows
char *default_goroot = DEFAULT_GOROOT;
static bool shouldbuild(char*, char*); static bool shouldbuild(char*, char*);
static void copy(char*, char*); static void copy(char*, char*);
...@@ -74,11 +73,7 @@ init(void) ...@@ -74,11 +73,7 @@ init(void)
binit(&b); binit(&b);
xgetenv(&b, "GOROOT"); xgetenv(&b, "GOROOT");
if(b.len == 0) { if(b.len > 0)
if(default_goroot == nil)
fatal("$GOROOT not set and not available");
bwritestr(&b, default_goroot);
}
goroot = btake(&b); goroot = btake(&b);
xgetenv(&b, "GOBIN"); xgetenv(&b, "GOBIN");
...@@ -116,12 +111,6 @@ init(void) ...@@ -116,12 +111,6 @@ init(void)
bprintf(&b, "%c", gochars[i]); bprintf(&b, "%c", gochars[i]);
gochar = btake(&b); gochar = btake(&b);
xgetenv(&b, "GOROOT_FINAL");
if(b.len > 0)
goroot_final = btake(&b);
else
goroot_final = goroot;
xsetenv("GOROOT", goroot); xsetenv("GOROOT", goroot);
xsetenv("GOARCH", goarch); xsetenv("GOARCH", goarch);
xsetenv("GOOS", goos); xsetenv("GOOS", goos);
...@@ -777,7 +766,7 @@ install(char *dir) ...@@ -777,7 +766,7 @@ install(char *dir)
if(streq(name, "goos.c")) { if(streq(name, "goos.c")) {
vadd(&compile, bprintf(&b, "-DGOOS=\"%s\"", goos)); vadd(&compile, bprintf(&b, "-DGOOS=\"%s\"", goos));
vadd(&compile, bprintf(&b, "-DGOARCH=\"%s\"", goarch)); vadd(&compile, bprintf(&b, "-DGOARCH=\"%s\"", goarch));
bprintf(&b1, "%s", goroot); bprintf(&b1, "%s", goroot_final);
bsubst(&b1, "\\", "\\\\"); // turn into C string bsubst(&b1, "\\", "\\\\"); // turn into C string
vadd(&compile, bprintf(&b, "-DGOROOT=\"%s\"", bstr(&b1))); vadd(&compile, bprintf(&b, "-DGOROOT=\"%s\"", bstr(&b1)));
vadd(&compile, bprintf(&b, "-DGOVERSION=\"%s\"", goversion)); vadd(&compile, bprintf(&b, "-DGOVERSION=\"%s\"", goversion));
......
...@@ -29,7 +29,7 @@ mkzversion(char *dir, char *file) ...@@ -29,7 +29,7 @@ mkzversion(char *dir, char *file)
"package runtime\n" "package runtime\n"
"\n" "\n"
"const defaultGoroot = `%s`\n" "const defaultGoroot = `%s`\n"
"const theVersion = `%s`\n", goroot, goversion)); "const theVersion = `%s`\n", goroot_final, goversion));
writefile(&out, file); writefile(&out, file);
......
...@@ -47,7 +47,9 @@ done ...@@ -47,7 +47,9 @@ done
echo '# Building C bootstrap tool.' echo '# Building C bootstrap tool.'
mkdir -p ../bin/tool mkdir -p ../bin/tool
DEFGOROOT='-DDEFAULT_GOROOT="'"$(cd .. && pwd)"'"' export GOROOT="$(cd .. && pwd)"
GOROOT_FINAL="${GOROOT_FINAL:-$GOROOT}"
DEFGOROOT='-DGOROOT_FINAL="'"$GOROOT_FINAL"'"'
gcc -O2 -Wall -Werror -o ../bin/tool/dist -Icmd/dist "$DEFGOROOT" cmd/dist/*.c gcc -O2 -Wall -Werror -o ../bin/tool/dist -Icmd/dist "$DEFGOROOT" cmd/dist/*.c
echo echo
......
...@@ -10,14 +10,16 @@ echo Must run make.bat from Go src directory. ...@@ -10,14 +10,16 @@ echo Must run make.bat from Go src directory.
goto fail goto fail
:ok :ok
:: Grab default $GOROOT, escape \ for C string. :: Grab default GOROOT_FINAL and set GOROOT for build.
:: The expression %CD:\=\\% means to take %CD% :: The expression %VAR:\=\\% means to take %VAR%
:: and apply the substitution \ = \\, escaping the :: and apply the substitution \ = \\, escaping the
:: backslashes. Then we wrap that in quotes to create :: backslashes. Then we wrap that in quotes to create
:: a C string. :: a C string.
cd .. cd ..
set DEFGOROOT=-DDEFAULT_GOROOT="\"%CD:\=\\%\"" set GOROOT="%CD%"
cd src cd src
if "x%GOROOT_FINAL%"=="x" set GOROOT_FINAL="%GOROOT%"
set DEFGOROOT=-DGOROOT_FINAL="\"%GOROOT_FINAL:\=\\%\""
echo # Building C bootstrap tool. echo # Building C bootstrap tool.
if not exist ..\bin\tool mkdir ..\bin\tool if not exist ..\bin\tool mkdir ..\bin\tool
...@@ -40,7 +42,7 @@ if errorlevel 1 goto fail ...@@ -40,7 +42,7 @@ if errorlevel 1 goto fail
del ..\bin\tool\go_bootstrap.exe del ..\bin\tool\go_bootstrap.exe
echo . echo .
if x%1==x--no-banner goto nobanner if "x%1"=="x--no-banner" goto nobanner
..\bin\tool\dist banner ..\bin\tool\dist banner
:nobanner :nobanner
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment