From 1b2029dbbbfdafb618aca3eccdbbba2512b5b49b Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 5 Jul 2026 00:56:42 +0200 Subject: kel rap for running multiple sims --- kel_rap/.nix/derivation.nix | 19 +++++++++++++ kel_rap/SConstruct | 69 +++++++++++++++++++++++++++++++++++++++++++++ kel_rap/c++/SConscript | 32 +++++++++++++++++++++ kel_rap/c++/kel_rap.cpp | 51 +++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 kel_rap/.nix/derivation.nix create mode 100644 kel_rap/SConstruct create mode 100644 kel_rap/c++/SConscript create mode 100644 kel_rap/c++/kel_rap.cpp (limited to 'kel_rap') diff --git a/kel_rap/.nix/derivation.nix b/kel_rap/.nix/derivation.nix new file mode 100644 index 0000000..54c41fd --- /dev/null +++ b/kel_rap/.nix/derivation.nix @@ -0,0 +1,19 @@ +{ stdenv +, scons +, clang-tools +}: + +stdenv.mkDerivation { + pname = "kel_rap"; + version = "0.0.0"; + + nativeBuildInputs = [ + clang-tools + scons + ]; + + buildInputs = [ + ]; + + src = ./..; +} diff --git a/kel_rap/SConstruct b/kel_rap/SConstruct new file mode 100644 index 0000000..262dced --- /dev/null +++ b/kel_rap/SConstruct @@ -0,0 +1,69 @@ +#!/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=[ + ] +) +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/kel_rap/c++/SConscript b/kel_rap/c++/SConscript new file mode 100644 index 0000000..bfcedae --- /dev/null +++ b/kel_rap/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_rap', [objects_static]); + +# Set Alias +env.Alias('binary', [env.binary]); + +env.targets += ['binary']; + +# Install +env.Install('$prefix/bin/', [env.binary]); diff --git a/kel_rap/c++/kel_rap.cpp b/kel_rap/c++/kel_rap.cpp new file mode 100644 index 0000000..d505125 --- /dev/null +++ b/kel_rap/c++/kel_rap.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#include +#include +#include + +namespace fs = std::filesystem; + +int main(int argc, char* argv[]) { + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " \n"; + return -1; + } + + for (const auto& e : fs::directory_iterator(argv[1])) { + if (!e.is_regular_file()) + continue; + + std::string path = e.path().string(); + + pid_t pid = fork(); + if (pid < 0) { + std::cerr << "fork failed\n"; + return -1; + } + + if (pid == 0) { + std::string path = e.path().string(); + std::array args{ + path.data(), + nullptr + }; + + execvp(args[0], args.data()); + + std::cerr << "execvp failed: " << path << '\n'; + return -1; + } + + int status; + if (waitpid(pid, &status, 0) < 0) { + std::cerr << "waitpid failed\n"; + return -1; + } + } + + return 0; +} -- cgit v1.2.3