From 6af069f3e1b64b89cd3f77b486af3d15cc8a4d8c Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Wed, 4 Apr 2012 00:03:42 +0800 Subject: [PATCH] 5a, 6a, 8a: take GOROOT_FINAL into consideration R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5940052 --- src/cmd/5a/lex.c | 33 ++++++++++++++++++++++++++++++++- src/cmd/6a/lex.c | 32 ++++++++++++++++++++++++++++++++ src/cmd/8a/lex.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/cmd/5a/lex.c b/src/cmd/5a/lex.c index 4bef0219a2..ff69069c8d 100644 --- a/src/cmd/5a/lex.c +++ b/src/cmd/5a/lex.c @@ -641,11 +641,37 @@ outhist(void) Hist *h; char *p, *q, *op, c; int n; - + char *tofree; + static int first = 1; + static char *goroot, *goroot_final; + + if(first) { + // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL. + first = 0; + goroot = getenv("GOROOT"); + goroot_final = getenv("GOROOT_FINAL"); + if(goroot == nil) + goroot = ""; + if(goroot_final == nil) + goroot_final = goroot; + if(strcmp(goroot, goroot_final) == 0) { + goroot = nil; + goroot_final = nil; + } + } + + tofree = nil; g = nullgen; c = '/'; for(h = hist; h != H; h = h->link) { p = h->name; + if(p != nil && goroot != nil) { + n = strlen(goroot); + if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') { + tofree = smprint("%s%s", goroot_final, p+n); + p = tofree; + } + } op = 0; if(systemtype(Windows) && p && p[1] == ':'){ c = p[2]; @@ -697,6 +723,11 @@ outhist(void) Bputc(&obuf, h->line>>24); zaddr(&nullgen, 0); zaddr(&g, 0); + + if(tofree) { + free(tofree); + tofree = nil; + } } } diff --git a/src/cmd/6a/lex.c b/src/cmd/6a/lex.c index e013bec2a7..275bcfe1a3 100644 --- a/src/cmd/6a/lex.c +++ b/src/cmd/6a/lex.c @@ -1250,11 +1250,38 @@ outhist(void) Hist *h; char *p, *q, *op, c; int n; + char *tofree; + static int first = 1; + static char *goroot, *goroot_final; + + if(first) { + // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL. + first = 0; + goroot = getenv("GOROOT"); + goroot_final = getenv("GOROOT_FINAL"); + if(goroot == nil) + goroot = ""; + if(goroot_final == nil) + goroot_final = goroot; + if(strcmp(goroot, goroot_final) == 0) { + goroot = nil; + goroot_final = nil; + } + } + + tofree = nil; g = nullgen; c = pathchar(); for(h = hist; h != H; h = h->link) { p = h->name; + if(p != nil && goroot != nil) { + n = strlen(goroot); + if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') { + tofree = smprint("%s%s", goroot_final, p+n); + p = tofree; + } + } op = 0; if(systemtype(Windows) && p && p[1] == ':'){ c = p[2]; @@ -1306,6 +1333,11 @@ outhist(void) Bputc(&obuf, h->line>>24); zaddr(&nullgen, 0); zaddr(&g, 0); + + if(tofree) { + free(tofree); + tofree = nil; + } } } diff --git a/src/cmd/8a/lex.c b/src/cmd/8a/lex.c index 1cc6e591dd..c54e4fe462 100644 --- a/src/cmd/8a/lex.c +++ b/src/cmd/8a/lex.c @@ -915,11 +915,38 @@ outhist(void) Hist *h; char *p, *q, *op, c; int n; + char *tofree; + static int first = 1; + static char *goroot, *goroot_final; + + if(first) { + // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL. + first = 0; + goroot = getenv("GOROOT"); + goroot_final = getenv("GOROOT_FINAL"); + if(goroot == nil) + goroot = ""; + if(goroot_final == nil) + goroot_final = goroot; + if(strcmp(goroot, goroot_final) == 0) { + goroot = nil; + goroot_final = nil; + } + } + + tofree = nil; g = nullgen; c = pathchar(); for(h = hist; h != H; h = h->link) { p = h->name; + if(p != nil && goroot != nil) { + n = strlen(goroot); + if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') { + tofree = smprint("%s%s", goroot_final, p+n); + p = tofree; + } + } op = 0; if(systemtype(Windows) && p && p[1] == ':'){ c = p[2]; @@ -971,6 +998,11 @@ outhist(void) Bputc(&obuf, h->line>>24); zaddr(&nullgen, 0); zaddr(&g, 0); + + if(tofree) { + free(tofree); + tofree = nil; + } } }