Commit 34b10d74 authored by Pieter Droogendijk's avatar Pieter Droogendijk Committed by Alex Brainman

cmd/dist: Make verbose messages print to stderr

Made the following changes:
 - Export errprintf() from all three OS-specific modules
 - Added errprintf() to a.h
 - Moved errprintf() in windows.c under xprintf(), since they are so similar
 - Replaced all instances of xprintf() with errprintf() where a vflag check is done
Fixes #3788.

R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/6346056
parent b213891c
...@@ -108,6 +108,7 @@ void xmain(int argc, char **argv); ...@@ -108,6 +108,7 @@ void xmain(int argc, char **argv);
// portability layer (plan9.c, unix.c, windows.c) // portability layer (plan9.c, unix.c, windows.c)
bool contains(char *p, char *sep); bool contains(char *p, char *sep);
void errprintf(char*, ...);
void fatal(char *msg, ...); void fatal(char *msg, ...);
bool hasprefix(char *p, char *prefix); bool hasprefix(char *p, char *prefix);
bool hassuffix(char *p, char *suffix); bool hassuffix(char *p, char *suffix);
......
...@@ -147,7 +147,7 @@ static void ...@@ -147,7 +147,7 @@ static void
rmworkdir(void) rmworkdir(void)
{ {
if(vflag > 1) if(vflag > 1)
xprintf("rm -rf %s\n", workdir); errprintf("rm -rf %s\n", workdir);
xremoveall(workdir); xremoveall(workdir);
} }
...@@ -543,9 +543,9 @@ install(char *dir) ...@@ -543,9 +543,9 @@ install(char *dir)
if(vflag) { if(vflag) {
if(!streq(goos, gohostos) || !streq(goarch, gohostarch)) if(!streq(goos, gohostos) || !streq(goarch, gohostarch))
xprintf("%s (%s/%s)\n", dir, goos, goarch); errprintf("%s (%s/%s)\n", dir, goos, goarch);
else else
xprintf("%s\n", dir); errprintf("%s\n", dir);
} }
binit(&b); binit(&b);
...@@ -575,7 +575,7 @@ install(char *dir) ...@@ -575,7 +575,7 @@ install(char *dir)
// For release, cmd/prof and cmd/cov are not included. // For release, cmd/prof and cmd/cov are not included.
if((streq(dir, "cmd/cov") || streq(dir, "cmd/prof")) && !isdir(bstr(&path))) { if((streq(dir, "cmd/cov") || streq(dir, "cmd/prof")) && !isdir(bstr(&path))) {
if(vflag > 1) if(vflag > 1)
xprintf("skipping %s - does not exist\n", dir); errprintf("skipping %s - does not exist\n", dir);
goto out; goto out;
} }
...@@ -784,7 +784,7 @@ install(char *dir) ...@@ -784,7 +784,7 @@ install(char *dir)
for(j=0; j<nelem(gentab); j++) { for(j=0; j<nelem(gentab); j++) {
if(hasprefix(elem, gentab[j].nameprefix)) { if(hasprefix(elem, gentab[j].nameprefix)) {
if(vflag > 1) if(vflag > 1)
xprintf("generate %s\n", p); errprintf("generate %s\n", p);
gentab[j].gen(bstr(&path), p); gentab[j].gen(bstr(&path), p);
// Do not add generated file to clean list. // Do not add generated file to clean list.
// In pkg/runtime, we want to be able to // In pkg/runtime, we want to be able to
...@@ -829,7 +829,7 @@ install(char *dir) ...@@ -829,7 +829,7 @@ install(char *dir)
if((!streq(goos, gohostos) || !streq(goarch, gohostarch)) && isgo) { if((!streq(goos, gohostos) || !streq(goarch, gohostarch)) && isgo) {
// We've generated the right files; the go command can do the build. // We've generated the right files; the go command can do the build.
if(vflag > 1) if(vflag > 1)
xprintf("skip build for cross-compile %s\n", dir); errprintf("skip build for cross-compile %s\n", dir);
goto nobuild; goto nobuild;
} }
...@@ -1112,7 +1112,7 @@ copy(char *dst, char *src, int exec) ...@@ -1112,7 +1112,7 @@ copy(char *dst, char *src, int exec)
Buf b; Buf b;
if(vflag > 1) if(vflag > 1)
xprintf("cp %s %s\n", src, dst); errprintf("cp %s %s\n", src, dst);
binit(&b); binit(&b);
readfile(&b, src); readfile(&b, src);
......
...@@ -177,7 +177,7 @@ genrun(Buf *b, char *dir, int mode, Vec *argv, int wait) ...@@ -177,7 +177,7 @@ genrun(Buf *b, char *dir, int mode, Vec *argv, int wait)
bwritestr(&cmd, q); bwritestr(&cmd, q);
} }
if(vflag > 1) if(vflag > 1)
xprintf("%s\n", bstr(&cmd)); errprintf("%s\n", bstr(&cmd));
if(b != nil) { if(b != nil) {
breset(b); breset(b);
...@@ -422,7 +422,7 @@ void ...@@ -422,7 +422,7 @@ void
xremove(char *p) xremove(char *p)
{ {
if(vflag > 2) if(vflag > 2)
xprintf("rm %s\n", p); errprintf("rm %s\n", p);
remove(p); remove(p);
} }
...@@ -445,7 +445,7 @@ xremoveall(char *p) ...@@ -445,7 +445,7 @@ xremoveall(char *p)
} }
} }
if(vflag > 2) if(vflag > 2)
xprintf("rm %s\n", p); errprintf("rm %s\n", p);
remove(p); remove(p);
bfree(&b); bfree(&b);
...@@ -661,6 +661,17 @@ xprintf(char *fmt, ...) ...@@ -661,6 +661,17 @@ xprintf(char *fmt, ...)
va_end(arg); va_end(arg);
} }
// errprintf prints a message to standard output.
void
errprintf(char *fmt, ...)
{
va_list arg;
va_start(arg, fmt);
vfprintf(stderr, fmt, arg);
va_end(arg);
}
// xsetenv sets the environment variable $name to the given value. // xsetenv sets the environment variable $name to the given value.
void void
xsetenv(char *name, char *value) xsetenv(char *name, char *value)
......
...@@ -177,7 +177,7 @@ genrun(Buf *b, char *dir, int mode, Vec *argv, int wait) ...@@ -177,7 +177,7 @@ genrun(Buf *b, char *dir, int mode, Vec *argv, int wait)
bwritestr(&cmd, q); bwritestr(&cmd, q);
} }
if(vflag > 1) if(vflag > 1)
xprintf("%s\n", bstr(&cmd)); errprintf("%s\n", bstr(&cmd));
if(b != nil) { if(b != nil) {
breset(b); breset(b);
...@@ -398,7 +398,7 @@ void ...@@ -398,7 +398,7 @@ void
xremove(char *p) xremove(char *p)
{ {
if(vflag > 2) if(vflag > 2)
xprintf("rm %s\n", p); errprintf("rm %s\n", p);
unlink(p); unlink(p);
} }
...@@ -420,11 +420,11 @@ xremoveall(char *p) ...@@ -420,11 +420,11 @@ xremoveall(char *p)
xremoveall(bstr(&b)); xremoveall(bstr(&b));
} }
if(vflag > 2) if(vflag > 2)
xprintf("rm %s\n", p); errprintf("rm %s\n", p);
rmdir(p); rmdir(p);
} else { } else {
if(vflag > 2) if(vflag > 2)
xprintf("rm %s\n", p); errprintf("rm %s\n", p);
unlink(p); unlink(p);
} }
...@@ -627,6 +627,17 @@ xprintf(char *fmt, ...) ...@@ -627,6 +627,17 @@ xprintf(char *fmt, ...)
va_end(arg); va_end(arg);
} }
// errprintf prints a message to standard output.
void
errprintf(char *fmt, ...)
{
va_list arg;
va_start(arg, fmt);
vfprintf(stderr, fmt, arg);
va_end(arg);
}
// xsetenv sets the environment variable $name to the given value. // xsetenv sets the environment variable $name to the given value.
void void
xsetenv(char *name, char *value) xsetenv(char *name, char *value)
......
...@@ -121,22 +121,6 @@ errstr(void) ...@@ -121,22 +121,6 @@ errstr(void)
return bstr(&b); // leak but we're dying anyway return bstr(&b); // leak but we're dying anyway
} }
static void
errprintf(char *fmt, ...) {
va_list arg;
char *p;
DWORD n, w;
va_start(arg, fmt);
n = vsnprintf(NULL, 0, fmt, arg);
p = xmalloc(n+1);
vsnprintf(p, n+1, fmt, arg);
va_end(arg);
w = 0;
WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
xfree(p);
}
void void
xgetenv(Buf *b, char *name) xgetenv(Buf *b, char *name)
{ {
...@@ -332,7 +316,7 @@ genrun(Buf *b, char *dir, int mode, Vec *argv, int wait) ...@@ -332,7 +316,7 @@ genrun(Buf *b, char *dir, int mode, Vec *argv, int wait)
} }
} }
if(vflag > 1) if(vflag > 1)
xprintf("%s\n", bstr(&cmd)); errprintf("%s\n", bstr(&cmd));
torune(&rcmd, bstr(&cmd)); torune(&rcmd, bstr(&cmd));
rexe = nil; rexe = nil;
...@@ -547,7 +531,7 @@ readfile(Buf *b, char *file) ...@@ -547,7 +531,7 @@ readfile(Buf *b, char *file)
Rune *r; Rune *r;
if(vflag > 2) if(vflag > 2)
xprintf("read %s\n", file); errprintf("read %s\n", file);
torune(&r, file); torune(&r, file);
h = CreateFileW(r, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); h = CreateFileW(r, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if(h == INVALID_HANDLE_VALUE) if(h == INVALID_HANDLE_VALUE)
...@@ -566,7 +550,7 @@ writefile(Buf *b, char *file, int exec) ...@@ -566,7 +550,7 @@ writefile(Buf *b, char *file, int exec)
USED(exec); USED(exec);
if(vflag > 2) if(vflag > 2)
xprintf("write %s\n", file); errprintf("write %s\n", file);
torune(&r, file); torune(&r, file);
h = CreateFileW(r, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, nil, CREATE_ALWAYS, 0, 0); h = CreateFileW(r, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, nil, CREATE_ALWAYS, 0, 0);
if(h == INVALID_HANDLE_VALUE) if(h == INVALID_HANDLE_VALUE)
...@@ -866,6 +850,22 @@ xprintf(char *fmt, ...) ...@@ -866,6 +850,22 @@ xprintf(char *fmt, ...)
xfree(p); xfree(p);
} }
void
errprintf(char *fmt, ...) {
va_list arg;
char *p;
DWORD n, w;
va_start(arg, fmt);
n = vsnprintf(NULL, 0, fmt, arg);
p = xmalloc(n+1);
vsnprintf(p, n+1, fmt, arg);
va_end(arg);
w = 0;
WriteFile(GetStdHandle(STD_ERROR_HANDLE), p, n, &w, 0);
xfree(p);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment