@@ -82,7 +82,7 @@ func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string
82
82
if err != nil {
83
83
return nil , utils .WrapError (err )
84
84
}
85
- return compileWithRecipe (objectFiles , sourcePath , sources , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
85
+ return compileFilesWithRecipe (objectFiles , sourcePath , sources , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
86
86
}
87
87
88
88
func findFilesInFolder (sourcePath string , extension string , recurse bool ) ([]string , error ) {
@@ -113,45 +113,54 @@ func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]str
113
113
return sources , nil
114
114
}
115
115
116
- func compileWithRecipe (objectFiles []string , sourcePath string , sources []string , buildPath string , buildProperties map [string ]string , includes []string , recipe string , verbose bool , warningsLevel string , logger i18n.Logger ) ([]string , error ) {
116
+ func compileFilesWithRecipe (objectFiles []string , sourcePath string , sources []string , buildPath string , buildProperties map [string ]string , includes []string , recipe string , verbose bool , warningsLevel string , logger i18n.Logger ) ([]string , error ) {
117
117
for _ , source := range sources {
118
- properties := utils .MergeMapsOfStrings (make (map [string ]string ), buildProperties )
119
- properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + warningsLevel ]
120
- properties [constants .BUILD_PROPERTIES_INCLUDES ] = strings .Join (includes , constants .SPACE )
121
- properties [constants .BUILD_PROPERTIES_SOURCE_FILE ] = source
122
- relativeSource , err := filepath .Rel (sourcePath , source )
118
+ objectFile , err := compileFileWithRecipe (sourcePath , source , buildPath , buildProperties , includes , recipe , verbose , warningsLevel , logger )
123
119
if err != nil {
124
120
return nil , utils .WrapError (err )
125
121
}
126
- properties [constants .BUILD_PROPERTIES_OBJECT_FILE ] = filepath .Join (buildPath , relativeSource + ".o" )
127
122
128
- err = os . MkdirAll ( filepath . Dir ( properties [ constants . BUILD_PROPERTIES_OBJECT_FILE ]), os . FileMode ( 0755 ) )
129
- if err != nil {
130
- return nil , utils . WrapError ( err )
131
- }
123
+ objectFiles = append ( objectFiles , objectFile )
124
+ }
125
+ return objectFiles , nil
126
+ }
132
127
133
- sourceFileStat , err := os .Stat (properties [constants .BUILD_PROPERTIES_SOURCE_FILE ])
134
- if err != nil {
135
- return nil , utils .WrapError (err )
136
- }
128
+ func compileFileWithRecipe (sourcePath string , source string , buildPath string , buildProperties map [string ]string , includes []string , recipe string , verbose bool , warningsLevel string , logger i18n.Logger ) (string , error ) {
129
+ properties := utils .MergeMapsOfStrings (make (map [string ]string ), buildProperties )
130
+ properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS ] = properties [constants .BUILD_PROPERTIES_COMPILER_WARNING_FLAGS + "." + warningsLevel ]
131
+ properties [constants .BUILD_PROPERTIES_INCLUDES ] = strings .Join (includes , constants .SPACE )
132
+ properties [constants .BUILD_PROPERTIES_SOURCE_FILE ] = source
133
+ relativeSource , err := filepath .Rel (sourcePath , source )
134
+ if err != nil {
135
+ return "" , utils .WrapError (err )
136
+ }
137
+ properties [constants .BUILD_PROPERTIES_OBJECT_FILE ] = filepath .Join (buildPath , relativeSource + ".o" )
137
138
138
- objectFileStat , err : = os .Stat ( properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
139
- if err != nil && ! os . IsNotExist ( err ) {
140
- return nil , utils .WrapError (err )
141
- }
139
+ err = os .MkdirAll ( filepath . Dir ( properties [constants .BUILD_PROPERTIES_OBJECT_FILE ]), os . FileMode ( 0755 ) )
140
+ if err != nil {
141
+ return "" , utils .WrapError (err )
142
+ }
142
143
143
- if ! objFileIsUpToDateWithSourceFile (sourceFileStat , objectFileStat ) {
144
- _ , err = ExecRecipe (properties , recipe , false , verbose , verbose , logger )
145
- if err != nil {
146
- return nil , utils .WrapError (err )
147
- }
148
- } else if verbose {
149
- logger .Println (constants .MSG_USING_PREVIOUS_COMPILED_FILE , properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
150
- }
144
+ sourceFileStat , err := os .Stat (properties [constants .BUILD_PROPERTIES_SOURCE_FILE ])
145
+ if err != nil {
146
+ return "" , utils .WrapError (err )
147
+ }
151
148
152
- objectFiles = append (objectFiles , properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
149
+ objectFileStat , err := os .Stat (properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
150
+ if err != nil && ! os .IsNotExist (err ) {
151
+ return "" , utils .WrapError (err )
153
152
}
154
- return objectFiles , nil
153
+
154
+ if ! objFileIsUpToDateWithSourceFile (sourceFileStat , objectFileStat ) {
155
+ _ , err = ExecRecipe (properties , recipe , false , verbose , verbose , logger )
156
+ if err != nil {
157
+ return "" , utils .WrapError (err )
158
+ }
159
+ } else if verbose {
160
+ logger .Println (constants .MSG_USING_PREVIOUS_COMPILED_FILE , properties [constants .BUILD_PROPERTIES_OBJECT_FILE ])
161
+ }
162
+
163
+ return properties [constants .BUILD_PROPERTIES_OBJECT_FILE ], nil
155
164
}
156
165
157
166
func objFileIsUpToDateWithSourceFile (sourceFileStat , objectFileStat os.FileInfo ) bool {
0 commit comments