From 3f935d679870de924aa65d78c23ecdcb483ab4a3 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Sun, 6 Feb 2022 03:49:16 -0500
Subject: [PATCH 4/6] Suggest optional packages to install if missing
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
builder/jobs.go | 17 +++++++++++++++++
builder/mingw-w64.go | 2 +-
builder/tools.go | 6 +++++-
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/builder/jobs.go b/builder/jobs.go
index 3d510974..d24a4165 100644
--- a/builder/jobs.go
+++ b/builder/jobs.go
@@ -7,6 +7,7 @@ import (
"container/heap"
"errors"
"fmt"
+ "os"
"runtime"
"sort"
"strings"
@@ -37,6 +38,22 @@ type compileJob struct {
duration time.Duration // how long it took to run this job (only set after finishing)
}
+// checkIfPackagedFileExistsJob returns a new *compileJob that checks if a file
+// exists. If the file does not exist, the job will fail with an error
+// suggesting to install the named system packageToInstall.
+func checkIfPackagedFileExistsJob(fileName, packageToInstall string) *compileJob {
+ return &compileJob{
+ description: fmt.Sprintf("check if %v exists", fileName),
+ result: fileName,
+ run: func(*compileJob) (err error) {
+ if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) {
+ return fmt.Errorf("%v does not exist; please install %v via dnf", fileName, packageToInstall)
+ }
+ return nil
+ },
+ }
+}
+
// dummyCompileJob returns a new *compileJob that produces an output without
// doing anything. This can be useful where a *compileJob producing an output is
// expected but nothing needs to be done, for example for a load from a cache.
diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go
index d233068d..d2539f6e 100644
--- a/builder/mingw-w64.go
+++ b/builder/mingw-w64.go
@@ -27,7 +27,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob {
var jobs []*compileJob
for _, name := range []string{"kernel32", "ucrt"} {
outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name)
- job := dummyCompileJob(outpath)
+ job := checkIfPackagedFileExistsJob(outpath, "mingw64-crt and mingw64-headers")
jobs = append(jobs, job)
}
return jobs
diff --git a/builder/tools.go b/builder/tools.go
index 53d89bf0..e55719b2 100644
--- a/builder/tools.go
+++ b/builder/tools.go
@@ -46,5 +46,9 @@ func link(linker string, flags ...string) error {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = goenv.Get("TINYGOROOT")
- return cmd.Run()
+ err := cmd.Run()
+ if linker == "avr-gcc" && errors.Is(err, exec.ErrNotFound) {
+ return errors.New("avr-gcc not found; please install avr-gcc and avr-libc via dnf")
+ }
+ return err
}
--
2.36.1