Skip to content

Commit

Permalink
Build: support including src/ (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Mar 7, 2025
1 parent 17f3212 commit 95c9a08
Show file tree
Hide file tree
Showing 35 changed files with 126 additions and 121 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ DEFINES := -DCABIN_CABIN_PKG_VERSION='"$(VERSION)"' \
-DCABIN_CABIN_COMMIT_HASH='"$(COMMIT_HASH)"' \
-DCABIN_CABIN_COMMIT_SHORT_HASH='"$(COMMIT_SHORT_HASH)"' \
-DCABIN_CABIN_COMMIT_DATE='"$(COMMIT_DATE)"'
INCLUDES := -isystem $(O)/DEPS/toml11/include \
INCLUDES := -Isrc -isystem $(O)/DEPS/toml11/include \
-isystem $(O)/DEPS/mitama-cpp-result/include \
$(shell pkg-config --cflags '$(LIBGIT2_VERREQ)') \
$(shell pkg-config --cflags '$(LIBCURL_VERREQ)') \
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/Compiler.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Compiler.hpp"

#include "../Algos.hpp"
#include "../Command.hpp"
#include "../Rustify/Result.hpp"
#include "Algos.hpp"
#include "Command.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <sstream>
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/Compiler.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "../Command.hpp"
#include "../Rustify/Result.hpp"
#include "../VersionReq.hpp"
#include "Command.hpp"
#include "Rustify/Result.hpp"
#include "VersionReq.hpp"

#include <filesystem>
#include <fmt/format.h>
Expand Down
29 changes: 16 additions & 13 deletions src/Builder/Project.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Project.hpp"

#include "../Algos.hpp"
#include "../Git2.hpp"
#include "../Rustify/Result.hpp"
#include "../TermColor.hpp"
#include "Algos.hpp"
#include "BuildProfile.hpp"
#include "Git2.hpp"
#include "Rustify/Result.hpp"
#include "TermColor.hpp"

#include <filesystem>
#include <spdlog/spdlog.h>
Expand All @@ -15,25 +15,28 @@

namespace cabin {

void
Project::includeIfExist(const fs::path& path, bool isSystem) {
if (fs::exists(path)) {
compiler.opts.cFlags.includeDirs.emplace_back(path, isSystem);
}
}

Result<Project>
Project::init(const fs::path& rootDir) {
Manifest manifest = Try(Manifest::tryParse(rootDir / Manifest::FILE_NAME));
Compiler compiler = Try(Compiler::init());

fs::path projectIncludePath = rootDir / "include";
if (fs::exists(projectIncludePath)) {
compiler.opts.cFlags.includeDirs.emplace_back(
std::move(projectIncludePath), /*isSystem=*/false
);
}
compiler.opts.cFlags.others.emplace_back(
"-std=c++" + manifest.package.edition.str
);
if (shouldColorStderr()) {
compiler.opts.cFlags.others.emplace_back("-fdiagnostics-color");
}

return Ok(Project(std::move(manifest), std::move(compiler)));
Project project(std::move(manifest), std::move(compiler));
project.includeIfExist(rootDir / "src", /*isSystem=*/false);
project.includeIfExist(rootDir / "include", /*isSystem=*/false);
return Ok(std::move(project));
}

// Generally split the string by space character, but it will properly interpret
Expand Down Expand Up @@ -186,7 +189,7 @@ Project::setBuildProfile(const BuildProfile& buildProfile) {

#ifdef CABIN_TEST

# include "../Rustify/Tests.hpp"
# include "Rustify/Tests.hpp"

namespace tests {

Expand Down
6 changes: 4 additions & 2 deletions src/Builder/Project.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "BuildProfile.hpp"
#include "Compiler.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <filesystem>
#include <utility>
Expand All @@ -16,6 +16,8 @@ class Project {
Project(Manifest manifest, Compiler compiler)
: manifest(std::move(manifest)), compiler(std::move(compiler)) {};

void includeIfExist(const fs::path& path, bool isSystem = false);

public:
const Manifest manifest;
Compiler compiler;
Expand Down
8 changes: 4 additions & 4 deletions src/Cmd/Add.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "Add.hpp"

#include "../Cli.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Cli.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <fmt/std.h>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Add.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
16 changes: 8 additions & 8 deletions src/Cmd/Build.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "Build.hpp"

#include "../Algos.hpp"
#include "../BuildConfig.hpp"
#include "../Builder/BuildProfile.hpp"
#include "../Cli.hpp"
#include "../Command.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Parallelism.hpp"
#include "Algos.hpp"
#include "BuildConfig.hpp"
#include "Builder/BuildProfile.hpp"
#include "Cli.hpp"
#include "Command.hpp"
#include "Common.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "Parallelism.hpp"

#include <charconv>
#include <chrono>
Expand Down
8 changes: 4 additions & 4 deletions src/Cmd/Build.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "../Builder/BuildProfile.hpp"
#include "../Cli.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Builder/BuildProfile.hpp"
#include "Cli.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <string>

Expand Down
8 changes: 4 additions & 4 deletions src/Cmd/Clean.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "Clean.hpp"

#include "../Cli.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Cli.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Clean.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
4 changes: 2 additions & 2 deletions src/Cmd/Common.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "../Cli.hpp"
#include "../Parallelism.hpp"
#include "Cli.hpp"
#include "Parallelism.hpp"

namespace cabin {

Expand Down
16 changes: 8 additions & 8 deletions src/Cmd/Fmt.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Fmt.hpp"

#include "../Algos.hpp"
#include "../BuildConfig.hpp"
#include "../Cli.hpp"
#include "../Diag.hpp"
#include "../Git2/Exception.hpp"
#include "../Git2/Repository.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Algos.hpp"
#include "BuildConfig.hpp"
#include "Cli.hpp"
#include "Diag.hpp"
#include "Git2/Exception.hpp"
#include "Git2/Repository.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <algorithm>
#include <cstdlib>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Fmt.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Help.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Help.hpp"

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Help.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
8 changes: 4 additions & 4 deletions src/Cmd/Init.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Init.hpp"

#include "../Cli.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Cli.hpp"
#include "Common.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "New.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <fstream>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Init.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
12 changes: 6 additions & 6 deletions src/Cmd/Lint.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Lint.hpp"

#include "../Algos.hpp"
#include "../Cli.hpp"
#include "../Command.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Algos.hpp"
#include "Cli.hpp"
#include "Command.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <filesystem>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Lint.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
12 changes: 6 additions & 6 deletions src/Cmd/New.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "New.hpp"

#include "../Algos.hpp"
#include "../Cli.hpp"
#include "../Diag.hpp"
#include "../Git2.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Algos.hpp"
#include "Cli.hpp"
#include "Common.hpp"
#include "Diag.hpp"
#include "Git2.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <fstream>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/New.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

#include <string>
#include <string_view>
Expand Down
8 changes: 4 additions & 4 deletions src/Cmd/Remove.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "Remove.hpp"

#include "../Cli.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Rustify/Result.hpp"
#include "Cli.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "Rustify/Result.hpp"

#include <cstdlib>
#include <fmt/ranges.h>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Remove.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
16 changes: 8 additions & 8 deletions src/Cmd/Run.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "Run.hpp"

#include "../Algos.hpp"
#include "../Builder/BuildProfile.hpp"
#include "../Cli.hpp"
#include "../Command.hpp"
#include "../Diag.hpp"
#include "../Manifest.hpp"
#include "../Parallelism.hpp"
#include "../Rustify/Result.hpp"
#include "Algos.hpp"
#include "Build.hpp"
#include "Builder/BuildProfile.hpp"
#include "Cli.hpp"
#include "Command.hpp"
#include "Common.hpp"
#include "Diag.hpp"
#include "Manifest.hpp"
#include "Parallelism.hpp"
#include "Rustify/Result.hpp"

#include <charconv>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Run.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../Cli.hpp"
#include "Cli.hpp"

namespace cabin {

Expand Down
Loading

0 comments on commit 95c9a08

Please sign in to comment.