From f957e117daf05794c09ce4d9d4d7929d1a0b6214 Mon Sep 17 00:00:00 2001 From: "Scott S. McCoy" Date: Thu, 3 Nov 2016 14:14:01 -0700 Subject: [PATCH] Run compiler from the project directory In an attempt to solve issue #406, run the compiler instead of from the package directory from the root of the project. Make all paths passed to the compiler relative to the project root. This appears to work, and the tests still pass; but it corrects the output of compiler errors and they now appear with filenames relative to the `GB_PROJECT_DIR`. --- build.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build.go b/build.go index 724c857..ec07c74 100644 --- a/build.go +++ b/build.go @@ -270,6 +270,9 @@ func gc(pkg *Package, gofiles []string) error { t0 := time.Now() includes := pkg.IncludePaths() importpath := pkg.ImportPath + + wd := pkg.Context.Project.Projectdir() + if pkg.TestScope && pkg.ExtraIncludes != "" { // TODO(dfc) gross includes = append([]string{pkg.ExtraIncludes}, includes...) @@ -280,14 +283,17 @@ func gc(pkg *Package, gofiles []string) error { continue } fullpath := filepath.Join(pkg.Dir, gofiles[i]) - path, err := filepath.Rel(pkg.Dir, fullpath) + + // Run this relative to the *working* directory. + path, err := filepath.Rel(wd, fullpath) + if err == nil { gofiles[i] = path } else { gofiles[i] = fullpath } } - err := pkg.tc.Gc(pkg, includes, importpath, pkg.Dir, objfile(pkg), gofiles) + err := pkg.tc.Gc(pkg, includes, importpath, wd, objfile(pkg), gofiles) pkg.Record("gc", time.Since(t0)) return err }