Skip to content

Commit cdd2a9c

Browse files
committed
Use FQBN parsing functions to parse FQBN in compile command
1 parent 1e825c0 commit cdd2a9c

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

Diff for: commands/compile/compile.go

+13-20
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,18 @@ func run(cmd *cobra.Command, args []string) {
9595
os.Exit(commands.ErrGeneric)
9696
}
9797

98-
fqbn := flags.fqbn
99-
if fqbn == "" && sketch != nil {
100-
fqbn = sketch.Metadata.CPU.Fqbn
98+
if flags.fqbn == "" && sketch != nil {
99+
flags.fqbn = sketch.Metadata.CPU.Fqbn
101100
}
102-
if fqbn == "" {
101+
if flags.fqbn == "" {
103102
formatter.PrintErrorMessage("No Fully Qualified Board Name provided.")
104103
os.Exit(commands.ErrGeneric)
105104
}
106-
fqbnParts := strings.Split(fqbn, ":")
107-
if len(fqbnParts) < 3 || len(fqbnParts) > 4 {
105+
fqbn, err := cores.ParseFQBN(flags.fqbn)
106+
if err != nil {
108107
formatter.PrintErrorMessage("Fully Qualified Board Name has incorrect format.")
109108
os.Exit(commands.ErrBadArgument)
110109
}
111-
packageName := fqbnParts[0]
112-
coreName := fqbnParts[1]
113110

114111
pm := commands.InitPackageManager()
115112

@@ -133,25 +130,20 @@ func run(cmd *cobra.Command, args []string) {
133130
}
134131

135132
targetPlatform := pm.FindPlatform(&packagemanager.PlatformReference{
136-
Package: packageName,
137-
PlatformArchitecture: coreName,
133+
Package: fqbn.Package,
134+
PlatformArchitecture: fqbn.PlatformArch,
138135
})
139136
if targetPlatform == nil || pm.GetInstalledPlatformRelease(targetPlatform) == nil {
140137
errorMessage := fmt.Sprintf(
141138
"\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
142-
commands.AppName+" core install %[1]s:%[2]s\".", packageName, coreName)
139+
commands.AppName+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
143140
formatter.PrintErrorMessage(errorMessage)
144141
os.Exit(commands.ErrCoreConfig)
145142
}
146143

147144
ctx := &types.Context{}
148145
ctx.PackageManager = pm
149-
if parsedFqbn, err := cores.ParseFQBN(fqbn); err != nil {
150-
formatter.PrintError(err, "Error parsing FQBN.")
151-
os.Exit(commands.ErrBadArgument)
152-
} else {
153-
ctx.FQBN = parsedFqbn
154-
}
146+
ctx.FQBN = fqbn
155147
ctx.SketchLocation = paths.New(sketch.FullPath)
156148

157149
// FIXME: This will be redundant when arduino-builder will be part of the cli
@@ -242,12 +234,13 @@ func run(cmd *cobra.Command, args []string) {
242234
// FIXME: Make a function to obtain these info...
243235
outputPath := ctx.BuildProperties.ExpandPropsInString("{build.path}/{recipe.output.tmp_file}")
244236
ext := filepath.Ext(outputPath)
237+
245238
// FIXME: Make a function to produce a better name...
246-
fqbn = strings.Replace(fqbn, ":", ".", -1)
239+
fqbnSuffix := strings.Replace(fqbn.String(), ":", ".", -1)
247240

248241
// Copy .hex file to sketch directory
249242
srcHex := paths.New(outputPath)
250-
dstHex := paths.New(sketch.FullPath).Join(sketch.Name + "." + fqbn + ext)
243+
dstHex := paths.New(sketch.FullPath).Join(sketch.Name + "." + fqbnSuffix + ext)
251244
logrus.WithField("from", srcHex).WithField("to", dstHex).Print("copying sketch build output")
252245
if err = srcHex.CopyTo(dstHex); err != nil {
253246
formatter.PrintError(err, "Error copying output file.")
@@ -256,7 +249,7 @@ func run(cmd *cobra.Command, args []string) {
256249

257250
// Copy .elf file to sketch directory
258251
srcElf := paths.New(outputPath[:len(outputPath)-3] + "elf")
259-
dstElf := paths.New(sketch.FullPath).Join(sketch.Name + "." + fqbn + ".elf")
252+
dstElf := paths.New(sketch.FullPath).Join(sketch.Name + "." + fqbnSuffix + ".elf")
260253
logrus.WithField("from", srcElf).WithField("to", dstElf).Print("copying sketch build output")
261254
if err = srcElf.CopyTo(dstElf); err != nil {
262255
formatter.PrintError(err, "Error copying elf file.")

0 commit comments

Comments
 (0)