]> Cypherpunks repositories - gostls13.git/commitdiff
5a, 6a, 8a: take GOROOT_FINAL into consideration
authorShenghou Ma <minux.ma@gmail.com>
Tue, 3 Apr 2012 16:03:42 +0000 (00:03 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 3 Apr 2012 16:03:42 +0000 (00:03 +0800)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5940052

src/cmd/5a/lex.c
src/cmd/6a/lex.c
src/cmd/8a/lex.c

index 4bef0219a2c5726caeb1f640eedba257a5e4142b..ff69069c8d87799939cbfd69398a81a357dffe31 100644 (file)
@@ -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;
+               }
        }
 }
 
index e013bec2a7dbc58c37108fc4389a4267678b7264..275bcfe1a3c3b822a8bc9760cad546802f6c609c 100644 (file)
@@ -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;
+               }
        }
 }
 
index 1cc6e591dd010d1236a7ba7ce8282b520d74d2e7..c54e4fe4625d6ed332fe95dd0672a03a2da95aa3 100644 (file)
@@ -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;
+               }
        }
 }