Skip to content

Add default output directory scalac in dotty project #19226

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

Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Dec 8, 2023

The previous default output directory when executing scalac, run, scala3-bootstrapped/scalac and scala3-bootstrapped/run was the root directory of the project. This could easily pollute the project with .class/.tasty files. In some situations, these could be mistakenly loaded by some of the projects or scripts.

Now when we execute scalac with no -d option set, we output ./out/default-last-scalac-out.jar. We also make scala and run use that JAR by default in the classpath if no -classpath option is set.

@sjrd
Copy link
Member

sjrd commented Dec 8, 2023

./out is not much better, since there are also subdirectories in there that could interfere with the classpath. We should use a directory that is only used for that purpose.

@nicolasstucki
Copy link
Contributor Author

I only set the -d ./out/default-last-scalac-out.jar and do not touch the classpath. That should not conflict with the other folders in ./out.

@sjrd
Copy link
Member

sjrd commented Dec 8, 2023

Ah, it's a .jar. That does address my comment.

Does the scala command also takes this into account to run the programs compiled by scalac?

@nicolasstucki
Copy link
Contributor Author

Ah, it's a .jar. That does address my comment.

I thought so. I updated the PR description to make it clearer.

Does the scala command also takes this into account to run the programs compiled by scalac?

Currently not. Now we add the . to the classpath. Arguably adding ./out/default-last-scalac-out.jar to the classpath would be better.

@nicolasstucki nicolasstucki assigned nicolasstucki and unassigned sjrd Dec 8, 2023
@nicolasstucki nicolasstucki force-pushed the scalac-in-dotty-project-default-output branch from a9696f4 to 1d7fa20 Compare December 11, 2023 08:18
@som-snytt
Copy link
Contributor

That's an interesting idea. I have a PR for Scala 2 to use (or consider using) a small lib to conventionalize the location of output.

Maybe that would apply here because it doesn't matter how the tool is run, or perhaps in the project, the appropriate environment should be set, whatever that is.

The considerations (for the general case) are not only polluting home or current dir, but also putting files where they are exposed to others, such as /tmp. For example, scala runner should compile to a private jar.

scala/scala#10611

The previous default output directory when executing `scalac`, `run`,
`scala3-bootstrapped/scalac` and `scala3-bootstrapped/run` was
the root directory of the project. This could easily pollute the project
with `.class`/`.tasty` files. In some situations, these could be
mistakenly loaded by some of the projects or scripts.

Now when we execute `scalac` with no `-d` option set, we output
`./out/default-last-scalac-out.jar`. We also make `scala` and `run` use
that JAR by default in the classpath if no `-classpath` option is set.
@nicolasstucki nicolasstucki force-pushed the scalac-in-dotty-project-default-output branch from 1d7fa20 to fca00c9 Compare December 11, 2023 08:48
@nicolasstucki nicolasstucki assigned sjrd and unassigned nicolasstucki Dec 12, 2023
@nicolasstucki nicolasstucki merged commit ce6ada2 into scala:main Dec 14, 2023
@nicolasstucki nicolasstucki deleted the scalac-in-dotty-project-default-output branch December 14, 2023 09:49
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
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.

4 participants