Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Ignore empty module.sc files when generating code #3427

Closed
wants to merge 1 commit into from

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Aug 27, 2024

We want to keep them as markers to limit how deeply in the folder hierarchy we discover things, so we don't need to traverse the project arbitrarily deeply every time. But we want to allow people to migrate individual sub-sub-folders to module.sc without causing naming conflict with modules defined in the project root.

This allows us to use empty module.sc files as markers for discovery but avoid generating code for them, avoiding the conflicts

@@ -139,7 +139,7 @@ object FileImportGraph {
p == projectRoot / millBuild ||
(os.isDir(p) && !os.exists(p / "module.sc"))
)
.filter(_.last == "module.sc")
.filter(p => p.last == "module.sc" && os.read(p).nonEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

What about spaces and comments?

I think it's reasonable to allow build maintainers to document the purpose of a file:

// file: module.sc
// marker for mill to search for sub-modules in this directory

or even leave some commented out stuff in it

// todo: finishe migration
// import mill._, scalalib._
// object foo extends ScalaModule 

Copy link
Member Author

Choose a reason for hiding this comment

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

good point. For that to work robustly, we would likely need to filter it out after the parser. We could probably make our existing compiler plugins perform that filtering

Copy link
Member

Choose a reason for hiding this comment

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

Sometimes perfect is the enemy of a working solution. Let's ignore comments on a best effort basis and improve later.

Suggested change
.filter(p => p.last == "module.sc" && os.read(p).nonEmpty)
.filter(p => p.last == "module.sc" &&
!os.read.lines(p).map(_.trim())
.forall(l => l.isEmpty || l.startsWith("//"))

Copy link
Member

Choose a reason for hiding this comment

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

@lihaoyi WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

@lefou let's hold off on this a bit, I suspect #3426 will change how this needs to be done

@lihaoyi
Copy link
Member Author

lihaoyi commented Sep 1, 2024

Superseded by #3426

@lihaoyi lihaoyi closed this Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants