How to exclude a file from *every* module in Package.swift?

rather than manually add README.md files to module exclude paths, i want to do something like the following:

for target:PackageDescription.Target in package.targets
{
    target.exclude.append("README.md")
}

but of course this just generates a deluge of warnings for all the modules that don’t have a README.md at the root of their sources directory:

warning: Invalid Exclude '/Sources/MarkdownABI/README.md': File not found.
warning: Invalid Exclude '/Sources/MarkdownRendering/README.md': File not found.
warning: Invalid Exclude '/Sources/Sources/README.md': File not found.
warning: Invalid Exclude '/Sources/MarkdownTrees/README.md': File not found.
warning: Invalid Exclude '/Sources/MarkdownParsing/README.md': File not found.
warning: Invalid Exclude '/Sources/MarkdownPluginSwift/README.md': File not found.
warning: Invalid Exclude '/Sources/MarkdownSemantics/README.md': File not found.
warning: Invalid Exclude '/Sources/Multiparts/README.md': File not found.

is there a better way?

Only way that comes to mind is to check whether the file exists in that for-loop.

Separately, I wonder whether a warning for a missing exclude is a bit over-eager? Yes, you could be accidentally including a file if you typo an exclude, but that is ultimately not something we can prevent since you can also typo it in a way where it matches a different file. Feels like something we can just not mention or maybe we could have a flag that enables these type of pedantic warnings.

3 Likes

I’m glad the default exclude includes a warning. It’d be very bad if, say, a credential file got into a built product. But it’d probably be okay to have a flag to turn that off for particular excludes.

can we just automatically exclude all files with an .md extension across an entire package?

No, you could very well have Markdown resources in a package!

2 Likes

I don't think excluding .md files without user input is good idea. One might want include those as documentation resources or inputs for plugins.

1 Like

including them as documentation resources is kind of the point? markdown files will always raise warnings unless they live in a directory with a name that ends in .docc, i would like this to also work with documentation tooling that is not called DocC, without having to repeat the same excludes in each target, as it is a package-wide convention.

Sure, but that already can't happen since we don't include unknown file types by default. It would have to be credentials in a file that's automatically included, such as a C or Swift source file.

Or be in the Resources directory, but I take your point.