Skip to content

Commit 2bf113b

Browse files
committed
Reordered compileFileWithRecipe for clarity
1 parent 3246db0 commit 2bf113b

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

internal/arduino/builder/compilation.go

+37-34
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func (b *Builder) compileFiles(
111111
return objectFiles, nil
112112
}
113113

114-
// CompileFilesRecursive fixdoc
115114
func (b *Builder) compileFileWithRecipe(
116115
sourcePath *paths.Path,
117116
source *paths.Path,
@@ -129,11 +128,6 @@ func (b *Builder) compileFileWithRecipe(
129128
return nil, err
130129
}
131130

132-
objIsUpToDate, err := utils.ObjFileIsUpToDate(source, objectFile, depsFile)
133-
if err != nil {
134-
return nil, err
135-
}
136-
137131
properties := b.buildProperties.Clone()
138132
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+b.logger.WarningsLevel()))
139133
properties.Set("includes", strings.Join(includes, " "))
@@ -146,41 +140,50 @@ func (b *Builder) compileFileWithRecipe(
146140
if b.compilationDatabase != nil {
147141
b.compilationDatabase.Add(source, command)
148142
}
149-
if !objIsUpToDate && !b.onlyUpdateCompilationDatabase {
150-
commandStdout, commandStderr := &bytes.Buffer{}, &bytes.Buffer{}
151-
command.RedirectStdoutTo(commandStdout)
152-
command.RedirectStderrTo(commandStderr)
153143

144+
objIsUpToDate, err := utils.ObjFileIsUpToDate(source, objectFile, depsFile)
145+
if err != nil {
146+
return nil, err
147+
}
148+
if objIsUpToDate {
154149
if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
155-
b.logger.Info(utils.PrintableCommand(command.GetArgs()))
156-
}
157-
// Since this compile could be multithreaded, we first capture the command output
158-
if err := command.Start(); err != nil {
159-
return nil, err
150+
b.logger.Info(i18n.Tr("Using previously compiled file: %[1]s", objectFile))
160151
}
161-
err := command.Wait()
162-
// and transfer all at once at the end...
152+
return objectFile, nil
153+
}
154+
if b.onlyUpdateCompilationDatabase {
163155
if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
164-
b.logger.WriteStdout(commandStdout.Bytes())
156+
b.logger.Info(i18n.Tr("Skipping compile of: %[1]s", objectFile))
165157
}
166-
b.logger.WriteStderr(commandStderr.Bytes())
158+
return objectFile, nil
159+
}
167160

168-
// Parse the output of the compiler to gather errors and warnings...
169-
if b.diagnosticStore != nil {
170-
b.diagnosticStore.Parse(command.GetArgs(), commandStdout.Bytes())
171-
b.diagnosticStore.Parse(command.GetArgs(), commandStderr.Bytes())
172-
}
161+
commandStdout, commandStderr := &bytes.Buffer{}, &bytes.Buffer{}
162+
command.RedirectStdoutTo(commandStdout)
163+
command.RedirectStderrTo(commandStderr)
164+
if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
165+
b.logger.Info(utils.PrintableCommand(command.GetArgs()))
166+
}
167+
// Since this compile could be multithreaded, we first capture the command output
168+
if err := command.Start(); err != nil {
169+
return nil, err
170+
}
171+
err = command.Wait()
172+
// and transfer all at once at the end...
173+
if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
174+
b.logger.WriteStdout(commandStdout.Bytes())
175+
}
176+
b.logger.WriteStderr(commandStderr.Bytes())
173177

174-
// ...and then return the error
175-
if err != nil {
176-
return nil, err
177-
}
178-
} else if b.logger.VerbosityLevel() == logger.VerbosityVerbose {
179-
if objIsUpToDate {
180-
b.logger.Info(i18n.Tr("Using previously compiled file: %[1]s", objectFile))
181-
} else {
182-
b.logger.Info(i18n.Tr("Skipping compile of: %[1]s", objectFile))
183-
}
178+
// Parse the output of the compiler to gather errors and warnings...
179+
if b.diagnosticStore != nil {
180+
b.diagnosticStore.Parse(command.GetArgs(), commandStdout.Bytes())
181+
b.diagnosticStore.Parse(command.GetArgs(), commandStderr.Bytes())
182+
}
183+
184+
// ...and then return the error
185+
if err != nil {
186+
return nil, err
184187
}
185188

186189
return objectFile, nil

0 commit comments

Comments
 (0)