diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 8da0b84c0..5506a7354 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -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] diff --git a/Makefile b/Makefile index 295844840..fbcc3660d 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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) diff --git a/cabin.toml b/cabin.toml index 57461e294..bd6a7ad14 100644 --- a/cabin.toml +++ b/cabin.toml @@ -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" diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index add6329c8..5366df060 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -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; } @@ -679,7 +679,7 @@ Result 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()); } diff --git a/src/Builder/BuildProfile.hpp b/src/Builder/BuildProfile.hpp index 69c3fbe1a..49d0ddb7f 100644 --- a/src/Builder/BuildProfile.hpp +++ b/src/Builder/BuildProfile.hpp @@ -59,7 +59,7 @@ struct fmt::formatter { case cabin::BuildProfile::Test: return fmt::format_to(ctx.out(), "test"); } - __builtin_unreachable(); + std::unreachable(); } else { return fmt::format_to(ctx.out(), "{}", std::get(buildProfile.type)); diff --git a/src/Cli.cc b/src/Cli.cc index 8de955f3d..95e93e621 100644 --- a/src/Cli.cc +++ b/src/Cli.cc @@ -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") { @@ -399,7 +399,7 @@ Result 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)); diff --git a/src/Cli.hpp b/src/Cli.hpp index 46d863888..09444d553 100644 --- a/src/Cli.hpp +++ b/src/Cli.hpp @@ -2,9 +2,11 @@ #include "Rustify/Result.hpp" +#include #include #include #include +#include #include #include #include @@ -25,6 +27,12 @@ class Cli; using CliArgsView = std::span; using Opts = std::unordered_set; +constexpr bool +matchesAny(std::string_view value, + std::initializer_list 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 diff --git a/src/Cmd/Add.cc b/src/Cmd/Add.cc index 0a55b6dfc..3876565b6 100644 --- a/src/Cmd/Add.cc +++ b/src/Cmd/Add.cc @@ -60,9 +60,9 @@ static void handleDependency(std::unordered_set& 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 ""; } @@ -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, diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index ff051fd33..fb1237d52 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -81,8 +81,10 @@ Result 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 buildMain(const CliArgsView args) { @@ -97,11 +99,11 @@ static Result 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); } diff --git a/src/Cmd/Clean.cc b/src/Cmd/Clean.cc index 07581bec7..c1f847147 100644 --- a/src/Cmd/Clean.cc +++ b/src/Cmd/Clean.cc @@ -35,13 +35,13 @@ static Result 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); } diff --git a/src/Cmd/Fmt.cc b/src/Cmd/Fmt.cc index 9510deaf9..cd9615e98 100644 --- a/src/Cmd/Fmt.cc +++ b/src/Cmd/Fmt.cc @@ -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(); }; diff --git a/src/Cmd/Init.cc b/src/Cmd/Init.cc index 6703e2d76..49c05bac7 100644 --- a/src/Cmd/Init.cc +++ b/src/Cmd/Init.cc @@ -34,9 +34,9 @@ static Result 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); diff --git a/src/Cmd/New.cc b/src/Cmd/New.cc index 362634298..c0c509cc2 100644 --- a/src/Cmd/New.cc +++ b/src/Cmd/New.cc @@ -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; } @@ -129,9 +129,9 @@ static Result 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; diff --git a/src/Cmd/Run.cc b/src/Cmd/Run.cc index e19a63152..c3c6b45e4 100644 --- a/src/Cmd/Run.cc +++ b/src/Cmd/Run.cc @@ -48,9 +48,9 @@ static Result 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); } diff --git a/src/Cmd/Test.cc b/src/Cmd/Test.cc index e21da0bda..a7fa65433 100644 --- a/src/Cmd/Test.cc +++ b/src/Cmd/Test.cc @@ -150,7 +150,7 @@ Result 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); } diff --git a/src/Cmd/Tidy.cc b/src/Cmd/Tidy.cc index 2ed946f4a..416ccaacb 100644 --- a/src/Cmd/Tidy.cc +++ b/src/Cmd/Tidy.cc @@ -60,7 +60,7 @@ static Result 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); } diff --git a/src/Command.cc b/src/Command.cc index 9606a81e3..4f406a6c8 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace cabin { @@ -232,7 +233,7 @@ Result Command::spawn() const noexcept { _exit(1); } - __builtin_unreachable(); + std::unreachable(); } else { // Parent process diff --git a/src/Driver.cc b/src/Driver.cc index e92f55858..c6fa11577 100644 --- a/src/Driver.cc +++ b/src/Driver.cc @@ -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') { diff --git a/src/TermColor.cc b/src/TermColor.cc index e59d0882f..fd15a3969 100644 --- a/src/TermColor.cc +++ b/src/TermColor.cc @@ -6,6 +6,7 @@ #include #include #include +#include namespace cabin { @@ -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); } diff --git a/src/VersionReq.cc b/src/VersionReq.cc index 14641b7fd..f1d779689 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -29,7 +29,7 @@ static std::string toString(const Comparator::Op op) noexcept { case Comparator::Lte: return "<="; } - __builtin_unreachable(); + std::unreachable(); } struct ComparatorToken { @@ -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 { diff --git a/tests/09-build-ninja.sh b/tests/09-build-ninja.sh index cbcdb98c6..2b744aeb7 100755 --- a/tests/09-build-ninja.sh +++ b/tests/09-build-ninja.sh @@ -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 &&