This commit is contained in:
vrd
2025-06-06 18:00:38 +03:00
parent 96f29e01bb
commit 4619776fa5
5 changed files with 30 additions and 24 deletions
+7 -3
View File
@@ -2,14 +2,18 @@
set -e set -e
# Test cppipe functions # Test cppipe functions
OKs=$(cppipe test/functions_test.cppipe | grep OK | wc -l) OKs=$(cppipe test/functions_test.cppipe 2>/dev/null | grep OK | wc -l)
if ! [ $OKs = 12 ] if ! [ $OKs = 12 ]
then then
echo "EXPECTED 1 OKs, got $OKs" echo "Functions test failed: EXPECTED 12 OKs, got $OKs"
exit 1 exit 1
fi fi
echo Functions test OK!
# Test on a C file # Test on a C file
echo OK | cppipe test/c_file.c cppipe test/c_file.c
# Test the cppipe command
./test/command_line_test.sh
echo ALL TESTS PASSED echo ALL TESTS PASSED
+13 -17
View File
@@ -59,6 +59,7 @@ SrcType find_src_type(string_view path);
const char DEBUG_PREFIX[] = "__DBG"; const char DEBUG_PREFIX[] = "__DBG";
// Context // Context
fs::path HOME;
bool debug = false; bool debug = false;
fs::path src_file; fs::path src_file;
SrcType src_type; SrcType src_type;
@@ -72,6 +73,7 @@ int main(int argc, char* argv[])
int src_arg = parse_args_until_src(argc, argv); int src_arg = parse_args_until_src(argc, argv);
// Init context // Init context
HOME = getenv("HOME");
src_file = find_path_to_src( argv[src_arg] ); src_file = find_path_to_src( argv[src_arg] );
src_type = find_src_type( argv[src_arg] ); src_type = find_src_type( argv[src_arg] );
cache_dir = get_cache_dir_path(src_file); cache_dir = get_cache_dir_path(src_file);
@@ -146,12 +148,6 @@ fs::path find_path_to_src(string_view src_file)
return src_file; return src_file;
} }
// Search in ~/cppipe
if(fs::path p = fs::path(getenv("HOME")) / "cppipe" / src_file; fs::exists(p))
{
return p;
}
// Search files on CPPIPEPATH // Search files on CPPIPEPATH
const char* cppipepath_var = getenv("CPPIPEPATH"); const char* cppipepath_var = getenv("CPPIPEPATH");
if(cppipepath_var) // is set if(cppipepath_var) // is set
@@ -161,16 +157,11 @@ fs::path find_path_to_src(string_view src_file)
; ;
begin = end+1, end = cppipepath.find(':', begin) ) begin = end+1, end = cppipepath.find(':', begin) )
{ {
const string_view path_entry = cppipepath.substr(begin, end - begin); const fs::path path_entry = cppipepath.substr(begin, end - begin);
if( fs::is_directory(path_entry) )
if( fs::path p = path_entry / src_file; fs::exists(p) )
{ {
for(const fs::directory_entry& e: fs::directory_iterator(path_entry)) return p;
{
if(fs::is_regular_file(e) && e.path().filename() == src_file)
{
return e;
}
}
} }
if(end == string::npos) if(end == string::npos)
@@ -178,6 +169,12 @@ fs::path find_path_to_src(string_view src_file)
} }
} }
// Search in ~/cppipe
if(fs::path p = HOME / "cppipe" / src_file; fs::exists(p)) // todo: what if ~/cppipe/../... matches
{
return p;
}
// Couln't find the src // Couln't find the src
cerr << "File: " << src_file << " doesn't exist\n"; cerr << "File: " << src_file << " doesn't exist\n";
exit(1); exit(1);
@@ -193,8 +190,7 @@ fs::path get_cache_dir_path(const fs::path& src_file)
} }
else else
{ {
char* home( getenv("HOME") ); cache_dir = HOME;
cache_dir = home;
cache_dir /= ".cache/cppipe"; cache_dir /= ".cache/cppipe";
} }
cache_dir += fs::canonical( src_file ).parent_path(); cache_dir += fs::canonical( src_file ).parent_path();
+1 -1
View File
@@ -8,7 +8,7 @@ int main()
x = y; /* should only work on C */ x = y; /* should only work on C */
if(x == 0) if(x == 0)
{ {
printf("C compilation OK!\n"); printf("C compilation: OK!\n");
} }
return 0; return 0;
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
set -e
export CPPIPEPATH="/:test::/usr"
cppipe c_file.c > /dev/null
echo Command line test: OK!
+1 -3
View File
@@ -3,20 +3,18 @@ tips (sigaction SIGCHILD, SIG_IGN, SIG_DFL)
make sure file descriptors are closed when no longer used make sure file descriptors are closed when no longer used
cppipe compile options from tft cppipe compile options from tft
respect CXXFLAGS LDFLAGS respect CXXFLAGS LDFLAGS
remove append_args
? ?
run(cmd)
string args string args
args before src file go to compiler args before src file go to compiler
use exceptions (open_or_die) use exceptions (open_or_die)
throw when a command couldnt be ran
precompiled header cppipe.h precompiled header cppipe.h
-Wno-unused-result in install.sh -Wno-unused-result in install.sh
file operations, lack of uniformity (C++ vs POSIX) file operations, lack of uniformity (C++ vs POSIX)
Check all return codes and report errors Check all return codes and report errors
shaded obj shaded obj
uninstall uninstall
throw when a command couldnt be ran
improve debug (the src file shown is the .ii) improve debug (the src file shown is the .ii)
no optimizations option no optimizations option
split split