Skip to content
Merged

Hexin #131

Show file tree
Hide file tree
Changes from all commits
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
19 changes: 11 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions codes/project/include/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ License
#include <set>
#include <vector>
#include <algorithm>
#include <filesystem>

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 );
Expand Down
91 changes: 54 additions & 37 deletions codes/project/src/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,63 +38,80 @@ License
#endif
#endif

#include <vector>
#include <climits>
#include <iostream>
#include <filesystem>

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<DWORD>(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<char> 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<size_t>(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 )
Expand Down
2 changes: 1 addition & 1 deletion codes/project/src/Prj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void Prj::ProcessCmdLineArgs( std::vector<std::string> &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";
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down