Skip to content

Commit ba529c9

Browse files
committed
doc-links(cs): a props or targets file that does not parse up to its root is unknown (R6)
The project-file scan wrote the "could not be read" blob for a *.csproj that is no readable MSBuild <Project>, and for a *.props or *.targets file only once its <Project> root was seen. A *.props or *.targets file that is malformed before its root, or ends before one, got no blob at all: an import of it counted as outside the repository with a closed scope, and as the nearest Directory.Build.* it was passed over for the one above, whose usings were then applied although MSBuild does not read that file. Such a file now gets the "could not be read" blob too, so the projects that evaluate it have an open scope. A *.props or *.targets file whose root element is not <Project> is still no MSBuild file and has no blob. Test: msbuild_malformed_props_opens (a malformed nearest Directory.Build.props under a usable one: a name found nowhere is external, and a type only the upper file's using reaches is not bound; decoy: a project without a nearer file binds through the upper file and keeps a closed scope). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent d77ce46 commit ba529c9

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

‎internal/cbm/doclink_cs.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,8 +3707,8 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
37073707
return blob;
37083708
}
37093709
/* a *.csproj marks its directory as a C# project even when it cannot be
3710-
* read; a *.props or *.targets file has a blob only as an MSBuild
3711-
* <Project> */
3710+
* read; a *.props or *.targets file has no blob only when it parses up to
3711+
* a root element that is not an MSBuild <Project> */
37123712
csx_scan_t p = {
37133713
.x = {.src = ctx->source, .n = ctx->source_len > 0 ? (uint32_t)ctx->source_len : 0},
37143714
.out = {.a = ctx->arena},
@@ -3719,6 +3719,7 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
37193719
p.x.i = 3;
37203720
}
37213721
bool is_project = false;
3722+
bool other_root = false; /* XML whose root element is not <Project> */
37223723
bool bad = false;
37233724
csx_tok_t t;
37243725
for (;;) {
@@ -3751,6 +3752,7 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
37513752
break;
37523753
}
37533754
if (!csx_is(&p.x, t.name, "Project")) {
3755+
other_root = true;
37543756
break; /* XML, but no MSBuild file */
37553757
}
37563758
is_project = true;
@@ -3762,7 +3764,12 @@ const char *cbm_doclink_cs_project_scan_scope(CBMExtractCtx *ctx) {
37623764
}
37633765
}
37643766
cs_cost_add(p.x.i, 0);
3765-
if ((bad && (is_project || named_project)) || (!is_project && named_project)) {
3767+
/* What the scan could not read is unknown, not absent: a file malformed
3768+
* anywhere or ending before its root, and a *.csproj that is no MSBuild
3769+
* <Project>. With no blob, an import of such a file would count as one
3770+
* outside the repository, and as the nearest Directory.Build.* it would
3771+
* be passed over for the one above, which MSBuild does not read. */
3772+
if (bad || (!is_project && (named_project || !other_root))) {
37663773
p.out.len = 0;
37673774
sb_puts(&p.out, CBM_DOCLINK_CS_SCOPE_TAG "\nP\t\t!\n");
37683775
} else if (!is_project) {

‎tests/test_doc_mentions.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9698,6 +9698,45 @@ TEST(doc_mentions_msbuild_unread_project_opens) {
96989698
PASS();
96999699
}
97009700

9701+
/* R6: a *.props or *.targets file that does not parse up to its root is not
9702+
* read either: what it holds is unknown. As the nearest Directory.Build.props
9703+
* it is the one MSBuild reads, so the scope of its project is open (a simple
9704+
* name found nowhere is external) and the usable file further up is not
9705+
* applied (its `Using Include="Lib"` imports nothing here). Decoy: a project
9706+
* with no nearer file reads the upper one (Gadget binds through it, a name
9707+
* found nowhere is missing). */
9708+
TEST(doc_mentions_msbuild_malformed_props_opens) {
9709+
const dm_source_t files[] = {
9710+
{"Directory.Build.props", "<Project><ItemGroup><Using Include=\"Lib\"/></ItemGroup>"
9711+
"</Project>\n"},
9712+
{"a/Directory.Build.props", "<\n<Project><ItemGroup><Using Include=\"Hidden\"/>"
9713+
"</ItemGroup></Project>\n"},
9714+
{"a/A.csproj", DM_EMPTY_PROJECT},
9715+
{"a/Thing.cs", "namespace Lib\n{\n public class Thing { }\n}\n"},
9716+
{"a/UsesA.cs", "namespace App\n"
9717+
"{\n"
9718+
" /// <summary><see cref=\"Thing\"/> <see cref=\"NowhereA\"/></summary>\n"
9719+
" public class UsesA { }\n"
9720+
"}\n"},
9721+
{"c/C.csproj", DM_EMPTY_PROJECT},
9722+
{"c/Gadget.cs", "namespace Lib\n{\n public class Gadget { }\n}\n"},
9723+
{"c/UsesC.cs",
9724+
"namespace App\n"
9725+
"{\n"
9726+
" /// <summary><see cref=\"Gadget\"/> <see cref=\"NowhereC\"/></summary>\n"
9727+
" public class UsesC { }\n"
9728+
"}\n"},
9729+
};
9730+
static const dm_want_t wants[] = {
9731+
{"a/UsesA.cs", "NowhereA", "UsesA.UsesA", NULL, "external", NULL, NULL},
9732+
{"a/UsesA.cs", "Thing", "UsesA.UsesA", NULL, "external", "Thing.Thing", NULL},
9733+
{"c/UsesC.cs", "Gadget", "UsesC.UsesC", "Gadget.Gadget", NULL, NULL, NULL},
9734+
{"c/UsesC.cs", "NowhereC", "UsesC.UsesC", NULL, "missing", NULL, NULL},
9735+
};
9736+
ASSERT_EQ(dm_check_repo("malformed_props", files, DM_COUNT(files), wants, DM_COUNT(wants)), 0);
9737+
PASS();
9738+
}
9739+
97019740
enum { DM_BIG_MEMBERS = 20000, DM_SMALL_FILES = 200 };
97029741

97039742
/* What the resolver looks at to build its index over one file of
@@ -10275,6 +10314,7 @@ SUITE(doc_mentions) {
1027510314
RUN_TEST(doc_mentions_cs_stored_scope_nesting);
1027610315
RUN_TEST(doc_mentions_index_status_unknown_reason);
1027710316
RUN_TEST(doc_mentions_msbuild_unread_project_opens);
10317+
RUN_TEST(doc_mentions_msbuild_malformed_props_opens);
1027810318
RUN_TEST(doc_mentions_cs_scratch_table_work);
1027910319
RUN_TEST(doc_mentions_incremental_non_ascii_name);
1028010320
RUN_TEST(doc_mentions_alloc_failure_status);

0 commit comments

Comments
 (0)