Skip to content

Commit cf110ab

Browse files
committed
Reordered compileFileWithRecipe for clarity
1 parent da71e60 commit cf110ab

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
@@ -110,7 +110,6 @@ func (b *Builder) compileFiles(
110110
return objectFiles, nil
111111
}
112112

113-
// CompileFilesRecursive fixdoc
114113
func (b *Builder) compileFileWithRecipe(
115114
sourcePath *paths.Path,
116115
source *paths.Path,
@@ -128,11 +127,6 @@ func (b *Builder) compileFileWithRecipe(
128127
return nil, err
129128
}
130129

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

143+
objIsUpToDate, err := utils.ObjFileIsUpToDate(source, objectFile, depsFile)
144+
if err != nil {
145+
return nil, err
146+
}
147+
if objIsUpToDate {
153148
if b.logger.Verbose() {
154-
b.logger.Info(utils.PrintableCommand(command.GetArgs()))
155-
}
156-
// Since this compile could be multithreaded, we first capture the command output
157-
if err := command.Start(); err != nil {
158-
return nil, err
149+
b.logger.Info(i18n.Tr("Using previously compiled file: %[1]s", objectFile))
159150
}
160-
err := command.Wait()
161-
// and transfer all at once at the end...
151+
return objectFile, nil
152+
}
153+
if b.onlyUpdateCompilationDatabase {
162154
if b.logger.Verbose() {
163-
b.logger.WriteStdout(commandStdout.Bytes())
155+
b.logger.Info(i18n.Tr("Skipping compile of: %[1]s", objectFile))
164156
}
165-
b.logger.WriteStderr(commandStderr.Bytes())
157+
return objectFile, nil
158+
}
166159

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

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

185188
return objectFile, nil

0 commit comments

Comments
 (0)