1
0
mirror of https://github.com/golang/go synced 2024-11-25 02:17:57 -07:00

gopack: add S flag to force marking a package as safe

R=r
CC=golang-dev
https://golang.org/cl/1597044
This commit is contained in:
Russ Cox 2010-06-12 10:47:42 -07:00
parent db8c2b1803
commit 9d72aaabda
2 changed files with 16 additions and 4 deletions

View File

@ -109,7 +109,7 @@ typedef struct Hashchain
/* constants and flags */ /* constants and flags */
char *man = "mrxtdpq"; char *man = "mrxtdpq";
char *opt = "uvnbailo"; char *opt = "uvnbailoS";
char artemp[] = "/tmp/vXXXXX"; char artemp[] = "/tmp/vXXXXX";
char movtemp[] = "/tmp/v1XXXXX"; char movtemp[] = "/tmp/v1XXXXX";
char tailtemp[] = "/tmp/v2XXXXX"; char tailtemp[] = "/tmp/v2XXXXX";
@ -123,6 +123,7 @@ int gflag;
int oflag; int oflag;
int uflag; int uflag;
int vflag; int vflag;
int Sflag; /* force mark Go package as safe */
int errors; int errors;
@ -217,6 +218,7 @@ main(int argc, char *argv[])
case 'u': uflag = 1; break; case 'u': uflag = 1; break;
case 'v': vflag = 1; break; case 'v': vflag = 1; break;
case 'x': setcom(xcmd); break; case 'x': setcom(xcmd); break;
case 'S': Sflag = 1; break;
default: default:
fprint(2, "gopack: bad option `%c'\n", *cp); fprint(2, "gopack: bad option `%c'\n", *cp);
exits("error"); exits("error");
@ -648,18 +650,25 @@ strstrn(char *line, int len, char *sub)
/* /*
* package import data * package import data
*/ */
int safe = 1;
char* pkgname; char* pkgname;
char* importblock; char* importblock;
void void
getpkgdef(char **datap, int *lenp) getpkgdef(char **datap, int *lenp)
{ {
char *tag;
if(pkgname == nil) { if(pkgname == nil) {
pkgname = "__emptyarchive__"; pkgname = "__emptyarchive__";
importblock = ""; importblock = "";
} }
*datap = smprint("import\n$$\npackage %s\n%s\n$$\n", pkgname, importblock); tag = "";
if(safe || Sflag)
tag = "safe";
*datap = smprint("import\n$$\npackage %s %s\n%s\n$$\n", pkgname, tag, importblock);
*lenp = strlen(*datap); *lenp = strlen(*datap);
} }
@ -695,6 +704,7 @@ scanpkg(Biobuf *b, long size)
goto foundstart; goto foundstart;
} }
// fprint(2, "gopack: warning: no package import section in %s\n", file); // fprint(2, "gopack: warning: no package import section in %s\n", file);
safe = 0; // non-Go file (C or assembly)
return; return;
foundstart: foundstart:
@ -728,6 +738,8 @@ foundstart:
pkgname = armalloc(pkg - data + 1); pkgname = armalloc(pkg - data + 1);
memmove(pkgname, data, pkg - data); memmove(pkgname, data, pkg - data);
pkgname[pkg-data] = '\0'; pkgname[pkg-data] = '\0';
if(strcmp(pkg, " safe\n") != 0)
safe = 0;
start = Boffset(b); // after package statement start = Boffset(b); // after package statement
first = 0; first = 0;
continue; continue;

View File

@ -100,7 +100,7 @@ if $havex; then
fi fi
# They all compile; now generate the code to call them. # They all compile; now generate the code to call them.
trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15 # trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15
# Suppress output to stdout on Linux # Suppress output to stdout on Linux
MAKEFLAGS= MAKEFLAGS=
@ -116,7 +116,7 @@ nmgrep() {
# Figure out pkg. # Figure out pkg.
case "$i" in case "$i" in
*.a) *.a)
pkg=$("$GOBIN"/gopack p $i __.PKGDEF | sed -n 's/^package //p' | sed 1q) pkg=$("$GOBIN"/gopack p $i __.PKGDEF | sed -n 's/^package //p' | sed 's/ .*//' | sed 1q)
;; ;;
*) *)
pkg=$(sed -n 's/^ .* in package "\(.*\)".*/\1/p' $i | sed 1q) pkg=$(sed -n 's/^ .* in package "\(.*\)".*/\1/p' $i | sed 1q)