@@ -57,19 +57,17 @@ func PreprocessSketchWithCtags(
57
57
58
58
// Check if the preprocessed file is already up-to-date
59
59
unpreprocessedSourceFile := buildPath .Join ("sketch" , sketch .MainFile .Base ()+ ".cpp.merged" )
60
- sourceFile := buildPath .Join ("sketch" , sketch .MainFile .Base ()+ ".cpp" )
60
+ preprocessedSourceFile := buildPath .Join ("sketch" , sketch .MainFile .Base ()+ ".cpp" )
61
61
if unpreprocessedStat , err := unpreprocessedSourceFile .Stat (); err != nil {
62
62
return nil , fmt .Errorf ("%s: %w" , i18n .Tr ("unable to open unpreprocessed source file" ), err )
63
- } else if sourceStat , err := sourceFile .Stat (); err != nil {
64
- return nil , fmt .Errorf ("%s: %w" , i18n .Tr ("unable to open source file" ), err )
65
- } else if unpreprocessedStat .ModTime ().Before (sourceStat .ModTime ()) {
63
+ } else if sourceStat , err := preprocessedSourceFile .Stat (); err == nil && unpreprocessedStat .ModTime ().Before (sourceStat .ModTime ()) {
66
64
fmt .Fprintln (stdout , i18n .Tr ("Sketch is unchanged, skipping preprocessing." ))
67
65
res := & runner.Result {Stdout : stdout .Bytes (), Stderr : stderr .Bytes ()}
68
66
return res , nil
69
67
}
70
68
71
69
// Run GCC preprocessor
72
- result := GCC (sourceFile , ctagsTarget , includes , buildProperties ).Run (ctx )
70
+ result := GCC (unpreprocessedSourceFile , ctagsTarget , includes , buildProperties ).Run (ctx )
73
71
stdout .Write (result .Stdout )
74
72
stderr .Write (result .Stderr )
75
73
if err := result .Error ; err != nil {
@@ -81,7 +79,7 @@ func PreprocessSketchWithCtags(
81
79
fmt .Fprintf (stderr , "%s: %s" ,
82
80
i18n .Tr ("An error occurred adding prototypes" ),
83
81
i18n .Tr ("the compilation database may be incomplete or inaccurate" ))
84
- if err := sourceFile .CopyTo (ctagsTarget ); err != nil {
82
+ if err := unpreprocessedSourceFile .CopyTo (ctagsTarget ); err != nil {
85
83
return & runner.Result {Args : result .Args , Stdout : stdout .Bytes (), Stderr : stderr .Bytes ()}, err
86
84
}
87
85
}
@@ -114,7 +112,7 @@ func PreprocessSketchWithCtags(
114
112
115
113
// Add prototypes to the original sketch source
116
114
var source string
117
- if sourceData , err := sourceFile .ReadFile (); err == nil {
115
+ if sourceData , err := unpreprocessedSourceFile .ReadFile (); err == nil {
118
116
source = string (sourceData )
119
117
} else {
120
118
return & runner.Result {Args : result .Args , Stdout : stdout .Bytes (), Stderr : stderr .Bytes ()}, err
@@ -148,7 +146,7 @@ func PreprocessSketchWithCtags(
148
146
}
149
147
150
148
// Write back arduino-preprocess output to the sourceFile
151
- err = sourceFile .WriteFile ([]byte (preprocessedSource ))
149
+ err = preprocessedSourceFile .WriteFile ([]byte (preprocessedSource ))
152
150
return & runner.Result {Args : result .Args , Stdout : stdout .Bytes (), Stderr : stderr .Bytes ()}, err
153
151
}
154
152
0 commit comments