Skip to content

Commit 88672d0

Browse files
authored
Env Check: Re-enable validation of Spack build env context (#4)
The shell script version of the Spack compiler wrapper (in the main Spack repo) validates that there is a well formed Spack env by testing for the presence of environment variables. Re-enable the same functionality in the MSVC wrapper. Additionally updates the MSVC wrapper validation to reflect the current state of env validation in the sh wrapper.
1 parent 457f4af commit 88672d0

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

src/main.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ int main(int argc, const char* argv[]) {
5858
}
5959
else {
6060
// Ensure required variables are set
61-
// if(!ValidateSpackEnv()) {
62-
// return -99;
63-
// }
61+
if(!ValidateSpackEnv()) {
62+
return -99;
63+
}
6464
// Determine which tool we're trying to run
6565
std::unique_ptr<ToolChainInvocation> tchain(ToolChainFactory::ParseToolChain(argv));
6666
if(!tchain) {

src/utils.cxx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,20 @@ StrList GetEnvList(const std::string &envVar, const std::string &delim) {
206206
return StrList();
207207
}
208208

209-
int ValidateSpackEnv() {
209+
bool ValidateSpackEnv() {
210210
std::vector<std::string> SpackEnv{
211-
"SPACK_ENV_PATH",
211+
"SPACK_COMPILER_WRAPPER_PATH",
212212
"SPACK_DEBUG_LOG_DIR",
213-
// "SPACK_DEBUG_LOG_ID"
214-
"SPACK_COMPILER_SPEC",
215-
// "SPACK_CC_RPATH_ARG"
216-
// "SPACK_CXX_RPATH_ARG"
217-
// "SPACK_F77_RPATH_ARG"
218-
// "SPACK_FC_RPATH_ARG"
219-
// "SPACK_LINKER_ARG"
220-
// "SPACK_SHORT_SPEC"
213+
"SPACK_DEBUG_LOG_ID",
214+
"SPACK_SHORT_SPEC",
221215
"SPACK_SYSTEM_DIRS",
222-
"SPACK_CC",
223-
"SPACK_LD",};
216+
"SPACK_MANAGED_DIRS"};
224217
for(auto &var: SpackEnv)
225218
if(!getenv(var.c_str())){
226219
std::cerr << var + " isn't set in the environment and is expected to be\n";
227-
return 0;
220+
return false;
228221
}
229-
return 1;
222+
return true;
230223
}
231224

232225
std::string stem(const std::string &file)
@@ -301,8 +294,9 @@ std::string LibraryFinder::FindLibrary(const std::string &lib_name, const std::s
301294
// next search the CWD
302295
std::string cwd(GetCWD());
303296
auto res = this->Finder(cwd, lib_name);
304-
if (!res.empty())
305-
return res;
297+
if (!res.empty()){
298+
return res;
299+
}
306300
this->EvalSearchPaths();
307301
if (this->evald_search_paths.empty()) {
308302
return std::string();
@@ -312,8 +306,9 @@ std::string LibraryFinder::FindLibrary(const std::string &lib_name, const std::s
312306
std::vector<std::string> searchable_paths = this->evald_search_paths.at(var);
313307
for (std::string pth: searchable_paths) {
314308
auto res = this->Finder(pth, lib_name);
315-
if (!res.empty())
309+
if (!res.empty()){
316310
return res;
311+
}
317312
}
318313
}
319314
return std::string();
@@ -324,8 +319,10 @@ void LibraryFinder::EvalSearchPaths() {
324319
return;
325320
for (std::string var: this->search_vars) {
326321
std::string envVal = GetSpackEnv(var.c_str());
327-
if (!envVal.empty())
322+
if (!envVal.empty()) {
328323
this->evald_search_paths[var] = split(envVal, ";");
324+
}
325+
329326
}
330327
}
331328

src/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef std::vector<std::string> StrList;
2929
std::string GetSpackEnv(const char* env);
3030
std::string GetSpackEnv(const std::string &env);
3131
StrList GetEnvList(const std::string &envVar, const std::string &delim = ";");
32-
int ValidateSpackEnv();
32+
bool ValidateSpackEnv();
3333

3434
// String helper methods adding cxx20 features to cxx14 //
3535

test/setup_and_drive_test.bat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ FOR /F "tokens=* USEBACKQ" %%F IN (`where link`) DO (
1111
SET SPACK_LD=%%F
1212
)
1313
popd
14-
SET SPACK_ENV_PATH=%PATH%
14+
SET SPACK_COMPILER_WRAPPER_PATH=%~dp0..
1515
SET SPACK_DEBUG_LOG_DIR=%CD%
16-
SET SPACK_COMPILER_SPEC=%msvc
16+
SET SPACK_DEBUG_LOG_ID=TEST
17+
SET SPACK_SHORT_SPEC=test%msvc
1718
SET SPACK_SYSTEM_DIRS=%PATH%
19+
SET SPACK_MANAGED_DIRS=%CD%\tmp
1820
SET SPACK_RELOCATE_PATH=%CD%\tmp
1921

2022
nmake test

0 commit comments

Comments
 (0)