Skip to content

Commit 82b1c12

Browse files
committed
feat(workspace): complete other commands support
1 parent 431b931 commit 82b1c12

15 files changed

Lines changed: 106 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.17)
2-
project(cppship VERSION 0.8.0)
2+
project(cppship VERSION 0.8.1)
33

44
# cpp std
55
set(CMAKE_CXX_STANDARD 20)

cppship.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cppship"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
authors = []
55
std = 20
66

include/cppship/cmd/bench.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ namespace cppship::cmd {
1010
struct BenchOptions {
1111
Profile profile = Profile::release;
1212
std::optional<std::string> target;
13+
std::optional<std::string> package;
1314
};
1415

1516
int run_bench(const BenchOptions& options);
1617

17-
}
18+
}

include/cppship/cmd/build.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct BuildOptions {
2626
Profile profile = Profile::debug;
2727
bool dry_run = false;
2828
std::optional<std::string> package;
29-
std::optional<std::string> target;
29+
std::optional<std::string> cmake_target;
3030
std::set<BuildGroup> groups;
3131
};
3232

include/cppship/cmd/run.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ namespace cppship::cmd {
1010
struct RunOptions {
1111
Profile profile = Profile::debug;
1212
std::string args;
13+
std::optional<std::string> package;
1314
std::optional<std::string> bin;
1415
std::optional<std::string> example;
1516
};
1617

1718
int run_run(const RunOptions& options);
1819

19-
}
20+
}

include/cppship/cmd/test.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ namespace cppship::cmd {
1010
struct TestOptions {
1111
Profile profile = Profile::debug;
1212
std::optional<std::string> target;
13+
std::optional<std::string> package;
1314
std::optional<std::string> name_regex;
1415
bool rerun_failed = false;
1516
};
1617

1718
int run_test(const TestOptions& options);
1819

19-
}
20+
}

include/cppship/core/workspace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <range/v3/view/map.hpp>
4+
35
#include "cppship/core/layout.h"
46
#include "cppship/core/manifest.h"
57

@@ -25,6 +27,8 @@ class Workspace {
2527

2628
auto end() const { return packages_.end(); }
2729

30+
auto layouts() const { return ranges::views::values(packages_); }
31+
2832
private:
2933
fs::path root_;
3034

include/cppship/cppship.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3-
#include "cppship/cmd/bench.h"
4-
#include "cppship/cmd/build.h"
5-
#include "cppship/cmd/clean.h"
6-
#include "cppship/cmd/cmake.h"
7-
#include "cppship/cmd/fmt.h"
8-
#include "cppship/cmd/init.h"
9-
#include "cppship/cmd/install.h"
10-
#include "cppship/cmd/lint.h"
11-
#include "cppship/cmd/run.h"
12-
#include "cppship/cmd/test.h"
3+
#include "cppship/cmd/bench.h" // IWYU pragma: export
4+
#include "cppship/cmd/build.h" // IWYU pragma: export
5+
#include "cppship/cmd/clean.h" // IWYU pragma: export
6+
#include "cppship/cmd/cmake.h" // IWYU pragma: export
7+
#include "cppship/cmd/fmt.h" // IWYU pragma: export
8+
#include "cppship/cmd/init.h" // IWYU pragma: export
9+
#include "cppship/cmd/install.h" // IWYU pragma: export
10+
#include "cppship/cmd/lint.h" // IWYU pragma: export
11+
#include "cppship/cmd/run.h" // IWYU pragma: export
12+
#include "cppship/cmd/test.h" // IWYU pragma: export

lib/cmake/generator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ find_package(GTest REQUIRED)
324324
}
325325

326326
mOut << fmt::format("add_test({} {})\n", target, target);
327+
mOut << fmt::format("set_tests_properties({} PROPERTIES LABELS {})\n", target, mName);
327328

328329
mTestTargets.emplace(target);
329330
}

lib/cmd/bench.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#include <boost/process/system.hpp>
66
#include <gsl/narrow>
7+
#include <range/v3/algorithm/all_of.hpp>
78
#include <range/v3/range/conversion.hpp>
89
#include <range/v3/view.hpp>
910
#include <spdlog/spdlog.h>
1011

1112
#include "cppship/cmake/msvc.h"
1213
#include "cppship/cmake/naming.h"
1314
#include "cppship/cmd/build.h"
14-
#include "cppship/core/manifest.h"
1515
#include "cppship/core/workspace.h"
1616
#include "cppship/util/fs.h"
1717
#include "cppship/util/log.h"
@@ -34,20 +34,19 @@ int run_one_bench(const cmd::BuildContext& ctx, const std::string_view bench)
3434

3535
int cmd::run_bench(const BenchOptions& options)
3636
{
37-
BuildContext ctx(options.profile);
38-
Manifest manifest(ctx.metafile);
39-
40-
const auto& layout = enforce_default_package(ctx.workspace);
41-
4237
NameTargetMapper mapper;
38+
39+
BuildContext ctx(options.profile);
4340
BuildOptions build_options { .profile = options.profile };
4441
if (options.target) {
45-
if (!layout.bench(*options.target)) {
42+
if (ranges::all_of(
43+
ctx.workspace.layouts(), [&](const auto& layout) { return !layout.bench(*options.target); })) {
4644
throw Error { fmt::format("bench `{}` not found", *options.target) };
4745
}
4846

49-
build_options.target = mapper.bench(*options.target);
47+
build_options.cmake_target = mapper.bench(*options.target);
5048
} else {
49+
build_options.package = options.package;
5150
build_options.groups.insert(BuildGroup::benches);
5251
}
5352

@@ -56,14 +55,16 @@ int cmd::run_bench(const BenchOptions& options)
5655
return EXIT_FAILURE;
5756
}
5857

59-
if (build_options.target) {
60-
return run_one_bench(ctx, *build_options.target);
58+
if (build_options.cmake_target) {
59+
return run_one_bench(ctx, *build_options.cmake_target);
6160
}
6261

63-
for (const auto& bench : layout.benches()) {
64-
const int res = run_one_bench(ctx, mapper.bench(bench.name));
65-
if (res != 0) {
66-
result = res;
62+
for (const auto& layout : ctx.workspace.layouts()) {
63+
for (const auto& bench : layout.benches()) {
64+
const int res = run_one_bench(ctx, mapper.bench(bench.name));
65+
if (res != 0) {
66+
result = res;
67+
}
6768
}
6869
}
6970

0 commit comments

Comments
 (0)