Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for literate programming. #3747

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

al45tair
Copy link
Contributor

Adds support for Markdown, reStructuredText and LaTeX files as Swift sources.

Adds support for Markdown, reStructuredText and LaTeX files as Swift sources.
@al45tair al45tair marked this pull request as draft September 15, 2021 18:12
@al45tair
Copy link
Contributor Author

See swiftlang/swift#39305

@@ -397,6 +400,9 @@ public struct TargetSourcesBuilder {
}
}

// Ignore README files.
if path.basename.hasPrefix("README") { continue}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this; I added it because not having it here broke the build (because of a package that was written in C++ but had a README.md file in the source directory).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think that it is clear cut that readme files in a target are never supposed to be resources and as such ignoring them doesn't seem right. I am curious how these files could have broken the build, unhandled files should only emit warnings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, it is because we're saying .md files are now sources, but if they aren't specially formatted, they will break the build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It's because there's a package written in C++ that has a README.md in its directory, so the package manager code refuses to build it because it thinks it is a mixed-language package.

The literate stuff doesn't care at all about whether or not there is actually code in a Markdown file.

I'm not certain what the right fix is here, though I am certain that this is particular "fix" is a hack and we should do something else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, because .md is becoming a source file type, it is seen as mixed source.

Would it make sense to have a more specific file extension for the literate programming stuff, so that we can distinguish them from "regular" markdown files? In principle, it could be correct that it is mixed source if the .md file does contain code.

Another approach could be only treating .md files as source if they're part of a target that isn't a C-family one, but that seems awfully specific.

Copy link
Contributor

@mattt mattt Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Piggy-backing on what @neonichu just said: What if we used a compound file extension convention. For example, README.swift.md (or maybe README.md.swift?). That way, we wouldn't have to rely on any assumptions or heuristics to determine whether a given file is a conventional text document or a literate programming notebook.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense to me. Using plain .md as files to be compiled seems that it would surprise a lot of users.

@@ -397,6 +400,9 @@ public struct TargetSourcesBuilder {
}
}

// Ignore README files.
if path.basename.hasPrefix("README") { continue}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we accommodate differences in case (e.g. readme.md)?

Suggested change
if path.basename.hasPrefix("README") { continue}
if path.basenameWithoutExt.uppercased() == "README" { continue }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I'm a bit uncertain that this is the right thing to do in any way whatsoever. Maybe it would be better to detect cases where there are C(++)/ObjC(++) sources and ignore any of the file formats we support for literate Swift.

@@ -397,6 +400,9 @@ public struct TargetSourcesBuilder {
}
}

// Ignore README files.
if path.basename.hasPrefix("README") { continue}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, to also accommodate variations like readme-en.md

Suggested change
if path.basename.hasPrefix("README") { continue}
if path.basename.uppercased().hasPrefix("README") { continue }

@@ -529,7 +535,7 @@ public struct FileRuleDescription {
.init(
rule: .compile,
toolsVersion: .minimumRequired,
fileTypes: ["swift"]
fileTypes: ["swift", "md", "rst", "tex"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new file types should get their own distinct rule with tools-version being 5.6

@elsh
Copy link
Contributor

elsh commented Oct 26, 2021

@al45tair Do you need any additional information to make a further progress on this?

@al45tair
Copy link
Contributor Author

al45tair commented Oct 27, 2021

@elsh No, but thanks for asking. This work was all somewhat experimental (which is why all the PRs are in Draft). Whether we'll land this in this form, or whether we'll eventually do something else I don't know at this point.

@tomerd tomerd added the WIP Work in progress label Jul 12, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants