From 97901a0c0c99ad1e663a38c29f42c22132422c82 Mon Sep 17 00:00:00 2001
From: Michael Wetter
Date: Fri, 10 Jan 2025 07:19:47 -0800
Subject: [PATCH] Spawn, improve error check if run from directory with spaces
(#4089)
* Improved test for spaces in directory names that can fail Spawn simulation
For #3993
---
.../libModelicaBuildingsEnergyPlus_24_2_0.so | 4 +--
.../ModelicaBuildingsEnergyPlus_24_2_0.dll | 4 +--
Buildings/Resources/Scripts/travis/Makefile | 2 +-
.../C-Sources/BuildingInstantiate.c | 30 +------------------
.../EnergyPlus_24_2_0/C-Sources/SpawnUtil.c | 9 ++++++
.../EnergyPlus_24_2_0/UsersGuide.mo | 10 +++++++
.../UsersGuide/ReleaseNotes/Version_12_0_0.mo | 5 +++-
7 files changed, 29 insertions(+), 35 deletions(-)
diff --git a/Buildings/Resources/Library/linux64/libModelicaBuildingsEnergyPlus_24_2_0.so b/Buildings/Resources/Library/linux64/libModelicaBuildingsEnergyPlus_24_2_0.so
index 874b47a7ad0..f1eef69964f 100644
--- a/Buildings/Resources/Library/linux64/libModelicaBuildingsEnergyPlus_24_2_0.so
+++ b/Buildings/Resources/Library/linux64/libModelicaBuildingsEnergyPlus_24_2_0.so
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:bfe26f706fd2494f0471000932798630934b208e10610c7892524f4e5c251bfa
-size 81672
+oid sha256:7008f7136f365720a64f59a4432d1ddb9b277095af99baa0873b2c0e392bd530
+size 81608
diff --git a/Buildings/Resources/Library/win64/ModelicaBuildingsEnergyPlus_24_2_0.dll b/Buildings/Resources/Library/win64/ModelicaBuildingsEnergyPlus_24_2_0.dll
index acbcedd4ad4..28f0747df07 100644
--- a/Buildings/Resources/Library/win64/ModelicaBuildingsEnergyPlus_24_2_0.dll
+++ b/Buildings/Resources/Library/win64/ModelicaBuildingsEnergyPlus_24_2_0.dll
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:c9ea522ad08afebf17d60498846d319e02d748f506e341163c13013670b6d688
-size 150528
+oid sha256:60e3818ab0f27695e28ce99c60e4d556c315bc75cbf250641a978272dc93212d
+size 149504
diff --git a/Buildings/Resources/Scripts/travis/Makefile b/Buildings/Resources/Scripts/travis/Makefile
index e1beca50272..e49f5fc65cd 100644
--- a/Buildings/Resources/Scripts/travis/Makefile
+++ b/Buildings/Resources/Scripts/travis/Makefile
@@ -120,7 +120,7 @@ test-openmodelica-spawn-spaces-failure:
"simulate(SpawnTest);\n" \
"getErrorString();" > openmod.mos )
@(cd $(TMP) && omc openmod.mos > /dev/null )
- @cd $(TMP) && sudo grep -q "To use EnergyPlus, the Modelica Buildings Library must be installed in a directory that has no spaces." SpawnTest.log
+ @cd $(TMP) && sudo grep -q "To run a simulation with EnergyPlus coupling, the working directory must not have spaces." SpawnTest.log
@sudo rm -rf $(TMP)
@echo " Success."
diff --git a/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/BuildingInstantiate.c b/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/BuildingInstantiate.c
index b9818c90fe7..2cdf44936d6 100644
--- a/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/BuildingInstantiate.c
+++ b/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/BuildingInstantiate.c
@@ -543,34 +543,6 @@ char* findSpawnExe(FMUBuilding* bui, const char* SEARCHPATH, const char* spawnEx
return spawnFullPath;
}
-
-void terminateIfSpacesInInstallation(FMUBuilding* bui){
- const char sep = '/';
- char* libBaseName;
- void (*SpawnFormatError)(const char *string, ...) = bui->SpawnFormatError;
- size_t lasPosInd;
-
- const char* ptr = strrchr(bui->buildingsLibraryRoot, sep);
-
- if (ptr == NULL){
- SpawnFormatError("Error. Expected separator '%c' in '%s'.", sep, bui->buildingsLibraryRoot);
- }
-
- /* Index of last position of the separator */
- lasPosInd = (size_t)(ptr - bui->buildingsLibraryRoot);
-
- mallocString(lasPosInd + 1, "Failed to allocate memory in terminateIfSpacesInInstallation().", &libBaseName, SpawnFormatError);
- /* Copy the path except for the last part of the path, which is Buildings or Buildings 8.0.0 */
- memcpy(libBaseName, bui->buildingsLibraryRoot, lasPosInd);
- libBaseName[lasPosInd] = '\0';
-
-
- if ( strchr(libBaseName, ' ') != NULL){
- SpawnFormatError("To use EnergyPlus, the Modelica Buildings Library must be installed in a directory that has no spaces. (The Buildings directory can however have spaces such as in 'Buildings 9.0.0'.) Installing in '%s' is not supported.",
- libBaseName);
- }
-}
-
void generateFMU(FMUBuilding* bui, const char* spawnFullPath, const char* modelicaBuildingsJsonFile){
/* Generate the FMU */
char* optionFlags;
@@ -962,7 +934,7 @@ void generateAndInstantiateBuilding(FMUBuilding* bui){
if (spawnFullPath == NULL){
SpawnFormatError("Failed to find spawn executable in Buildings Library installation, on SPAWNPATH and on PATH. See installation instructions at Buildings.ThermalZones.EnergyPlus_%s.UsersGuide.Installation", bui->idfVersion);
}
- terminateIfSpacesInInstallation(bui);
+
/* Generate FMU using spawnFullPath */
generateFMU(bui, spawnFullPath, modelicaBuildingsJsonFile);
free(spawnFullPath);
diff --git a/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/SpawnUtil.c b/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/SpawnUtil.c
index db8dec197b4..f994e54e994 100644
--- a/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/SpawnUtil.c
+++ b/Buildings/Resources/src/ThermalZones/EnergyPlus_24_2_0/C-Sources/SpawnUtil.c
@@ -612,6 +612,15 @@ void getSimulationTemporaryDirectory(
replaceChar(curDir, '\\', '/');
#endif
+ /* Ensure that there are no spaces in the current working directory.
+ See https://github.com/lbl-srg/modelica-buildings/issues/3993
+ */
+ if(strchr(curDir, ' ') != NULL){
+ SpawnFormatError(
+ "To run a simulation with EnergyPlus coupling, the working directory must not have spaces. Working directory is '%s'.",
+ curDir);
+ }
+
/* Reduced the name of modelicaNameBuilding because Windows has limits on the length
of the file name.
*/
diff --git a/Buildings/ThermalZones/EnergyPlus_24_2_0/UsersGuide.mo b/Buildings/ThermalZones/EnergyPlus_24_2_0/UsersGuide.mo
index c073329da62..ed09b1788e9 100644
--- a/Buildings/ThermalZones/EnergyPlus_24_2_0/UsersGuide.mo
+++ b/Buildings/ThermalZones/EnergyPlus_24_2_0/UsersGuide.mo
@@ -579,6 +579,16 @@ of the current EnergyPlus time step.
This will be addressed through
issue 2000.
+Running Spawn from a directory with spaces
+
+Spawn stops with an error message if run from a directory that contains spaces (because loading the FMU would fail).
+Therefore, make sure the working directory has no spaces.
+The installation directory of the Buildings library however is allowed to have spaces.
+
+
+This error check has been introduced in
+issue 3993.
+