Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
name: "build & test (macOS ${{ matrix.osver }} - Apple Clang - ${{ matrix.build }})"
runs-on: macos-${{ matrix.osver }}
strategy:
fail-fast: false
matrix:
osver: [14, 15, 26]
build: [dev, release]
Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
CXX ?= clang++
CABIN_TIDY ?= clang-tidy
GIT ?= git
PREFIX ?= /usr/local
INSTALL ?= install
BUILD ?= dev
COMMIT_HASH ?= $(shell git rev-parse HEAD)
COMMIT_SHORT_HASH ?= $(shell git rev-parse --short=8 HEAD)
COMMIT_DATE ?= $(shell git show -s --date=format-local:'%Y-%m-%d' --format=%cd)
COMMIT_HASH ?= $(shell $(GIT) rev-parse HEAD)
COMMIT_SHORT_HASH ?= $(shell $(GIT) rev-parse --short=8 HEAD)
COMMIT_DATE ?= $(shell $(GIT) show -s --date=format-local:'%Y-%m-%d' --format=%cd)

CXXFLAGS := -std=c++$(shell grep -m1 edition cabin.toml | cut -f 2 -d'"')
CXXFLAGS += -fdiagnostics-color
Expand Down Expand Up @@ -163,10 +164,10 @@ versions:

$(O)/DEPS/toml11:
$(MKDIR_P) $(@D)
git clone https://github.com/ToruNiina/toml11.git $@
git -C $@ reset --hard $(TOML11_VER)
$(GIT) clone https://github.com/ToruNiina/toml11.git $@
$(GIT) -C $@ reset --hard $(TOML11_VER)

