Skip to content

Commit 0d09a41

Browse files
committed
Inlined FixLDflags
1 parent 3985c7b commit 0d09a41

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

Diff for: legacy/builder/phases/libraries_builder.go

+32-35
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import (
3030
"github.com/pkg/errors"
3131
)
3232

33-
var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map[string]bool{".a": true}
34-
var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC = map[string]bool{".so": true}
3533
var FLOAT_ABI_CFLAG = "float-abi"
3634
var FPU_CFLAG = "fpu"
3735

@@ -105,33 +103,6 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
105103
return nil
106104
}
107105

108-
func fixLDFLAG(ctx *types.Context, library *libraries.Library, path *paths.Path) {
109-
// find all library names in the folder and prepend -l
110-
filePaths := []string{}
111-
libsCmd := library.LDflags + " "
112-
extensions := func(ext string) bool {
113-
return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC[ext] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext]
114-
}
115-
utils.FindFilesInFolder(&filePaths, path.String(), extensions, false)
116-
for _, lib := range filePaths {
117-
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
118-
// strip "lib" first occurrence
119-
if strings.HasPrefix(name, "lib") {
120-
name = strings.Replace(name, "lib", "", 1)
121-
libsCmd += "-l" + name + " "
122-
}
123-
}
124-
125-
key := "compiler.libraries.ldflags"
126-
if !ctx.BuildProperties.ContainsKey(key) {
127-
logger := ctx.GetLogger()
128-
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'.")
129-
key = "compiler.ldflags"
130-
}
131-
currLDFlags := ctx.BuildProperties.Get(key)
132-
ctx.BuildProperties.Set(key, currLDFlags+" \"-L"+path.String()+"\" "+libsCmd+" ")
133-
}
134-
135106
func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
136107
ctx.Progress.AddSubSteps(len(libraries))
137108
defer ctx.Progress.RemoveSubSteps()
@@ -166,19 +137,45 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
166137

167138
if library.Precompiled {
168139
if precompiledPath := findExpectedPrecompiledLibFolder(ctx, library); precompiledPath != nil {
140+
var staticLibExts = map[string]bool{".a": true}
141+
var dynamixLibExts = map[string]bool{".so": true}
142+
dynAndStatic := func(ext string) bool { return dynamixLibExts[ext] || staticLibExts[ext] }
143+
staticOnly := func(ext string) bool { return staticLibExts[ext] }
144+
169145
// Add required LD flags
170-
fixLDFLAG(ctx, library, precompiledPath)
146+
147+
// find all library names in the folder and prepend -l
148+
dynAndStaticLibs := []string{}
149+
libsCmd := library.LDflags + " "
150+
if err := utils.FindFilesInFolder(&dynAndStaticLibs, precompiledPath.String(), dynAndStatic, false); err != nil {
151+
return nil, errors.WithStack(err)
152+
}
153+
for _, lib := range dynAndStaticLibs {
154+
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
155+
// strip "lib" first occurrence
156+
if strings.HasPrefix(name, "lib") {
157+
name = strings.Replace(name, "lib", "", 1)
158+
libsCmd += "-l" + name + " "
159+
}
160+
}
161+
162+
key := "compiler.libraries.ldflags"
163+
if !ctx.BuildProperties.ContainsKey(key) {
164+
logger := ctx.GetLogger()
165+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'.")
166+
key = "compiler.ldflags"
167+
}
168+
currLDFlags := ctx.BuildProperties.Get(key)
169+
ctx.BuildProperties.Set(key, currLDFlags+" \"-L"+precompiledPath.String()+"\" "+libsCmd+" ")
171170

172171
// TODO: This codepath is just taken for .a with unusual names that would
173172
// be ignored by -L / -l methods.
174173
// Should we force precompiled libraries to start with "lib" ?
175-
extensions := func(ext string) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext] }
176-
filePaths := []string{}
177-
err := utils.FindFilesInFolder(&filePaths, precompiledPath.String(), extensions, false)
178-
if err != nil {
174+
staticLibs := []string{}
175+
if err := utils.FindFilesInFolder(&staticLibs, precompiledPath.String(), staticOnly, false); err != nil {
179176
return nil, errors.WithStack(err)
180177
}
181-
for _, path := range filePaths {
178+
for _, path := range staticLibs {
182179
if !strings.HasPrefix(filepath.Base(path), "lib") {
183180
objectFiles.Add(paths.New(path))
184181
}

0 commit comments

Comments
 (0)