Skip to content

Conversation

sake92
Copy link
Contributor

@sake92 sake92 commented Feb 2, 2025

Changes:

Some minor questions/suggestions:

  1. current spawnClassloader is more flexible, you can pass your own classloader rather that use getClass.getClassLoader, this is ok I guess?
  2. suggestion to name spawnClassLoader as createClassLoader
  3. suggestion to name callClassloader as withClassloader (common loan pattern name)
  4. getMainMethod is not public so runLocal can't be removed.. so expose getMainMethod or leave runLocal as is?
  5. Some calls are inside build.mill files.
    I have to wait for new version of Mill with these changes included, and then update them?
  6. Not sure if closeClassLoaderWhenDone is needed, I don't understand why it is left unclosed in few places.

Closes #3772

@lihaoyi
Copy link
Member

lihaoyi commented Feb 2, 2025

The naming is pulled a bit in two directions

  1. On one hand, we want classloader methods to be consistent with the equivalent subprocess methods, which are named spawn and call
  2. On the other hand, we want classloader methods to be consistent with the equivalent Scala patterns, which call them create and with

TBH I'm not sure which one is better. @lefou @lolgab not sure if you guys have any opinions here?

@lihaoyi
Copy link
Member

lihaoyi commented Feb 2, 2025

current spawnClassloader is more flexible, you can pass your own classloader rather that use getClass.getClassLoader, this is ok I guess?

This is to let you select the parent classloader; at the minimum it lets you decide whether or not to include the current Mill classloader on the child classpath, or have the child classpath entirely isolated. So we probably need to keep it as necessary complexity in the API

@lihaoyi
Copy link
Member

lihaoyi commented Feb 2, 2025

Some calls are inside build.mill files.
I have to wait for new version of Mill with these changes included, and then update them?

That's right. For now can just leave them in place

@lihaoyi
Copy link
Member

lihaoyi commented Feb 2, 2025

getMainMethod is not public so runLocal can't be removed.. so expose getMainMethod or leave runLocal as is?

Seems that Jvm.runLocal is only called in one place in RunModule.scala, so maybe we can move getMainMethod there?

@lihaoyi
Copy link
Member

lihaoyi commented Feb 2, 2025

Not sure if closeClassLoaderWhenDone is needed, I don't understand why it is left unclosed in few places.

Maybe we can try closing it all the time and see if any tests break? I don't understand why we wouldn't close it either haha

@lihaoyi
Copy link
Member

lihaoyi commented Feb 2, 2025

The name Jvm is also somewhat generic, could we come up with a more specific name? e.g. maybe Classpath.withClassLoader/Classpath.spawnSubprocess?

@sake92
Copy link
Contributor Author

sake92 commented Feb 2, 2025

getMainMethod is not public so runLocal can't be removed.. so expose getMainMethod or leave runLocal as is?

Seems that Jvm.runLocal is only called in one place in RunModule.scala, so maybe we can move getMainMethod there?

Good point.
Copied it to RunModule, we can remove the one from Jvm when we remove these deprecated functions.

@sake92
Copy link
Contributor Author

sake92 commented Feb 6, 2025

In the last commit I only changed a comment.
But the previous commit tests worked fine..

@lihaoyi
Copy link
Member

lihaoyi commented Feb 7, 2025

Last few comments, after that we can merge it! Test failures are probably flakes and can be ignored.

@sake92 sake92 requested a review from lihaoyi February 7, 2025 07:49
@sake92
Copy link
Contributor Author

sake92 commented Feb 7, 2025

Should be good now.

@lihaoyi
Copy link
Member

lihaoyi commented Feb 7, 2025

@sake92 looks like there's a compile error somewhere

@lihaoyi lihaoyi merged commit e5600ec into com-lihaoyi:main Feb 7, 2025
28 of 31 checks passed
@lihaoyi
Copy link
Member

lihaoyi commented Feb 7, 2025

Thanks @sake92! Failures look unrelated so I'll merge this first and deal with failures asynchronously. Could you help open a PR backporting this to 0.12.x? Then I'll separately remove the deprecated methods from main and transfer the bounty using the same bank details as before

@lefou lefou added this to the 0.13.0 milestone Feb 7, 2025
sake92 added a commit to sake92/mill that referenced this pull request Feb 7, 2025
Changes:
- added functions based on com-lihaoyi#3772 description
- the process related ones now return os-lib process result or
subprocess handle
- `callClassLoader` uses a loan pattern function and closes the
classloader after usage
- added `mill.util.ProcessUtil.toResult(processResult)` to handle
process result in same way
https://github.com/com-lihaoyi/mill/blob/main/main/util/src/mill/util/Jvm.scala#L352-L357

Some minor questions/suggestions:
1. current `spawnClassloader` is more flexible, you can pass your own
classloader rather that use `getClass.getClassLoader`, this is ok I
guess?
1. suggestion to name `spawnClassLoader` as `createClassLoader`
1. suggestion to name `callClassloader` as `withClassloader` (common
loan pattern name)
1. `getMainMethod` is not public so `runLocal` can't be removed.. so
expose `getMainMethod` or leave `runLocal` as is?
1. Some calls are inside build.mill files.
I have to wait for new version of Mill with these changes included, and
then update them?
1. Not sure if `closeClassLoaderWhenDone` is needed, I don't understand
why it is left unclosed in few places.

Closes com-lihaoyi#3772

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
lihaoyi pushed a commit that referenced this pull request Feb 7, 2025
… to 0.12 (#4504)

Backport of #4456

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@lihaoyi lihaoyi mentioned this pull request Feb 16, 2025
unlsycn added a commit to unlsycn/chisel that referenced this pull request Apr 9, 2025
ref:
com-lihaoyi/mill@f35464c
com-lihaoyi/mill#4456

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
unlsycn added a commit to unlsycn/chisel that referenced this pull request Apr 9, 2025
ref:
com-lihaoyi/mill@f35464c
com-lihaoyi/mill#4456

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
unlsycn added a commit to unlsycn/chisel that referenced this pull request Apr 9, 2025
ref:
com-lihaoyi/mill@f35464c
com-lihaoyi/mill#4456

Signed-off-by: unlsycn <unlsycn@unlsycn.com>
lihaoyi added a commit that referenced this pull request Apr 10, 2025
Fixes #4863

Seems like it was broken by #4837 which replaced `Jvm.runSubprocess`
with `os.call`, which unfortunately had different stream forwarding
defaults. This class of problem should be impossible in future thanks to
#4456 from @sake92 which
standardizing the stream forwarding defaults of `Jvm.*Process` APIs with
`os.*`
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.

Clean up Jvm.* subprocess/inprocess APIs (500USD Bounty)
3 participants