builder: add support for -x flag

Print commands as they are executed with the -x flag. This is not yet
complete: library builds don't print commands yet. But it's a step
closer.
Этот коммит содержится в:
Ayke van Laethem 2021-03-12 17:14:42 +01:00 коммит произвёл Ron Evans
родитель fb03787b73
коммит 896a848001
3 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -476,6 +476,9 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
}
ldflags = append(ldflags, dependency.result)
}
if config.Options.PrintCommands {
fmt.Printf("%s %s\n", config.Target.Linker, strings.Join(ldflags, " "))
}
err = link(config.Target.Linker, ldflags...)
if err != nil {
return &commandError{"failed to link", executable, err}

Просмотреть файл

@ -124,6 +124,9 @@ func compileAndCacheCFile(abspath, tmpdir string, config *compileopts.Config) (s
flags := config.CFlags()
flags = append(flags, "-MD", "-MV", "-MTdeps", "-MF", depTmpFile.Name()) // autogenerate dependencies
flags = append(flags, "-c", "-o", objTmpFile.Name(), abspath)
if config.Options.PrintCommands {
fmt.Printf("%s %s\n", config.Target.Compiler, strings.Join(flags, " "))
}
err = runCCompiler(config.Target.Compiler, flags...)
if err != nil {
return "", &commandError{"failed to build", abspath, err}

Просмотреть файл

@ -93,7 +93,7 @@ func copyFile(src, dst string) error {
// executeCommand is a simple wrapper to exec.Cmd
func executeCommand(options *compileopts.Options, name string, arg ...string) *exec.Cmd {
if options.PrintCommands {
fmt.Printf("%s %s\n ", name, strings.Join(arg, " "))
fmt.Printf("%s %s\n", name, strings.Join(arg, " "))
}
return exec.Command(name, arg...)
}