$(O)/DEPS/mitama-cpp-result:
$(MKDIR_P) $(@D)
git clone https://github.com/loliGothicK/mitama-cpp-result.git $@
git -C $@ reset --hard $(RESULT_VER)
$(GIT) clone https://github.com/loliGothicK/mitama-cpp-result.git $@
$(GIT) -C $@ reset --hard $(RESULT_VER)
2 changes: 1 addition & 1 deletion cabin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Ken Matsui <26405363+ken-matsui@users.noreply.github.com>"]
description = "C++ package manager and build system"
documentation = "https://docs.cabinpkg.com"
edition = "20"
edition = "2b"
homepage = "https://cabinpkg.com"
license = "Apache-2.0"
name = "cabin"
Expand Down
4 changes: 2 additions & 2 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ BuildConfig::containsTestCode(const std::string& sourceFile) const {
std::ifstream ifs(sourceFile);
std::string line;
while (std::getline(ifs, line)) {
if (line.find("CABIN_TEST") == std::string::npos) {
if (!line.contains("CABIN_TEST")) {
continue;
}

Expand Down Expand Up @@ -679,7 +679,7 @@ Result<bool> ninjaNeedsWork(const fs::path& outDir,

const CommandOutput dryRun = Try(dryRunCmd.output());
static constexpr std::string_view noWorkMsg = "ninja: no work to do.";
const bool hasNoWork = dryRun.stdOut.find(noWorkMsg) != std::string::npos;
const bool hasNoWork = dryRun.stdOut.contains(noWorkMsg);
return Ok(!hasNoWork || !dryRun.exitStatus.success());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Builder/BuildProfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct fmt::formatter<cabin::BuildProfile> {
case cabin::BuildProfile::Test:
return fmt::format_to(ctx.out(), "test");
}
__builtin_unreachable();
std::unreachable();
} else {
return fmt::format_to(ctx.out(), "{}",
std::get<std::string>(buildProfile.type));
Expand Down
8 changes: 4 additions & 4 deletions src/Cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,20 @@ Cli::handleGlobalOpts(std::forward_iterator auto& itr,
const std::string& subcmd) {
const std::string_view arg = *itr;

if (arg == "-h" || arg == "--help") {
if (matchesAny(arg, { "-h", "--help" })) {
if (!subcmd.empty()) {
// {{ }} is a workaround for std::span until C++26.
return getCli().printHelp({ { subcmd } }).map([] { return Return; });
} else {
return getCli().printHelp({}).map([] { return Return; });
}
} else if (arg == "-v" || arg == "--verbose") {
} else if (matchesAny(arg, { "-v", "--verbose" })) {
setDiagLevel(DiagLevel::Verbose);
return Ok(Continue);
} else if (arg == "-vv") {
setDiagLevel(DiagLevel::VeryVerbose);
return Ok(Continue);
} else if (arg == "-q" || arg == "--quiet") {
} else if (matchesAny(arg, { "-q", "--quiet" })) {
setDiagLevel(DiagLevel::Off);
return Ok(Continue);
} else if (arg == "--color") {
Expand Down Expand Up @@ -399,7 +399,7 @@ Result<void> Cli::parseArgs(const CliArgsView args) const noexcept {
// else: Fallthrough: current argument wasn't handled

// Local options
else if (arg == "-V" || arg == "--version") {
else if (matchesAny(arg, { "-V", "--version" })) {
return exec("version", { itr + 1, args.end() });
} else if (arg == "--list") {
fmt::print("{}", formatAllSubcmds(true));
Expand Down
8 changes: 8 additions & 0 deletions src/Cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include "Rustify/Result.hpp"

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <optional>
#include <span>
Expand All @@ -25,6 +27,12 @@ class Cli;
using CliArgsView = std::span<const std::string>;
using Opts = std::unordered_set<Opt>;

constexpr bool
matchesAny(std::string_view value,
std::initializer_list<std::string_view> choices) noexcept {
return std::ranges::find(choices, value) != choices.end();
}

// FIXME: remove this. To do so, we need to do actions (like printing help)
// within the Cli class in addition to just parsing the arguments.
// Defined in Cabin.cc
Expand Down
6 changes: 3 additions & 3 deletions src/Cmd/Add.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ static void handleDependency(std::unordered_set<std::string_view>& newDeps,
}

static std::string getDependencyGitUrl(const std::string_view dep) {
if (dep.find("://") == std::string_view::npos) {
if (!dep.contains("://")) {
// Check if at least in "user/repo" format.
if (dep.find('/') == std::string_view::npos) {
if (!dep.contains('/')) {
Diag::error("Invalid dependency: {}", dep);
return "";
}
Expand All @@ -76,7 +76,7 @@ static std::string getDependencyName(const std::string_view dep) {
using std::string_view_literals::operator""sv;

std::string name;
if (dep.find("://") == std::string_view::npos) {
if (!dep.contains("://")) {
name = dep.substr(dep.find_last_of('/') + 1);
} else {
name = dep.substr(dep.find_last_of('/') + 1,
Expand Down
8 changes: 5 additions & 3 deletions src/Cmd/Build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ Result<void> buildImpl(const Manifest& manifest, std::string& outDir,
const Profile& profile = manifest.profiles.at(buildProfile);
Diag::info("Finished", "`{}` profile [{}] target(s) in {:.2f}s",
buildProfile, profile, elapsed.count());
return Ok();
} else {
return Err(anyhow::anyhow("build failed"));
}
return Ok();
}

static Result<void> buildMain(const CliArgsView args) {
Expand All @@ -97,11 +99,11 @@ static Result<void> buildMain(const CliArgsView args) {
return Ok();
} else if (control == Cli::Continue) {
continue;
} else if (arg == "-r" || arg == "--release") {
} else if (matchesAny(arg, { "-r", "--release" })) {
buildProfile = BuildProfile::Release;
} else if (arg == "--compdb") {
buildCompdb = true;
} else if (arg == "-j" || arg == "--jobs") {
} else if (matchesAny(arg, { "-j", "--jobs" })) {
if (itr + 1 == args.end()) {
return Subcmd::missingOptArgumentFor(arg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cmd/Clean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ static Result<void> cleanMain(CliArgsView args) noexcept {
return Ok();
} else if (control == Cli::Continue) {
continue;
} else if (arg == "-p" || arg == "--profile") {
} else if (matchesAny(arg, { "-p", "--profile" })) {
if (itr + 1 == args.end()) {
return Subcmd::missingOptArgumentFor(arg);
}

const std::string_view nextArg = *++itr;
if (!(nextArg == "dev" || nextArg == "release")) {
if (!matchesAny(nextArg, { "dev", "release" })) {
Bail("Invalid argument for {}: {}", arg, nextArg);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Cmd/Fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ collectFormatTargets(const fs::path& manifestDir,
}

const auto isExcluded = [&](std::string_view path) -> bool {
return std::ranges::find_if(
excludes,
[&](const fs::path& path2) {
return fs::relative(path2, manifestDir).string() == path;
return std::ranges::find(
excludes, path,
[&](const fs::path& candidate) {
return fs::relative(candidate, manifestDir).string();
})
!= excludes.end();
};
Expand Down
4 changes: 2 additions & 2 deletions src/Cmd/Init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static Result<void> initMain(const CliArgsView args) {
return Ok();
} else if (control == Cli::Continue) {
continue;
} else if (arg == "-b" || arg == "--bin") {
} else if (matchesAny(arg, { "-b", "--bin" })) {
isBin = true;
} else if (arg == "-l" || arg == "--lib") {
} else if (matchesAny(arg, { "-l", "--lib" })) {
isBin = false;
} else {
return INIT_CMD.noSuchArg(arg);
Expand Down
6 changes: 3 additions & 3 deletions src/Cmd/New.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ std::string createCabinToml(const std::string_view projectName) noexcept {
"authors = [\"";
cabinToml += getAuthor();
cabinToml += "\"]\n"
"edition = \"20\"\n";
"edition = \"2b\"\n";
return cabinToml;
}

Expand Down Expand Up @@ -129,9 +129,9 @@ static Result<void> newMain(const CliArgsView args) {
return Ok();
} else if (control == Cli::Continue) {
continue;
} else if (arg == "-b" || arg == "--bin") {
} else if (matchesAny(arg, { "-b", "--bin" })) {
isBin = true;
} else if (arg == "-l" || arg == "--lib") {
} else if (matchesAny(arg, { "-l", "--lib" })) {
isBin = false;
} else if (packageName.empty()) {
packageName = arg;
Expand Down
4 changes: 2 additions & 2 deletions src/Cmd/Run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ static Result<void> runMain(const CliArgsView args) {
return Ok();
} else if (control == Cli::Continue) {
continue;
} else if (arg == "-r" || arg == "--release") {
} else if (matchesAny(arg, { "-r", "--release" })) {
buildProfile = BuildProfile::Release;
} else if (arg == "-j" || arg == "--jobs") {
} else if (matchesAny(arg, { "-j", "--jobs" })) {
if (itr + 1 == args.end()) {
return Subcmd::missingOptArgumentFor(arg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Result<void> Test::exec(const CliArgsView cliArgs) {
return Ok();
} else if (control == Cli::Continue) {
continue;
} else if (arg == "-j" || arg == "--jobs") {
} else if (matchesAny(arg, { "-j", "--jobs" })) {
if (itr + 1 == cliArgs.end()) {
return Subcmd::missingOptArgumentFor(arg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cmd/Tidy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Result<void> tidyMain(const CliArgsView args) {
continue;
} else if (arg == "--fix") {
fix = true;
} else if (arg == "-j" || arg == "--jobs") {
} else if (matchesAny(arg, { "-j", "--jobs" })) {
if (itr + 1 == args.end()) {
return Subcmd::missingOptArgumentFor(arg);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sys/select.h>
#include <sys/wait.h>
#include <unistd.h>
#include <utility>
#include <vector>

namespace cabin {
Expand Down Expand Up @@ -232,7 +233,7 @@ Result<Child> Command::spawn() const noexcept {
_exit(1);
}

__builtin_unreachable();
std::unreachable();
} else {
// Parent process

Expand Down
2 changes: 1 addition & 1 deletion src/Driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Cli& getCli() noexcept {
}

static std::string colorizeAnyhowError(std::string s) {
if (s.find("Caused by:") != std::string::npos) {
if (s.contains("Caused by:")) {
replaceAll(s, "Caused by:", Yellow("Caused by:").toErrStr());
}
if (s.back() == '\n') {
Expand Down
3 changes: 2 additions & 1 deletion src/TermColor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdlib>
#include <string_view>
#include <unistd.h>
#include <utility>

namespace cabin {

Expand Down Expand Up @@ -76,7 +77,7 @@ bool shouldColor(FILE* file) noexcept {
case ColorMode::Never:
return false;
}
__builtin_unreachable();
std::unreachable();
}
bool shouldColorStdout() noexcept { return shouldColor(stdout); }
bool shouldColorStderr() noexcept { return shouldColor(stderr); }
Expand Down
4 changes: 2 additions & 2 deletions src/VersionReq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static std::string toString(const Comparator::Op op) noexcept {
case Comparator::Lte:
return "<=";
}
__builtin_unreachable();
std::unreachable();
}

struct ComparatorToken {
Expand Down Expand Up @@ -366,7 +366,7 @@ bool Comparator::satisfiedBy(const Version& ver) const noexcept {
case Op::Lte:
return matchesExact(*this, ver) || matchesLess(*this, ver);
}
__builtin_unreachable();
std::unreachable();
}

Comparator Comparator::canonicalize() const noexcept {
Expand Down
2 changes: 1 addition & 1 deletion tests/09-build-ninja.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_expect_success 'cabin build generates Ninja files and uses ninja' '
"$CABIN" new ninja_project &&
cd ninja_project &&

"$CABIN" build >build.out 2>build.err &&
"$CABIN" build &&

test_path_is_file cabin-out/dev/build.ninja &&
test_path_is_file cabin-out/dev/config.ninja &&
Expand Down
Loading