1
0
mirror of https://github.com/golang/go synced 2024-11-23 00:00:07 -07:00

cmd/gc: support -installsuffix in the compiler and builder

Add the -installsuffix flag to gc and {5,6,8}l, which overrides -race
for the suffix if both are supplied.
Pass this flag from the go tool for build and install.

R=rsc
CC=golang-dev
https://golang.org/cl/14246044
This commit is contained in:
Dave Day 2013-10-03 13:48:47 +10:00
parent 45b830ed31
commit 0a033a18ad
9 changed files with 36 additions and 11 deletions

View File

@ -117,6 +117,7 @@ main(int argc, char *argv[])
flagstr("extldflags", "flags for external linker", &extldflags);
flagcount("f", "ignore version mismatch", &debug['f']);
flagcount("g", "disable go package data checks", &debug['g']);
flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix);
flagstr("k", "sym: set field tracking symbol", &tracksym);
flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
flagcount("n", "dump symbol table", &debug['n']);

View File

@ -112,6 +112,7 @@ main(int argc, char *argv[])
flagstr("extldflags", "flags for external linker", &extldflags);
flagcount("f", "ignore version mismatch", &debug['f']);
flagcount("g", "disable go package data checks", &debug['g']);
flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix);
flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
flagstr("k", "sym: set field tracking symbol", &tracksym);
flagcount("n", "dump symbol table", &debug['n']);

View File

@ -118,6 +118,7 @@ main(int argc, char *argv[])
flagstr("extldflags", "flags for external linker", &extldflags);
flagcount("f", "ignore version mismatch", &debug['f']);
flagcount("g", "disable go package data checks", &debug['g']);
flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix);
flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode);
flagstr("k", "sym: set field tracking symbol", &tracksym);
flagstr("o", "outfile: set output file", &outfile);

View File

@ -976,6 +976,7 @@ EXTERN int typecheckok;
EXTERN int compiling_runtime;
EXTERN int compiling_wrappers;
EXTERN int pure_go;
EXTERN char* flag_installsuffix;
EXTERN int flag_race;
EXTERN int flag_largemodel;
EXTERN int noescape;

View File

@ -257,6 +257,7 @@ main(int argc, char *argv[])
flagcount("g", "debug code generation", &debug['g']);
flagcount("h", "halt on error", &debug['h']);
flagcount("i", "debug line number stack", &debug['i']);
flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix);
flagcount("j", "debug runtime-initialized variables", &debug['j']);
flagcount("l", "disable inlining", &debug['l']);
flagcount("m", "print optimization decisions", &debug['m']);
@ -577,7 +578,7 @@ static int
findpkg(Strlit *name)
{
Idir *p;
char *q, *race;
char *q, *suffix, *suffixsep;
if(islocalname(name)) {
if(safemode)
@ -615,13 +616,19 @@ findpkg(Strlit *name)
return 1;
}
if(goroot != nil) {
race = "";
if(flag_race)
race = "_race";
snprint(namebuf, sizeof(namebuf), "%s/pkg/%s_%s%s/%Z.a", goroot, goos, goarch, race, name);
suffix = "";
suffixsep = "";
if(flag_installsuffix != nil) {
suffixsep = "_";
suffix = flag_installsuffix;
} else if(flag_race) {
suffixsep = "_";
suffix = "race";
}
snprint(namebuf, sizeof(namebuf), "%s/pkg/%s_%s%s%s/%Z.a", goroot, goos, goarch, suffixsep, suffix, name);
if(access(namebuf, 0) >= 0)
return 1;
snprint(namebuf, sizeof(namebuf), "%s/pkg/%s_%s%s/%Z.%c", goroot, goos, goarch, race, name, thechar);
snprint(namebuf, sizeof(namebuf), "%s/pkg/%s_%s%s%s/%Z.%c", goroot, goos, goarch, suffixsep, suffix, name, thechar);
if(access(namebuf, 0) >= 0)
return 1;
}

View File

@ -1530,6 +1530,9 @@ func (gcToolchain) gc(b *builder, p *Package, obj string, importArgs []string, g
if extFiles == 0 {
gcargs = append(gcargs, "-complete")
}
if buildContext.InstallSuffix != "" {
gcargs = append(gcargs, "-installsuffix", buildContext.InstallSuffix)
}
args := stringList(tool(archChar+"g"), "-o", ofile, buildGcflags, gcargs, "-D", p.localPrefix, importArgs)
for _, f := range gofiles {
@ -1579,6 +1582,9 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action,
}
}
ldflags := buildLdflags
if buildContext.InstallSuffix != "" {
ldflags = append(ldflags, "-installsuffix", buildContext.InstallSuffix)
}
if cxx {
// The program includes C++ code. If the user has not
// specified the -extld option, then default to

View File

@ -82,6 +82,7 @@ var testFlagDefn = []*testFlagSpec{
{name: "tags"},
{name: "compiler"},
{name: "race", boolVar: &buildRace},
{name: "installsuffix"},
// passed to 6.out, adding a "test." prefix to the name if necessary: -v becomes -test.v.
{name: "bench", passToTest: true},

View File

@ -91,7 +91,7 @@ Lflag(char *arg)
void
libinit(void)
{
char *race;
char *suffix, *suffixsep;
fmtinstall('i', iconv);
fmtinstall('Y', Yconv);
@ -101,10 +101,16 @@ libinit(void)
print("goarch is not known: %s\n", goarch);
// add goroot to the end of the libdir list.
race = "";
if(flag_race)
race = "_race";
Lflag(smprint("%s/pkg/%s_%s%s", goroot, goos, goarch, race));
suffix = "";
suffixsep = "";
if(flag_installsuffix != nil) {
suffixsep = "_";
suffix = flag_installsuffix;
} else if(flag_race) {
suffixsep = "_";
suffix = "race";
}
Lflag(smprint("%s/pkg/%s_%s%s%s", goroot, goos, goarch, suffixsep, suffix));
// Unix doesn't like it when we write to a running (or, sometimes,
// recently run) binary, so remove the output file before writing it.

View File

@ -160,6 +160,7 @@ EXTERN char** ldflag;
EXTERN int havedynamic;
EXTERN int iscgo;
EXTERN int elfglobalsymndx;
EXTERN char* flag_installsuffix;
EXTERN int flag_race;
EXTERN int flag_shared;
EXTERN char* tracksym;