Skip to content

Commit

Permalink
Merge pull request #18 from iglesias/action
Browse files Browse the repository at this point in the history
Action
  • Loading branch information
iglesias authored Apr 15, 2024
2 parents bbd9b73 + 47c00ea commit 210af75
Show file tree
Hide file tree
Showing 4 changed files with 946 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/nob.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: nob
run-name: ${{ github.actor }} is building with nobuild
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Build with nob
- run: |
g++ -std=c++20 -fpermissive -o nob nob.cpp
./nob
69 changes: 69 additions & 0 deletions nob.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#define NOBUILD_IMPLEMENTATION
#include "./nob.h"

#include <filesystem>
#include <queue>
#include <string_view>

#define CFLAGS "-Wall", "-Wextra", "-std=c2x", "-pedantic"
#define CPPFLAGS "-Wall", "-Wextra", "-std=c++23", "-pedantic", "-Wconversion", "-Wfatal-errors", "-fsanitize=undefined,address"

namespace fs = std::filesystem;

void build_kattis_c_file(std::string_view filename) {
Cstr tool_path = PATH("kattis", filename.data());
CMD("cc", CFLAGS, "-o", NOEXT(tool_path), tool_path);
}

void build_kattis_c_files() {
for (auto const& entry : fs::directory_iterator("kattis"))
if (fs::is_regular_file(entry.path())) {
auto const filename = entry.path().filename().string();
if (filename.ends_with(".c"))
build_kattis_c_file(filename);
}
}

void build_cpp_file(std::string_view filename) {
Cstr tool_path = PATH(filename.data());
CMD("g++", CPPFLAGS, "-o", NOEXT(tool_path), tool_path);
}

void build_directory_cpp_files(std::string const& root_directory) {
std::queue<std::string> directoriesQ;
directoriesQ.push(root_directory);
while (!directoriesQ.empty()) {
for (auto const& entry : fs::directory_iterator(directoriesQ.front()))
if (fs::is_regular_file(entry.path())) {
auto const filename = entry.path().filename().string();
if (filename.ends_with(".cc") or filename.ends_with(".cpp"))
build_cpp_file(directoriesQ.front() + "/" + filename);
} else if (fs::is_directory(entry.path())) {
directoriesQ.push(directoriesQ.front() + "/" + entry.path().filename().string());
}
directoriesQ.pop();
}
}

void run_example(const char *example) {
Cstr example_path = PATH("uva", example);
CMD("g++", CPPFLAGS, "-o", NOEXT(example_path), example_path, "-lgtest");
CMD(NOEXT(example_path));
}

void run_examples() {
for (const auto& entry : fs::directory_iterator("uva"))
if (fs::is_regular_file(entry.path())) {
auto filename = entry.path().filename().string();
if (filename == "summing_digits.cpp")
run_example(filename.c_str());
}
}

int main(int argc, char* argv[]) {
GO_REBUILD_URSELF(argc, argv);

build_kattis_c_files();
build_directory_cpp_files("adventofcode");
run_examples();
}
Loading

0 comments on commit 210af75

Please sign in to comment.