Skip to content

Commit e8722a9

Browse files
committed
Check if ctags and core installed before compiling.
1 parent fd2be08 commit e8722a9

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

commands/compile/compile.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package compile
3131

3232
import (
33+
"fmt"
3334
"os"
3435
"path/filepath"
3536
"strings"
@@ -40,6 +41,7 @@ import (
4041
"github.com/bcmi-labs/arduino-cli/commands"
4142
"github.com/bcmi-labs/arduino-cli/common"
4243
"github.com/bcmi-labs/arduino-cli/common/formatter"
44+
"github.com/bcmi-labs/arduino-cli/cores"
4345
"github.com/bcmi-labs/arduino-cli/sketches"
4446
"github.com/sirupsen/logrus"
4547
"github.com/spf13/cobra"
@@ -90,7 +92,7 @@ func run(cmd *cobra.Command, args []string) {
9092
formatter.PrintError(err, "Sketch file not found.")
9193
isCorrectSyntax = false
9294
}
93-
var packageName string
95+
var packageName, coreName string
9496
fullyQualifiedBoardName := flags.fullyQualifiedBoardName
9597
if fullyQualifiedBoardName == "" && sketch != nil {
9698
fullyQualifiedBoardName = sketch.Metadata.CPU.Fqbn
@@ -105,8 +107,31 @@ func run(cmd *cobra.Command, args []string) {
105107
isCorrectSyntax = false
106108
} else {
107109
packageName = fqbnParts[0]
110+
coreName = fqbnParts[1]
108111
}
109112
}
113+
114+
isCtagsInstalled, err := cores.IsToolInstalled(packageName, "ctags")
115+
if err != nil {
116+
formatter.PrintError(err, "Cannot check ctags installation.")
117+
os.Exit(commands.ErrCoreConfig)
118+
}
119+
if !isCtagsInstalled {
120+
// TODO: how to properly install ctags?
121+
formatter.PrintErrorMessage("\"ctags\" tool not installed, please install it.")
122+
isCorrectSyntax = false
123+
}
124+
125+
isCoreInstalled, err := cores.IsCoreInstalled(packageName, coreName)
126+
if err != nil {
127+
formatter.PrintError(err, "Cannot check core installation.")
128+
os.Exit(commands.ErrCoreConfig)
129+
}
130+
if !isCoreInstalled {
131+
formatter.PrintErrorMessage(fmt.Sprintf("\"%[1]s:%[2]s\" core is not installed, please install it by running \"arduino core install %[1]s:%[2]s\".", packageName, coreName))
132+
isCorrectSyntax = false
133+
}
134+
110135
if !isCorrectSyntax {
111136
os.Exit(commands.ErrBadCall)
112137
}

cores/common.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@
3030
package cores
3131

3232
import (
33+
"os"
34+
"path/filepath"
3335
"regexp"
3436
"strings"
37+
38+
"github.com/bcmi-labs/arduino-cli/common"
3539
)
3640

3741
// CoreIDTuple represents a tuple to identify a Core
@@ -72,3 +76,29 @@ func ParseArgs(args []string) []CoreIDTuple {
7276
}
7377
return ret
7478
}
79+
80+
// IsCoreInstalled detects if a core has been installed.
81+
func IsCoreInstalled(packageName string, name string) (bool, error) {
82+
location, err := common.GetDefaultCoresFolder(packageName)
83+
if err != nil {
84+
return false, err
85+
}
86+
_, err = os.Stat(filepath.Join(location, name))
87+
if !os.IsNotExist(err) {
88+
return true, nil
89+
}
90+
return false, nil
91+
}
92+
93+
// IsToolInstalled detects if a tool has been installed.
94+
func IsToolInstalled(packageName string, name string) (bool, error) {
95+
location, err := common.GetDefaultToolsFolder(packageName)
96+
if err != nil {
97+
return false, err
98+
}
99+
_, err = os.Stat(filepath.Join(location, name))
100+
if !os.IsNotExist(err) {
101+
return true, nil
102+
}
103+
return false, nil
104+
}

0 commit comments

Comments
 (0)