Skip to content

Commit 3f6b9ed

Browse files
committed
#938: a missing source named by its path is refused in an editable tree and warned of in a fetched package
The scanner states the entries (unnamed_sources) and the prepare step decides their weight by whose tree the package is, the line state.editablePackage draws for a dependency's lints: a published package's tarball cannot be changed by its consumer, and refusing it would refuse a release that built before. e2e 1097 asserts the fetched side.
1 parent e12c8cb commit 3f6b9ed

7 files changed

Lines changed: 56 additions & 10 deletions

File tree

‎.agents/docs/2026-11-15-ecosystem-gap-supplement-design.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,11 @@ profile 给出一次提示。需要评审后实现,不在本轮。
579579
- 设计:`sources` 中不含模式字符(`*?[{`)的条目指名一个文件;文件不存在时,扫描以错误拒绝,并指出陈述它的表。
580580
- 表按 `[build]`、`[target.'<sel>'.build]`、`[features.<f>]` 的顺序查找,取自条件合并前的清单
581581
(`beforeConditionalMerge`)。
582-
- 这条规则与 `scan_overrides` 的 #902 规则在同一处执行(扫描器的 `scan_one_into`),对所有包相同。
582+
- 扫描器导出 `unnamed_sources(root, manifest)`,只陈述条目,不决定严重性。
583+
- 严重性由准备阶段第 11 步按包所在的树决定,复用 `state.editablePackage`(与依赖 lint 的划线相同):
584+
可编辑的树(根、workspace 成员、`path` 包)报错;取入存储的包报警告。
585+
- 理由:已发布包的 tarball 不可更改,使用者无从修复。若新引擎拒绝它,此前能构建的发布就会被拒绝。
586+
警告仍然说明随后导入失败的原因。
583587
- 不在检查范围内:
584588
- 构建会写出的文件,即 action 的输出与声明的单元;
585589
- 绝对路径条目,它们来自构建程序;

