summaryrefslogtreecommitdiff
path: root/kel_cpp_boilerplate/c++
diff options
context:
space:
mode:
Diffstat (limited to 'kel_cpp_boilerplate/c++')
-rw-r--r--kel_cpp_boilerplate/c++/blueprints.hpp9
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/default_nix.hpp6
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp7
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/gitignore.hpp6
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp7
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/readme_txt.hpp12
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/sconscript.hpp9
-rw-r--r--kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp7
-rw-r--r--kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp96
9 files changed, 136 insertions, 23 deletions
diff --git a/kel_cpp_boilerplate/c++/blueprints.hpp b/kel_cpp_boilerplate/c++/blueprints.hpp
new file mode 100644
index 0000000..f013e88
--- /dev/null
+++ b/kel_cpp_boilerplate/c++/blueprints.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "blueprints/readme_txt.hpp"
+#include "blueprints/default_nix.hpp"
+#include "blueprints/derivation_nix.hpp"
+#include "blueprints/main_cpp.hpp"
+#include "blueprints/gitignore.hpp"
+#include "blueprints/sconstruct.hpp"
+#include "blueprints/sconscript.hpp"
diff --git a/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp b/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp
index 312ad7f..6edb8e1 100644
--- a/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp
+++ b/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp
@@ -1,10 +1,10 @@
#pragma once
#include <string_view>
-constexpr std::string_view default_nix_file_name = "default.nix";
+constexpr std::string_view default_nix_file_path = "default.nix";
-constexpr std::string_view default_nix_file_content = R"(
-{ pkgs ? import <nixpkgs> {}
+constexpr std::string_view default_nix_file_content =
+R"({ pkgs ? import <nixpkgs> {}
, stdenv ? pkgs.llvmPackages_19.stdenv
, clang-tools ? pkgs.clang-tools_19
}:
diff --git a/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp b/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp
index 9715769..4417a8d 100644
--- a/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp
+++ b/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp
@@ -1,11 +1,10 @@
#pragma once
#include <string_view>
-constexpr std::string_view derivation_nix_dir_name = "app/.nix";
-constexpr std::string_view derivation_nix_file_name = "derivation.nix";
+constexpr std::string_view derivation_nix_file_path = "app/.nix/derivation.nix";
-constexpr std::string_view derivation_nix_file_content = R"(
-{ stdenv
+constexpr std::string_view derivation_nix_file_content =
+R"({ stdenv
, scons
, clang-tools
, forstio
diff --git a/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp b/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp
index b09b153..d7d141e 100644
--- a/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp
+++ b/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp
@@ -1,8 +1,8 @@
#pragma once
#include <string_view>
-constexpr std::string_view gitignore_file_name = ".gitignore";
+constexpr std::string_view gitignore_file_path = ".gitignore";
-constexpr std::string_view gitignore_file_content = R"(
-result*
+constexpr std::string_view gitignore_file_content =
+R"(result*
)";
diff --git a/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp b/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp
index 353a045..c3bdb39 100644
--- a/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp
+++ b/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp
@@ -1,11 +1,10 @@
#pragma once
#include <string_view>
-constexpr std::string_view main_cpp_dir_name = "app/c++";
-constexpr std::string_view main_cpp_file_name = "main.cpp";
+constexpr std::string_view main_cpp_file_path = "app/c++/main.cpp";
-constexpr std::string_view main_cpp_file_content = R"(
-#include <forstio/error.hpp>
+constexpr std::string_view main_cpp_file_content =
+R"(#include <forstio/error.hpp>
#include <iostream>
namespace kel {
diff --git a/kel_cpp_boilerplate/c++/blueprints/readme_txt.hpp b/kel_cpp_boilerplate/c++/blueprints/readme_txt.hpp
new file mode 100644
index 0000000..ffb2c65
--- /dev/null
+++ b/kel_cpp_boilerplate/c++/blueprints/readme_txt.hpp
@@ -0,0 +1,12 @@
+#pragma once
+#include <string_view>
+
+constexpr std::string_view readme_txt_file_path = "readme.txt";
+
+constexpr std::string_view readme_txt_file_content =
+R"(# Generated by keldu's stupid blueprint program
+
+Remember to:
+* Change the binary name in app/c++/Sconscript
+* Add the pname in app/.nix/derivation.nix
+)";
diff --git a/kel_cpp_boilerplate/c++/blueprints/sconscript.hpp b/kel_cpp_boilerplate/c++/blueprints/sconscript.hpp
index e1c8c8b..bd25fdd 100644
--- a/kel_cpp_boilerplate/c++/blueprints/sconscript.hpp
+++ b/kel_cpp_boilerplate/c++/blueprints/sconscript.hpp
@@ -2,11 +2,10 @@
#include <string_view>
-constexpr std::string_view sconscript_dir_name = "app/c++";
-constexpr std::string_view sconscript_file_name = "SConscript";
+constexpr std::string_view sconscript_file_path = "app/c++/SConscript";
-constexpr std::string_view sconscript_file_content = R"(
-#!/bin/false
+constexpr std::string_view sconscript_file_content =
+R"(#!/bin/false
import os
import os.path
@@ -29,7 +28,7 @@ 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_cpp_boilerplate', [objects_static]);
+env.binary = program_env.Program('#build/binary_change_in_sconscript', [objects_static]);
# Set Alias
env.Alias('binary', [env.binary]);
diff --git a/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp b/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp
index cd47e83..ba4f84e 100644
--- a/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp
+++ b/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp
@@ -2,11 +2,10 @@
#include <string_view>
-constexpr std::string_view sconstruct_dir_name = "app";
-constexpr std::string_view sconstruct_file_name = "SConstruct";
+constexpr std::string_view sconstruct_file_path = "app/SConstruct";
-constexpr std::string_view sconstruct_file_content = R"(
-#!/usr/bin/env python3
+constexpr std::string_view sconstruct_file_content =
+R"(#!/usr/bin/env python3
import sys
import os
diff --git a/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp b/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp
index 972feb7..2399f61 100644
--- a/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp
+++ b/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp
@@ -1,10 +1,106 @@
#include <forstio/error.hpp>
+
+#include "blueprints.hpp"
+
#include <iostream>
+#include <filesystem>
+#include <fstream>
namespace kel {
+saw::error_or<void> write_to_file(
+ std::string_view file_path,
+ std::string_view file_content
+){
+ namespace fs = std::filesystem;
+ try {
+ auto fpath = fs::path(file_path);
+ if(fpath.has_parent_path()){
+ fs::create_directories(fs::path(fpath).parent_path());
+ }
+
+ std::ofstream out(fpath, std::ios::binary);
+ if(not out){
+ return saw::make_error<saw::err::critical>("Couldn't create file");
+ }
+ out.write(file_content.data(), static_cast<std::streamsize>(file_content.size()));
+ if(not out){
+ return saw::make_error<saw::err::critical>("Couldn't write to file");
+ }
+ }catch(const std::exception& e){
+ (void) e;
+ return saw::make_error<saw::err::critical>("Couldn't create file somehow");
+ }
+
+ return saw::make_void();
+}
+
saw::error_or<void> kel_main(int argc, char** argv){
(void) argc;
(void) argv;
+
+ namespace fs = std::filesystem;
+
+ try {
+ fs::path cwd = fs::current_path();
+ std::cout << "\nCurrent working is directory: " << cwd << "\n\n";
+
+ } catch (const std::exception& e) {
+ return saw::make_error<saw::err::critical>("Couldn't get the working directory");
+ }
+ {
+ std::string confirm;
+ std::cout << "Are you sure to proceed? Type 'yes' to continue: ";
+ std::getline(std::cin, confirm);
+
+ if (confirm != "yes") {
+ std::cout<<"Didn't type \"yes\". Aborting..."<<std::endl;
+ return saw::make_void();
+ }
+ }
+
+ {
+ auto eov = write_to_file(readme_txt_file_path,readme_txt_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_to_file(default_nix_file_path,default_nix_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_to_file(sconstruct_file_path,sconstruct_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_to_file(sconscript_file_path,sconscript_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_to_file(main_cpp_file_path,main_cpp_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_to_file(gitignore_file_path,gitignore_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_to_file(derivation_nix_file_path,derivation_nix_file_content);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
return saw::make_void();
}
}