1
0
mirror of https://github.com/golang/go synced 2024-11-26 03:37:57 -07:00

yet another attempt at auto-linking

store only the original import path string (+ .a)
if 6g resolves it to an archive file.
let 6l re-resolve the .a at link time.

this lets libraries build against an archive
in the current directory but get used
against an installed archive.

R=r
OCL=27244
CL=27244
This commit is contained in:
Russ Cox 2009-04-08 22:45:33 -07:00
parent 91a2ac1f1e
commit f95da9a639
6 changed files with 43 additions and 26 deletions

View File

@ -635,12 +635,13 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
void void
addlib(char *src, char *obj) addlib(char *src, char *obj)
{ {
char name[1024], comp[256], *p, *q; char name[1024], pname[1024], comp[256], *p, *q;
int i; int i, search;
if(histfrogp <= 0) if(histfrogp <= 0)
return; return;
search = 0;
if(histfrog[0]->name[1] == '/') { if(histfrog[0]->name[1] == '/') {
sprint(name, ""); sprint(name, "");
i = 1; i = 1;
@ -649,11 +650,9 @@ addlib(char *src, char *obj)
sprint(name, "."); sprint(name, ".");
i = 0; i = 0;
} else { } else {
if(debug['9']) sprint(name, "");
sprint(name, "/%s/lib", thestring);
else
sprint(name, "/usr/%clib", thechar);
i = 0; i = 0;
search = 1;
} }
for(; i<histfrogp; i++) { for(; i<histfrogp; i++) {
@ -683,6 +682,15 @@ addlib(char *src, char *obj)
strcat(name, "/"); strcat(name, "/");
strcat(name, comp); strcat(name, comp);
} }
if(search) {
// try dot and then try goroot.
// going to have to do better (probably a command line flag) later.
snprint(pname, sizeof pname, ".%s", name);
if(access(pname, AEXIST) < 0)
snprint(pname, sizeof pname, "%s/pkg/%s", goroot, name);
strcpy(name, pname);
}
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f addlib: %s %s pulls in %s\n", cputime(), obj, src, name); Bprint(&bso, "%5.2f addlib: %s %s pulls in %s\n", cputime(), obj, src, name);

View File

@ -703,7 +703,7 @@ Sym* pkglookup(char*, char*);
void yyerror(char*, ...); void yyerror(char*, ...);
void warn(char*, ...); void warn(char*, ...);
void fatal(char*, ...); void fatal(char*, ...);
void linehist(char*, int32); void linehist(char*, int32, int);
int32 setlineno(Node*); int32 setlineno(Node*);
Node* nod(int, Node*, Node*); Node* nod(int, Node*, Node*);
Node* nodlit(Val); Node* nodlit(Val);

View File

@ -74,7 +74,7 @@ main(int argc, char *argv[])
setfilename(argv[0]); setfilename(argv[0]);
infile = argv[0]; infile = argv[0];
linehist(infile, 0); linehist(infile, 0, 0);
curio.infile = infile; curio.infile = infile;
curio.bin = Bopen(infile, OREAD); curio.bin = Bopen(infile, OREAD);
@ -103,7 +103,7 @@ main(int argc, char *argv[])
yyparse(); yyparse();
runifacechecks(); runifacechecks();
linehist(nil, 0); linehist(nil, 0, 0);
if(curio.bin != nil) if(curio.bin != nil)
Bterm(curio.bin); Bterm(curio.bin);
@ -254,7 +254,7 @@ void
importfile(Val *f) importfile(Val *f)
{ {
Biobuf *imp; Biobuf *imp;
char *file; char *file, *p;
int32 c; int32 c;
int len; int len;
@ -276,14 +276,21 @@ importfile(Val *f)
file = strdup(namebuf); file = strdup(namebuf);
len = strlen(namebuf); len = strlen(namebuf);
if(len > 2) if(len > 2 && namebuf[len-2] == '.' && namebuf[len-1] == 'a') {
if(namebuf[len-2] == '.')
if(namebuf[len-1] == 'a')
if(!skiptopkgdef(imp)) if(!skiptopkgdef(imp))
fatal("import not package file: %s", namebuf); fatal("import not package file: %s", namebuf);
linehist(file, 0); // assume .a files move (get installed)
linehist(file, -1); // acts as #pragma lib // so don't record the full path.
p = file + len - f->u.sval->len - 2;
linehist(p, 0, 0);
linehist(p, -1, 1); // acts as #pragma lib
} else {
// assume .6 files don't move around
// so do record the full path
linehist(file, 0, 0);
linehist(file, -1, 0);
}
/* /*
* position the input right * position the input right
@ -314,7 +321,7 @@ importfile(Val *f)
void void
unimportfile(void) unimportfile(void)
{ {
linehist(nil, 0); linehist(nil, 0, 0);
if(curio.bin != nil) { if(curio.bin != nil) {
Bterm(curio.bin); Bterm(curio.bin);
@ -330,7 +337,7 @@ void
cannedimports(char *file, char *cp) cannedimports(char *file, char *cp)
{ {
lineno++; // if sys.6 is included on line 1, lineno++; // if sys.6 is included on line 1,
linehist(file, 0); // the debugger gets confused linehist(file, 0, 0); // the debugger gets confused
pushedio = curio; pushedio = curio;
curio.bin = nil; curio.bin = nil;

View File

@ -63,7 +63,7 @@ fatal(char *fmt, ...)
} }
void void
linehist(char *file, int32 off) linehist(char *file, int32 off, int relative)
{ {
Hist *h; Hist *h;
char *cp; char *cp;
@ -78,7 +78,7 @@ linehist(char *file, int32 off)
print("end of import at line %L\n", lineno); print("end of import at line %L\n", lineno);
} }
if(off < 0 && file[0] != '/') { if(off < 0 && file[0] != '/' && !relative) {
cp = mal(strlen(file) + strlen(pathname) + 2); cp = mal(strlen(file) + strlen(pathname) + 2);
sprint(cp, "%s/%s", pathname, file); sprint(cp, "%s/%s", pathname, file);
file = cp; file = cp;

View File

@ -3078,12 +3078,12 @@ colas(Node *nl, Node *nr)
convlit(nr->left, types[TFUNC]); convlit(nr->left, types[TFUNC]);
t = nr->left->type; t = nr->left->type;
if(t == T) if(t == T)
return; // error already printed return nl; // error already printed
if(t->etype == tptr) if(t->etype == tptr)
t = t->type; t = t->type;
if(t == T || t->etype != TFUNC) { if(t == T || t->etype != TFUNC) {
yyerror("cannot call %T", t); yyerror("cannot call %T", t);
return; return nl;
} }
if(t->outtuple != cl) { if(t->outtuple != cl) {
cr = t->outtuple; cr = t->outtuple;

View File

@ -68,7 +68,9 @@ test.files: $(addsuffix .test, $(TEST))
rm -f $*.6 rm -f $*.6
%.install: %.6 %.install: %.6
mv $*.6 $(GOROOT)/pkg/$*.6 6ar grc $*.a $*.6
mv $*.a $(GOROOT)/pkg/$*.a
rm -f $*.6
%.dirclean: %.dirclean:
+cd $* && make clean +cd $* && make clean
@ -95,7 +97,7 @@ test: test.files
bignum.6: fmt.dirinstall bignum.6: fmt.dirinstall
bufio.6: io.dirinstall os.dirinstall bufio.6: io.dirinstall os.dirinstall
exec.6: os.dirinstall exec.6: os.dirinstall strings.install
flag.6: fmt.dirinstall os.dirinstall strconv.dirinstall flag.6: fmt.dirinstall os.dirinstall strconv.dirinstall
log.6: fmt.dirinstall io.dirinstall os.dirinstall time.dirinstall log.6: fmt.dirinstall io.dirinstall os.dirinstall time.dirinstall
path.6: io.dirinstall path.6: io.dirinstall