aboutsummaryrefslogtreecommitdiffhomepage
path: root/loader
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-07-09 18:08:51 +0200
committerAyke <[email protected]>2024-07-13 13:26:26 +0200
commitd7773d3e86e82a64c79a04fa70f740daf333a3be (patch)
tree99361d45c7872f8da2d2c2e6fea55090942a9570 /loader
parentb04b690842f837aedc6d8187bb4a4200b0cc6acc (diff)
downloadtinygo-d7773d3e86e82a64c79a04fa70f740daf333a3be.tar.gz
tinygo-d7773d3e86e82a64c79a04fa70f740daf333a3be.zip
loader: handle `go list` errors inside TinyGo
Instead of exiting with an error, handle these errors internally. This will enable a few improvements in the future.
Diffstat (limited to 'loader')
-rw-r--r--loader/loader.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/loader/loader.go b/loader/loader.go
index a874291a6..fe75e6c9b 100644
--- a/loader/loader.go
+++ b/loader/loader.go
@@ -128,7 +128,7 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
}
// List the dependencies of this package, in raw JSON format.
- extraArgs := []string{"-json", "-deps"}
+ extraArgs := []string{"-json", "-deps", "-e"}
if config.TestConfig.CompileTestBinary {
extraArgs = append(extraArgs, "-test")
}
@@ -149,6 +149,7 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
// Parse the returned json from `go list`.
decoder := json.NewDecoder(buf)
+ var pkgErrors []error
for {
pkg := &Package{
program: p,
@@ -188,6 +189,12 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
pos.Filename = strings.Join(fields[:len(fields)-1], ":")
pos.Line, _ = strconv.Atoi(fields[len(fields)-1])
}
+ if abs, err := filepath.Abs(pos.Filename); err == nil {
+ // Make the path absolute, so that error messages will be
+ // prettier (it will be turned back into a relative path
+ // when printing the error).
+ pos.Filename = abs
+ }
pos.Filename = p.getOriginalPath(pos.Filename)
}
err := scanner.Error{
@@ -195,10 +202,11 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
Msg: pkg.Error.Err,
}
if len(pkg.Error.ImportStack) != 0 {
- return nil, Error{
+ pkgErrors = append(pkgErrors, Error{
ImportStack: pkg.Error.ImportStack,
Err: err,
- }
+ })
+ continue
}
return nil, err
}
@@ -241,6 +249,13 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
p.Packages[pkg.ImportPath] = pkg
}
+ if len(pkgErrors) != 0 {
+ // TODO: use errors.Join in Go 1.20.
+ return nil, Errors{
+ Errs: pkgErrors,
+ }
+ }
+
if config.TestConfig.CompileTestBinary && !strings.HasSuffix(p.sorted[len(p.sorted)-1].ImportPath, ".test") {
// Trying to compile a test binary but there are no test files in this
// package.