diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a93c74c80..a7cfb0ab3 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -14,7 +14,10 @@ on: workflow_dispatch: permissions: - contents: read + contents: read + +env: + GCC_VERSION: 12 # 这里修改 10 /11 /12 /13 切换编译器版本 # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -23,12 +26,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - - name: Install GCC-10 + - name: Install GCC ${{ env.GCC_VERSION }} run: | sudo apt-get update - sudo apt install gcc-10 g++-10 -y - gcc --version - g++ --version + sudo apt install gcc-${{ env.GCC_VERSION }} g++-${{ env.GCC_VERSION }} -y + gcc-${{ env.GCC_VERSION }} --version + g++-${{ env.GCC_VERSION }} --version ls /usr/bin/gcc* shell: bash - name: Install Third party library @@ -41,9 +44,9 @@ jobs: sudo apt-get install libhdf5-dev libcgns-dev libmetis-dev libmpich-dev -y shell: bash - name: CMake Build and Install - #env: - # CC: gcc-10 - # CXX: g++-10 + env: + CC: gcc-${{ env.GCC_VERSION }} + CXX: g++-${{ env.GCC_VERSION }} run: | cd ${{ github.workspace }} ls diff --git a/codes/project/include/FileUtil.h b/codes/project/include/FileUtil.h index 37b385c47..90587b629 100644 --- a/codes/project/include/FileUtil.h +++ b/codes/project/include/FileUtil.h @@ -28,13 +28,15 @@ License #include #include #include +#include BeginNameSpace( ONEFLOW ) bool DirExist( const std::string & dirName ); -void MakeDir( const std::string & dirName ); +bool MakeDir( const std::string & dirName ); -std::string HX_GetExePath(); +//std::string HX_GetExeDirectory(); +std::filesystem::path HX_GetExeDirectory(); std::string HX_GetCurrentDir(); bool EndWithSlash( const std::string & fileName ); diff --git a/codes/project/src/FileUtil.cpp b/codes/project/src/FileUtil.cpp index f34add3ca..7f07eac42 100644 --- a/codes/project/src/FileUtil.cpp +++ b/codes/project/src/FileUtil.cpp @@ -38,63 +38,80 @@ License #endif #endif +#include +#include #include +#include BeginNameSpace( ONEFLOW ) -bool DirExist( const std::string & dirName ) +bool DirExist(const std::string& dirName) { -#ifdef _WINDOWS - bool flag = ( _access( dirName.c_str(), 0 ) == 0 ); - return flag; -#else - bool flag = ( access( dirName.c_str(), 0 ) == 0 ); - return flag; -#endif + std::error_code ec; + return std::filesystem::is_directory(dirName, ec) && !ec; } -void MakeDir( const std::string & dirName ) +bool MakeDir(const std::string& dirName) { - int flag; -#ifdef _WINDOWS - flag = _mkdir( dirName.c_str() ); -#else - #ifdef WIN_GNU - flag = _mkdir( dirName.c_str() ); - #else - flag = mkdir( dirName.c_str(), S_IRWXU ); - #endif -#endif - - if ( flag == 0 ) - { - std::cout << dirName << " directory has been created successfully !\n"; + try { + if (std::filesystem::exists(dirName)) { + if (std::filesystem::is_directory(dirName)) { + std::cout << "Directory already exists: " << dirName << std::endl; + return true; + } else { + std::cerr << "Path exists but is not a directory: " << dirName << std::endl; + return false; + } + } + + // Ŀ¼ĬȨޣֵ֧ݹ飩 + if (std::filesystem::create_directories(dirName)) { + std::cout << "Directory created successfully: " << dirName << std::endl; + return true; + } else { + std::cerr << "Failed to create directory: " << dirName << std::endl; + return false; + } + } catch (const std::filesystem::filesystem_error& e) { + std::cerr << "Filesystem error: " << e.what() << std::endl; + return false; } } -std::string HX_GetExePath() +std::filesystem::path HX_GetExeDirectory() { - char buffer[ FILENAME_MAX ] = { 0 }; #ifdef _WIN32 - GetModuleFileName( NULL, buffer, FILENAME_MAX ); + std::wstring wbuf(MAX_PATH, L'\0'); + DWORD len = 0; + while (true) { + len = GetModuleFileNameW(nullptr, wbuf.data(), static_cast(wbuf.size())); + if (len == 0) return {}; + if (len < wbuf.size()) break; + wbuf.resize(wbuf.size() * 2); + } + return std::filesystem::path(wbuf.substr(0, len)).parent_path(); #else - std::size_t count = readlink( "/proc/self/exe", buffer, FILENAME_MAX ); + std::vector buf(PATH_MAX); + ssize_t count = -1; + while (true) { + count = readlink("/proc/self/exe", buf.data(), buf.size()); + if (count < 0) return {}; + if (static_cast(count) < buf.size()) break; + buf.resize(buf.size() * 2); + } + buf[count] = '\0'; + return std::filesystem::path(std::string(buf.data(), count)).parent_path(); #endif - std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" ); - return std::string( buffer ).substr( 0, pos); } std::string HX_GetCurrentDir() { -#ifdef _WINDOWS - char * cwd = _getcwd( 0, 0 ); -#else - char * cwd = getcwd( 0, 0 ); -#endif - std::string working_dir( cwd ) ; - std::free( cwd ) ; - return working_dir ; + try { + return std::filesystem::current_path().string(); + } catch (const std::filesystem::filesystem_error&) { + return {}; // or rethrow / log the error + } } bool EndWithSlash( const std::string & fileName ) diff --git a/codes/project/src/Prj.cpp b/codes/project/src/Prj.cpp index 09495a1a3..aacab215b 100644 --- a/codes/project/src/Prj.cpp +++ b/codes/project/src/Prj.cpp @@ -60,7 +60,7 @@ void Prj::ProcessCmdLineArgs( std::vector &args ) void Prj::Init() { - Prj::execute_dir = HX_GetExePath(); + Prj::execute_dir = HX_GetExeDirectory().string(); Prj::current_dir = HX_GetCurrentDir(); std::cout << " Prj::execute_dir = " << Prj::execute_dir << "\n"; diff --git a/doc/source/conf.py b/doc/source/conf.py index 7acd13cac..a3285a565 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -7,7 +7,7 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = 'Scientific Computing' -copyright = '2017~2024, eric' +copyright = '2017-2026, eric' author = 'eric' release = '1.0'