summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore27
-rw-r--r--default.nix16
-rw-r--r--run_and_record/.nix/derivation.nix21
-rw-r--r--run_and_record/SConstruct71
-rw-r--r--run_and_record/c++/SConscript32
-rw-r--r--run_and_record/c++/main.cpp83
-rw-r--r--run_and_record/tests/SConscript33
-rw-r--r--run_and_record/todo.txt1
8 files changed, 284 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..808aaa5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+# obj
+*.so
+*.o
+*.a
+*.os
+
+# scons
+.sconsign.dblite
+
+# nix
+result*
+
+# regular target which is not really used
+build
+bin
+
+# compile commands
+.cache
+compile_commands.json
+
+# default log dumps
+log
+
+# Doc ignores
+docs/html
+docs/latex
+docs/xml
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..85895d6
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,16 @@
+{ pkgs ? import <nixpkgs> {}
+, stdenv ? pkgs.llvmPackages_19.stdenv
+, forstio ? (import ((builtins.fetchGit {
+ url = "git@git.keldu.de:forstio/forstio";
+ ref = "dev";
+ }).outPath + "/default.nix"){
+ inherit stdenv;
+ }).forstio
+}:
+
+let
+in {
+ kel_rar = pkgs.callPackage ./run_and_record/.nix/derivation.nix {
+ inherit stdenv forstio;
+ };
+}
diff --git a/run_and_record/.nix/derivation.nix b/run_and_record/.nix/derivation.nix
new file mode 100644
index 0000000..d312b5a
--- /dev/null
+++ b/run_and_record/.nix/derivation.nix
@@ -0,0 +1,21 @@
+{ stdenv
+, scons
+, forstio
+}:
+
+stdenv.mkDerivation {
+ pname = "kel_run_and_record";
+ version = "0.0.0";
+
+ nativeBuildInputs = [
+ scons
+ ];
+
+ buildInputs = [
+ forstio.core
+ forstio.codec
+ forstio.codec-json
+ ];
+
+ src = ./..;
+}
diff --git a/run_and_record/SConstruct b/run_and_record/SConstruct
new file mode 100644
index 0000000..d85358b
--- /dev/null
+++ b/run_and_record/SConstruct
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+import os.path
+import glob
+import re
+
+
+if sys.version_info < (3,):
+ def isbasestring(s):
+ return isinstance(s,basestring)
+else:
+ def isbasestring(s):
+ return isinstance(s, (str,bytes))
+
+def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
+
+ if isbasestring(filetype):
+ dir_path = self.Dir('.').abspath
+ filetype = sorted(glob.glob(dir_path+"/"+filetype))
+
+ for path in filetype:
+ target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
+ if shared:
+ target_name+='.os'
+ sources.append( self.SharedObject( target=target_name, source=path ) )
+ else:
+ target_name+='.o'
+ sources.append( self.StaticObject( target=target_name, source=path ) )
+ pass
+
+def isAbsolutePath(key, dirname, env):
+ assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
+
+env_vars = Variables(
+ args=ARGUMENTS
+)
+
+env_vars.Add('prefix',
+ help='Installation target location of build results and headers',
+ default='/usr/local/',
+ validator=isAbsolutePath
+);
+
+env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
+ CXX=['c++'],
+ CPPDEFINES=['SAW_UNIX'],
+ CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
+ LIBS=[
+ 'forstio-core'
+ ]
+)
+env.__class__.add_source_files = add_kel_source_files
+env.Tool('compilation_db');
+env.cdb = env.CompilationDatabase('compile_commands.json');
+
+env.objects = [];
+env.sources = [];
+env.headers = [];
+env.targets = [];
+
+Export('env')
+SConscript('c++/SConscript')
+#SConscript('tests/SConscript')
+
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/run_and_record/c++/SConscript b/run_and_record/c++/SConscript
new file mode 100644
index 0000000..bf3e778
--- /dev/null
+++ b/run_and_record/c++/SConscript
@@ -0,0 +1,32 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+program_env = env.Clone();
+
+program_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+program_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += program_env.sources;
+env.headers += program_env.headers;
+
+## Static lib
+objects_static = []
+program_env.add_source_files(objects_static, program_env.sources, shared=False);
+env.binary = program_env.Program('#build/kel_rar', [objects_static]);
+
+# Set Alias
+env.Alias('binary', [env.binary]);
+
+env.targets += ['binary'];
+
+# Install
+env.Install('$prefix/bin/', [env.binary]);
diff --git a/run_and_record/c++/main.cpp b/run_and_record/c++/main.cpp
new file mode 100644
index 0000000..28676b7
--- /dev/null
+++ b/run_and_record/c++/main.cpp
@@ -0,0 +1,83 @@
+#include <forstio/codec/args.hpp>
+#include <forstio/codec/json/json.hpp>
+
+#include <unistd.h>
+#include <sys/wait.h>
+#include <iostream>
+
+namespace kel {
+namespace sch {
+using namespace saw::schema;
+
+
+}
+
+/**
+ * Run program by fork + exec
+ * Arguments are the program path + following args
+ */
+saw::error_or<void> run_program(const std::array<char*, 32u>& prog_and_params){
+ pid_t pid = fork();
+
+ if(pid < 0){
+ return saw::make_error<saw::err::critical>("Fork failed.");
+ }
+
+ if(pid == 0){
+ execvp(prog_and_params[0], prog_and_params.data());
+ return saw::make_error<saw::err::critical>("ExecVP failed.");
+ }
+
+ // Every other case
+ {
+ int status = 0;
+ waitpid(pid,&status,0);
+ }
+
+ return saw::make_void();
+}
+
+saw::error_or<void> kel_main(int argc, char** argv){
+ if(argc < 2){
+ return saw::make_error<saw::err::critical>("Path to recorded program required.");
+ }
+
+ /// Try to find separator
+ bool separator_found{false};
+ int sep_pos = -1;
+ for(int i = 1; i < argc; ++i){
+ if(std::string_view{argv[i]} == std::string_view{"--"}){
+ if((i+1) < argc){
+ separator_found = true;
+ sep_pos = i;
+ }
+ }
+ }
+
+ if(not separator_found){
+ return saw::make_error<saw::err::not_found>("Separator '--' and command following the separator required");
+ }
+ // 0 til i-1
+
+
+ return saw::make_void();
+}
+}
+
+int main(int argc, char** argv){
+ auto eov = kel::kel_main(argc, argv);
+ if(eov.is_error()){
+ auto& err = eov.get_error();
+ auto err_msg = err.get_message();
+ std::cerr<<"[Error]: "<<err.get_category();
+
+ if(not err_msg.empty()){
+ std::cerr<<" - "<<err_msg;
+ }
+ std::cerr<<std::endl;
+
+ return err.get_id();
+ }
+
+ return 0;
+}
diff --git a/run_and_record/tests/SConscript b/run_and_record/tests/SConscript
new file mode 100644
index 0000000..08a8c71
--- /dev/null
+++ b/run_and_record/tests/SConscript
@@ -0,0 +1,33 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+test_cases_env = env.Clone();
+
+test_cases_env.Append(LIBS=['forstio-test']);
+test_cases_env.Append(CCFLAGS=['-fsanitize=address','-g']);
+test_cases_env.Append(LINKFLAGS=['-fsanitize=address']);
+
+test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += test_cases_env.sources;
+env.headers += test_cases_env.headers;
+
+objects_static = []
+test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False);
+test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]);
+
+# Set Alias
+env.Alias('test', test_cases_env.program);
+env.Alias('check', test_cases_env.program);
+
+env.targets += ['test','check'];
diff --git a/run_and_record/todo.txt b/run_and_record/todo.txt
new file mode 100644
index 0000000..7c796fc
--- /dev/null
+++ b/run_and_record/todo.txt
@@ -0,0 +1 @@
+* Actually test things