Skip to content

Commit 6726a85

Browse files
Fix compilation of a library that contains a "utility" file
Libraries can contain a "utility" directory, which is then added to the include path and whose contents are compiled. However, the code that handled this only checked for existence of the "utility" path, not if it was actually a directory. If a file with that name existed, it would be treated as a directory, breaking the build. This happens for example with the StandardCplusplus library. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent edbf386 commit 6726a85

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/arduino.cc/builder/phases/libraries_builder.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,17 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr
107107
}
108108
} else {
109109
utilitySourcePath := filepath.Join(library.SrcFolder, constants.LIBRARY_FOLDER_UTILITY)
110-
_, utilitySourcePathErr := os.Stat(utilitySourcePath)
111-
if utilitySourcePathErr == nil {
110+
stat, err := os.Stat(utilitySourcePath)
111+
haveUtilityDir := err == nil && stat.IsDir()
112+
if haveUtilityDir {
112113
includes = append(includes, utils.WrapWithHyphenI(utilitySourcePath))
113114
}
114115
objectFiles, err = builder_utils.CompileFiles(objectFiles, library.SrcFolder, false, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
115116
if err != nil {
116117
return nil, i18n.WrapError(err)
117118
}
118119

119-
if utilitySourcePathErr == nil {
120+
if haveUtilityDir {
120121
utilityBuildPath := filepath.Join(libraryBuildPath, constants.LIBRARY_FOLDER_UTILITY)
121122
objectFiles, err = builder_utils.CompileFiles(objectFiles, utilitySourcePath, false, utilityBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
122123
if err != nil {

0 commit comments

Comments
 (0)