MCPcopy Create free account
hub / github.com/celer-pkg/celer / setupEnvs

Method setupEnvs

buildsystems/buildconfig_envs.go:48–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func (b *BuildConfig) setupEnvs() {
49 b.envBackup.backup()
50
51 // Setup environments if defined.
52 toolchain := b.Ctx.Platform().GetToolchain()
53 if toolchain != nil {
54 toolchain.SetupEnvs()
55 }
56
57 for _, env := range b.Envs {
58 env = strings.TrimSpace(env)
59
60 before, after, ok := strings.Cut(env, "=")
61 if !ok {
62 color.Printf(color.Warning, "invalid environment variable `%s` and is ignored.", env)
63 continue
64 }
65
66 key := strings.TrimSpace(before)
67 currentValue := strings.TrimSpace(after)
68 currentValue = b.expandVariables(currentValue)
69
70 switch key {
71 case "CPATH", "LIBRARY_PATH", "PATH":
72 lastValue := filepath.ToSlash(os.Getenv(key))
73 if strings.TrimSpace(lastValue) == "" {
74 b.envBackup.setenv(key, currentValue)
75 } else {
76 b.envBackup.setenv(key, fmt.Sprintf("%s%s%s", currentValue, string(os.PathListSeparator), lastValue))
77 }
78
79 case "CFLAGS", "CXXFLAGS", "LDFLAGS", "CPPFLAGS":
80 // celer can wrap CFLAGS, CXXFLAGS and CPPFLAGS automatically, so we need to remove them.
81 currentValue = strings.ReplaceAll(currentValue, "${CFLAGS}", "")
82 currentValue = strings.ReplaceAll(currentValue, "${CXXFLAGS}", "")
83 currentValue = strings.ReplaceAll(currentValue, "${CPPFLAGS}", "")
84 currentValue = strings.ReplaceAll(currentValue, "${LDFLAGS}", "")
85
86 lastValue := filepath.ToSlash(os.Getenv(key))
87 if strings.TrimSpace(lastValue) == "" {
88 b.envBackup.setenv(key, strings.TrimSpace(currentValue))
89 } else {
90 b.envBackup.setenv(key, fmt.Sprintf("%s %s", lastValue, currentValue))
91 }
92
93 default:
94 b.envBackup.setenv(key, currentValue)
95 }
96 }
97
98 if b.buildSystem.Name() != "cmake" {
99 // This allows the bin to locate the libraries in the relative lib dir.
100 toolchain := b.Ctx.Platform().GetToolchain()
101 if strings.ToLower(toolchain.GetSystemName()) == "linux" &&
102 b.buildSystem.Name() == "makefiles" {
103 b.envBackup.setenv("LDFLAGS", env.JoinSpace("-Wl,-rpath=\\$$ORIGIN/../lib", os.Getenv("LDFLAGS")))
104 }
105

Callers 1

InstallMethod · 0.95

Calls 15

expandVariablesMethod · 0.95
setLanguageStandardMethod · 0.95
setEnvFlagsMethod · 0.95
setupPkgConfigMethod · 0.95
setupRuntimePathMethod · 0.95
setupPythonEnvsMethod · 0.95
setupQNXEnvsMethod · 0.95
PrintfFunction · 0.92
JoinSpaceFunction · 0.92
PathExistsFunction · 0.92
JoinPathsFunction · 0.92
IfFunction · 0.92

Tested by

no test coverage detected