Skip to content

Commit 49e7683

Browse files
committed
fix(manifest): 消掉最后一处 optional<string>,不再赌一轮 CI
上一次把嫌疑判给 `version_req_problem` 并把它移进匿名命名空间, Windows 仍以同样的报错失败;那证明它不是唯一的因,却没有证明它无辜。 成员那一处已经修好,但两个候选一次只排除一个,每轮要四十分钟。 `version_req_problem` 现在返回 `std::string`,空串表示没有问题。调用侧 不需要区分「没有问题」与「问题是空串」,所以不损失任何东西,而这个模块 的新代码里再没有 `std::optional<std::string>`——下一轮 CI 的结论因此 不含歧义。
1 parent aebf9ea commit 49e7683

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/manifest/toml.cppm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import mcpp.platform;
1616
//
1717
// The first version of this helper sat at namespace scope in the module
1818
// purview, which makes its declaration part of what this module's interface
19-
// records. Its return type is `std::optional<std::string>`, and under clang
19+
// records. Under clang
2020
// with the MSVC standard library that was enough to break every downstream
2121
// translation unit that constructs one:
2222
//
@@ -65,10 +65,16 @@ namespace {
6565
// not invalidate a running program; equally, a new program must not invalidate
6666
// published data. A manifest check has no standing to do so over an entry that
6767
// may never be reached.
68-
std::optional<std::string> version_req_problem(std::string_view spec) {
69-
if (spec.empty()) return std::nullopt; // path/git/workspace deps
68+
// ⚠️ RETURNS A PLAIN STRING, EMPTY MEANING "NO PROBLEM", AND NOT AN
69+
// `std::optional<std::string>`. The optional was the obvious spelling and cost
70+
// two rounds of Windows CI: see the note on `TargetEntry::sysroot` for what
71+
// that specialisation does to importers under clang with the MSVC standard
72+
// library. Nothing here needs to distinguish an absent problem from an empty
73+
// one, so nothing is lost.
74+
std::string version_req_problem(std::string_view spec) {
75+
if (spec.empty()) return {}; // path/git/workspace deps
7076
if (auto r = mcpp::version_req::parse_req(spec); !r) return r.error();
71-
return std::nullopt;
77+
return {};
7278
}
7379

7480
} // namespace
@@ -697,14 +703,14 @@ std::expected<Manifest, ManifestError> parse_string(std::string_view content,
697703
if (auto it = sub.find("path"); it != sub.end() && it->second.is_string()) spec.path = it->second.as_string();
698704
if (auto it = sub.find("version"); it != sub.end() && it->second.is_string()) {
699705
spec.version = it->second.as_string();
700-
if (auto why = version_req_problem(spec.version))
706+
if (auto why = version_req_problem(spec.version); !why.empty())
701707
m.schemaWarnings.push_back(std::format(
702708
"[{}.\"{}\"] version = '{}' is not a requirement this "
703709
"resolver can match ({}). The fetch will fail naming the "
704710
"PACKAGE, which may well exist; it is this requirement that "
705711
"does not parse. Accepted: an exact version (\"1.2.3\") or "
706712
"a comparator (\"^1.2.3\", \">=1.0.0, <2.0.0\").",
707-
section, fqName, spec.version, *why));
713+
section, fqName, spec.version, why));
708714
}
709715
if (auto it = sub.find("git"); it != sub.end() && it->second.is_string()) spec.git = it->second.as_string();
710716
if (auto it = sub.find("visibility"); it != sub.end() && it->second.is_string()) {
@@ -819,14 +825,14 @@ std::expected<Manifest, ManifestError> parse_string(std::string_view content,
819825
auto key = selector.stableMapKey;
820826
if (value.is_string()) {
821827
spec.version = value.as_string();
822-
if (auto why = version_req_problem(spec.version))
828+
if (auto why = version_req_problem(spec.version); !why.empty())
823829
m.schemaWarnings.push_back(std::format(
824830
"[{}] {} = '{}' is not a requirement this resolver can "
825831
"match ({}). The fetch will fail naming the PACKAGE, which "
826832
"may well exist; it is this requirement that does not "
827833
"parse. Accepted: an exact version (\"1.2.3\") or a "
828834
"comparator (\"^1.2.3\", \">=1.0.0, <2.0.0\").",
829-
section, key, spec.version, *why));
835+
section, key, spec.version, why));
830836
} else if (value.is_table()) {
831837
auto& sub = value.as_table();
832838
if (!looks_like_inline_dep_spec(sub)) {

tests/unit/test_manifest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ sysroot = ""
36883688
EXPECT_TRUE(it->second.sysroot.empty());
36893689
}
36903690

3691-
TEST(Manifest, TargetSysrootAbsentStaysNullopt) {
3691+
TEST(Manifest, TargetSysrootAbsentIsNotDeclared) {
36923692
constexpr auto src = R"(
36933693
[package]
36943694
name = "x"

0 commit comments

Comments
 (0)