‎CHANGELOG.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
unchanged module in a run, and on Windows a failed rewrite of a module
8888
another process had mapped (#936).
8989
- A `sources` entry without a pattern that names no existing file is an error
90-
naming its table. It was skipped, and the build failed at an importer of its
91-
module (#938).
90+
naming its table, and a warning in a package fetched into a store. It was
91+
skipped, and the build failed at an importer of its module (#938).
9292
- On Windows a runner named with a directory and no suffix (`../tools/x`)
9393
takes the system's suffixes as a bare name does; it could not be started.
9494
A `.bat` or `.cmd` program, which the system starts through its command

‎docs/04-mcpp-toml.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ belongs at the package/feature boundary, not on an individual target.
572572
> entry with none of `*`, `?`, `[`, `{` names a file, and a file that does not
573573
> exist is an error naming the table that states it (`[build]`,
574574
> `[target.'<sel>'.build]`, `[features.<f>]`): it was skipped, and the build
575-
> failed at an importer of the module the file provides. A file an action or
575+
> failed at an importer of the module the file provides. In a package fetched
576+
> into a store, which its consumer cannot change, it is a warning. A file an action or
576577
> a build program of the build writes is the build's. A pattern that matches
577578
> nothing selects nothing, as a target's selection may.
578579

‎docs/zh/04-mcpp-toml.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ required_features = ["gui"] # only built when feature `gui` is
540540
541541
> **不含模式的路径指名一个文件**(2026.11.16.1+)。不含 `*`、`?`、`[`、`{` 的 `sources` 条目指名一个
542542
> 文件,文件不存在时报错,并指出陈述它的表(`[build]`、`[target.'<sel>'.build]`、`[features.<f>]`):
543-
> 此前它被跳过,构建在导入该文件所提供模块的地方失败。构建中 action 或构建程序写出的文件属于构建。
543+
> 此前它被跳过,构建在导入该文件所提供模块的地方失败。取入存储的包由其使用者无法修改,其中的这类条目是警告。构建中 action 或构建程序写出的文件属于构建。
544544
> 匹配为空的模式不选中任何文件,一个目标上的选择可以为空。
545545
546546
> **`**/` 代表整段目录。** 在 `sources` 以及沿用其文法的每一处 glob 中,

‎src/build/prepare/scan.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ static std::expected<bool, std::string> step11_scan_sources(PrepareState& state)
246246
}
247247
return mcpp::modgraph::scan_packages(scannedPackages, closures);
248248
}();
249+
// A `sources` entry that names a file which is not there (#938) stops a
250+
// build of the tree it is written in, and is a warning in a package
251+
// fetched into a store: its consumer cannot change it, and an engine that
252+
// refused it would refuse a release that built before.
253+
for (std::size_t i = 0; i < state.packages.size(); ++i) {
254+
if (!state.compilesHere(i)) continue;
255+
auto& into = state.editablePackage(i) ? state.scan.errors : state.scan.warnings;
256+
for (auto& e : mcpp::modgraph::unnamed_sources(state.packages[i].root, state.packages[i].manifest))
257+
into.push_back(std::move(e));
258+
}
249259
if (!state.scan.errors.empty()) {
250260
std::string msg = "scanner errors:\n";
251261
for (auto& e : state.scan.errors) msg += " " + e.format() + "\n";

‎src/modgraph/scanner.cppm‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ std::set<std::filesystem::path>
8585
package_source_files(const std::filesystem::path& root,
8686
const mcpp::manifest::Manifest& manifest);
8787

88+
// The entries of a package's `sources` that name one file by its path and
89+
// find none (#938), each stated against the table it is written in. Exported
90+
// rather than raised by the scan: whether such an entry stops the build is the
91+
// caller's to decide by whose tree the package is (an editable tree is
92+
// refused; a fetched package, which its consumer cannot change, is warned of).
93+
std::vector<ScanError> unnamed_sources(const std::filesystem::path& root,
94+
const mcpp::manifest::Manifest& manifest);
95+
8896
// Scan the entire package: collects all sources via manifest globs and returns a Graph.
8997
struct ScanResult {
9098
Graph graph;
@@ -1164,15 +1172,13 @@ package_source_files(const std::filesystem::path& root,
11641172
return all_files;
11651173
}
11661174

1167-
namespace {
1168-
11691175
// A SOURCE NAMED BY ITS PATH THAT IS NOT THERE (#938). An entry of a
11701176
// `sources` list without a pattern character names one file; when that file
11711177
// does not exist the entry selected nothing and the build went on, to fail at
11721178
// an importer ("failed to read compiled module", a module "imported but not
11731179
// provided") that names no manifest -- measured where an ignore rule left the
11741180
// file out of a fresh checkout. Each such entry of the lists this build reads
1175-
// is an error naming the table that states it. A pattern that matches nothing
1181+
// is stated against the table that states it. A pattern that matches nothing
11761182
// is not: a selection may be empty on a target. A file an action of the build
11771183
// writes or a build program declares is the build's, not yet on disk, and an
11781184
// absolute entry is a build program's (`select_sources`).
@@ -1218,6 +1224,8 @@ std::vector<ScanError> unnamed_sources(const std::filesystem::path& root,
12181224
return out;
12191225
}
12201226

1227+
namespace {
1228+
12211229
// Phase 1: scan a single package, append units to result.graph.units;
12221230
// errors go straight into result.errors. producerOf/edges are NOT built
12231231
// here — the caller does that after all packages are scanned.
@@ -1401,7 +1409,6 @@ void scan_one_into(ScanResult& result,
14011409
"a stale declaration)", glob)});
14021410
}
14031411
}
1404-
for (auto& e : unnamed_sources(root, manifest)) result.errors.push_back(std::move(e));
14051412

14061413
// A `module_extensions` entry that matches nothing is dead config, and it
14071414
// is invisible otherwise: the build succeeds, the extension does nothing,

‎tests/e2e/modules/scanner.cpp‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// What the module scanner reads: the walk pruned at `.mcpp`, defines that reach the scan, a
22
// private module fragment, a byte-order mark, an implementation unit in a module file, comments
33
// and raw strings, scan overrides of files a build excludes, a source named by a path that is
4-
// not there (formerly tests/e2e/113, 167, 634, 635, 636, 639, 1064; 1096).
4+
// not there (formerly tests/e2e/113, 167, 634, 635, 636, 639, 1064; 1096, 1097).
55
import std;
66
import mcpplibs.mtest;
77
import mcpp.test.support;
@@ -280,6 +280,30 @@ sources = ["src/target/unix/target.cppm"]
280280
r = p.mcpp({"build"});
281281
expect(e2e::succeeded(r)) << "the build with the file in place failed\n" << s::text(r);
282282
};
283+
284+
"1097 a fetched package's source named by its path that is not there is a warning"_test[s::gcc][s::fresh_sandbox] = [] {
285+
// #938, the other side: the entry is in a package fetched into a store, which its consumer
286+
// cannot change. The build is not refused; a warning names the entry.
287+
s::project p({{"local-index/pkgs/a/acme.gone.lua", R"(package = {
288+
spec = "1", namespace = "acme", name = "acme.gone",
289+
description = "fixture", licenses = {"MIT"}, type = "package",
290+
xpm = {
291+
linux = { ["1.0.0"] = { url = "u", sha256 = "0" } },
292+
macosx = { ["1.0.0"] = { url = "u", sha256 = "0" } },
293+
windows = { ["1.0.0"] = { url = "u", sha256 = "0" } },
294+
},
295+
mcpp = { language = "c++23", import_std = false, sources = { "src/gone.cppm", "src/absent.cpp" },
296+
targets = { ["gone"] = { kind = "lib" } }, deps = {} },
297+
}
298+
)"},
299+
{".mcpp/.xlings/data/xpkgs/acme.gone/1.0.0/src/gone.cppm", "export module gone;\nexport int gone_value() { return 3; }\n"},
300+
{"src/main.cpp", "import gone;\nint main() { return gone_value() == 3 ? 0 : 1; }\n"},
301+
{"mcpp.toml", "[package]\nname = \"s1097\"\nversion = \"0.1.0\"\n\n[indices]\nacme = { path = \"local-index\" }\n\n[dependencies.acme]\ngone = \"1.0.0\"\n\n[targets.s1097]\nkind = \"bin\"\nmain = \"src/main.cpp\"\n"}});
302+
auto r = p.mcpp({"build"}, {.where = s::home::inherited});
303+
expect(fatal(e2e::succeeded(r))) << "a fetched package's missing file refused the build\n" << s::text(r);
304+
expect(e2e::contains(s::text(r), R"("src/absent.cpp" names no file)"))
305+
<< "no warning names the entry\n" << s::text(r);
306+
};
283307
}};
284308

285309
} // namespace

0 commit comments

Comments
 (0)