Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use 'hasEnv' for env value checks #541

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/android/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace SSC::android {

for (auto const &var : parseStringList(this->config["build_env"])) {
auto key = trim(var);

if (!hasEnv(key)) {
continue;
}

auto value = getEnv(key.c_str());

if (value.size() > 0) {
Expand Down
22 changes: 12 additions & 10 deletions src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1655,8 +1655,8 @@ int main (const int argc, const char* argv[]) {
auto parts = split(value, '=');
if (parts.size() == 2) {
stream << parts[0] << " = " << parts[1] << "\n";
} else if (parts.size() == 1) {
stream << parts[0] << " = " << getEnv(parts[0].c_str()) << "\n";
} else if (parts.size() == 1 && hasEnv(parts[0])) {
stream << parts[0] << " = " << getEnv(parts[0]) << "\n";
}
}

Expand Down Expand Up @@ -4553,14 +4553,16 @@ int main (const int argc, const char* argv[]) {
compilerFlags += " -stdlib=libstdc++";
}

if (CXX.ends_with("clang++")) {
compiler = CXX.substr(0, CXX.size() - 2);
} else if (CXX.ends_with("clang++.exe")) {
compiler = CXX.substr(0, CXX.size() - 6) + ".exe";
} else if (CXX.ends_with("g++")) {
compiler = CXX.substr(0, CXX.size() - 2) + "cc";
} else if (CXX.ends_with("g++.exe")) {
compiler = CXX.substr(0, CXX.size() - 6) + "cc.exe";
if (CXX.size() == 0) {
if (compiler.ends_with("clang++")) {
compiler = compiler.substr(0, compiler.size() - 2);
} else if (compiler.ends_with("clang++.exe")) {
compiler = compiler.substr(0, compiler.size() - 6) + ".exe";
} else if (compiler.ends_with("g++")) {
compiler = compiler.substr(0, compiler.size() - 2) + "cc";
} else if (compiler.ends_with("g++.exe")) {
compiler = compiler.substr(0, compiler.size() - 6) + "cc.exe";
}
}
} else if (source.ends_with(".o") || source.ends_with(".a")) {
objects << source << " ";
Expand Down
37 changes: 37 additions & 0 deletions src/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,43 @@ namespace SSC {
return r;
}

inline bool hasEnv (const char* variableName) {
static auto appData = getUserConfig();

if (appData[String("env_") + variableName].size() > 0) {
return true;
}

#if defined(_WIN32)
char* value = nullptr;
size_t size = 0;
auto result = _dupenv_s(&value, &size, variableName);

if (value && value[0] == '\0') {
free(value);
return false;
}

free(value);

if (size == 0 || result != 0) {
return false;
}
#else
auto value = getenv(variableName);

if (value == nullptr || value[0] == '\0') {
return false;
}
#endif

return true;
}

inline bool hasEnv (const String& variableName) {
return hasEnv(variableName.c_str());
}

inline String getEnv (const char* variableName) {
static auto appData = getUserConfig();

Expand Down
5 changes: 5 additions & 0 deletions src/desktop/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ MAIN {
SSC::StringStream env;
for (auto const &envKey : parseStringList(app.appData["build_env"])) {
auto cleanKey = trim(envKey);

if (!hasEnv(cleanKey)) {
continue;
}

auto envValue = getEnv(cleanKey.c_str());

env << SSC::String(
Expand Down
5 changes: 5 additions & 0 deletions src/ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ - (BOOL) application: (UIApplication*) application

for (auto const &envKey : parseStringList(appData["build_env"])) {
auto cleanKey = trim(envKey);

if (!hasEnv(cleanKey)) {
continue;
}

auto envValue = getEnv(cleanKey.c_str());

env << String(
Expand Down
10 changes: 10 additions & 0 deletions src/window/window.hh
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ namespace SSC {
if (opts.appData.size() > 0) {
for (auto const &envKey : parseStringList(opts.appData["build_env"])) {
auto cleanKey = trim(envKey);

if (!hasEnv(cleanKey)) {
continue;
}

auto envValue = getEnv(cleanKey.c_str());

env << String(
Expand All @@ -454,6 +459,11 @@ namespace SSC {
} else {
for (auto const &envKey : parseStringList(this->options.appData["build_env"])) {
auto cleanKey = trim(envKey);

if (!hasEnv(cleanKey)) {
continue;
}

auto envValue = getEnv(cleanKey.c_str());

env << String(
Expand Down
Loading