Merge branch 'temp_file_generation' into 'master'

util function GetTempFilename()

See merge request jschoeberl/netgen!446
This commit is contained in:
Matthias Hochsteger 2021-11-05 16:41:11 +00:00
commit 8efcd93db6
6 changed files with 41 additions and 22 deletions

View File

@ -246,7 +246,7 @@ build_mac:
-DUSE_NATIVE_ARCH=OFF -DUSE_NATIVE_ARCH=OFF
-DUSE_CCACHE=ON -DUSE_CCACHE=ON
-DENABLE_UNIT_TESTS=ON -DENABLE_UNIT_TESTS=ON
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15
-DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
-DUSE_CGNS=ON -DUSE_CGNS=ON
-DUSE_OCC=ON -DUSE_OCC=ON

View File

@ -8,20 +8,27 @@ set (NETGEN_DEPENDENCIES)
set (LAPACK_DEPENDENCIES) set (LAPACK_DEPENDENCIES)
set (NETGEN_CMAKE_ARGS "" CACHE INTERNAL "") set (NETGEN_CMAKE_ARGS "" CACHE INTERNAL "")
set (SUBPROJECT_CMAKE_ARGS "" CACHE INTERNAL "") set (SUBPROJECT_CMAKE_ARGS "" CACHE INTERNAL "")
set (SUBPROJECT_ARGS set (SUBPROJECT_ARGS
LIST_SEPARATOR |
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dependencies
)
# only show output on failure in ci-builds
if(DEFINED ENV{CI} AND WIN32)
set (SUBPROJECT_ARGS
LOG_DOWNLOAD ON LOG_DOWNLOAD ON
LOG_BUILD ON LOG_BUILD ON
LOG_INSTALL ON LOG_INSTALL ON
LOG_CONFIGURE ON LOG_CONFIGURE ON
LIST_SEPARATOR | )
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/dependencies if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0")
)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0")
set (SUBPROJECT_ARGS set (SUBPROJECT_ARGS
${SUBPROJECT_ARGS} ${SUBPROJECT_ARGS}
LOG_OUTPUT_ON_FAILURE 1 LOG_OUTPUT_ON_FAILURE ON
LOG_MERGED_STDOUTERR 1 LOG_MERGED_STDOUTERR ON
) )
endif()
endif() endif()

View File

@ -7,6 +7,7 @@
#include <cxxabi.h> #include <cxxabi.h>
#endif #endif
#include <array> #include <array>
#include <filesystem>
#include <iostream> #include <iostream>
#include <regex> #include <regex>
@ -111,5 +112,14 @@ namespace ngcore
#endif #endif
} }
NGCORE_API std::string GetTempFilename()
{
static int counter = 0;
auto path = std::filesystem::temp_directory_path();
std::string filename = ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter());
path.append(filename);
return path.string();
}
} // namespace ngcore } // namespace ngcore

View File

@ -201,6 +201,8 @@ namespace ngcore
NGCORE_API int GetCompiledSIMDSize(); NGCORE_API int GetCompiledSIMDSize();
NGCORE_API bool IsRangeCheckEnabled(); NGCORE_API bool IsRangeCheckEnabled();
NGCORE_API std::string GetTempFilename();
} // namespace ngcore } // namespace ngcore
#endif // NETGEN_CORE_UTILS_HPP #endif // NETGEN_CORE_UTILS_HPP

View File

@ -58,11 +58,11 @@ namespace netgen
OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape, int aoccdim) OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape, int aoccdim)
{ {
auto filename = ".tmpfile_out.step"; auto filename = GetTempFilename();
step_utils::WriteSTEP(_shape, filename); step_utils::WriteSTEP(_shape, filename.c_str());
LoadOCCInto(this, filename); LoadOCCInto(this, filename.c_str());
occdim = aoccdim; occdim = aoccdim;
std::remove(filename); std::remove(filename.c_str());
} }
string STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader) string STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader)
@ -1650,24 +1650,24 @@ namespace netgen
std::stringstream ss; std::stringstream ss;
STEPControl_Writer writer; STEPControl_Writer writer;
writer.Transfer(shape, STEPControl_AsIs); writer.Transfer(shape, STEPControl_AsIs);
auto filename = ".tmpfile_out.step"; auto filename = GetTempFilename();
writer.Write(filename); writer.Write(filename.c_str());
std::ifstream is(filename); std::ifstream is(filename.c_str());
ss << is.rdbuf(); ss << is.rdbuf();
ar << ss.str(); ar << ss.str();
std::remove(filename); std::remove(filename.c_str());
} }
else else
{ {
std::string str; std::string str;
ar & str; ar & str;
auto filename = ".tmpfile.step"; auto filename = GetTempFilename();
auto tmpfile = std::fopen(filename, "w"); auto tmpfile = std::fopen(filename.c_str(), "w");
std::fputs(str.c_str(), tmpfile); std::fputs(str.c_str(), tmpfile);
std::fclose(tmpfile); std::fclose(tmpfile);
LoadOCCInto(this, filename); LoadOCCInto(this, filename.c_str());
std::remove(filename); std::remove(filename.c_str());
} }
} }

View File

@ -9,5 +9,5 @@ $PYDIR/python3 --version
$PYDIR/pip3 install --user numpy twine scikit-build wheel $PYDIR/pip3 install --user numpy twine scikit-build wheel
export CMAKE_OSX_ARCHITECTURES='arm64;x86_64' export CMAKE_OSX_ARCHITECTURES='arm64;x86_64'
$PYDIR/python3 setup.py bdist_wheel --plat-name macosx-10.14-universal2 -j10 $PYDIR/python3 setup.py bdist_wheel --plat-name macosx-10.15-universal2 -j10
$PYDIR/python3 -m twine upload --repository testpypi dist/*.whl $PYDIR/python3 -m twine upload --repository testpypi dist/*.whl