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

src/cmd/5c/swt.c
src/cmd/6c/swt.c
src/cmd/8c/swt.c

index 7268f9af26726ddf5ccaaccfec69c61af0e31eca..f8fbb13545c4c6cbb208a12a1d639965b93447dd 100644 (file)
@@ -472,12 +472,38 @@ outhist(Biobuf *b)
        char *p, *q, *op, c;
        Prog pg;
        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;
        pg = zprog;
        pg.as = AHISTORY;
        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];
@@ -525,6 +551,11 @@ outhist(Biobuf *b)
                        pg.to.type = D_CONST;
 
                zwrite(b, &pg, 0, 0);
+
+               if(tofree) {
+                       free(tofree);
+                       tofree = nil;
+               }
        }
 }
 
index f16d0f78a215533410a834a55bae468648955800..272cce2595bdcd9d2cf61089b85c7a70d14b13a7 100644 (file)
@@ -339,12 +339,38 @@ outhist(Biobuf *b)
        char *p, *q, *op, c;
        Prog pg;
        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;
        pg = zprog;
        pg.as = AHISTORY;
        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];
@@ -400,6 +426,11 @@ outhist(Biobuf *b)
                Bputc(b, pg.lineno>>24);
                zaddr(b, &pg.from, 0);
                zaddr(b, &pg.to, 0);
+
+               if(tofree) {
+                       free(tofree);
+                       tofree = nil;
+               }
        }
 }
 
index f1ca4c25fa8b59c69a278de5509f9a9985c94ac8..5a6f22e0bab4763b1b7c680c03c64a484870b36b 100644 (file)
@@ -343,12 +343,38 @@ outhist(Biobuf *b)
        char *p, *q, *op, c;
        Prog pg;
        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;
        pg = zprog;
        pg.as = AHISTORY;
        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];
@@ -404,6 +430,11 @@ outhist(Biobuf *b)
                Bputc(b, pg.lineno>>24);
                zaddr(b, &pg.from, 0);
                zaddr(b, &pg.to, 0);
+
+               if(tofree) {
+                       free(tofree);
+                       tofree = nil;
+               }
        }
 }