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

Use OS-Lib's pwdDynamicFunction to allow sandboxing of os.pwd, write sandboxing doc page, introduce RunModule#runner #3479

Merged
merged 38 commits into from
Sep 8, 2024

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Sep 7, 2024

Also did some misc cleanup: synchronizedEval is now unnecessary since #3243 added a coarse grained lock around BSP, prettied up the #threadId prefixes, remove empty .dest/ folders for tidyness

RunModule#runner continues the pattern estabilished with CoursierModule#defaultResolver: a convenient way to bundle up the various tasks related to running a modules code in a way that lets downstream callers pass things to run while being able to override the default configs (e.g. forkEnv, forkArgs, etc.) and without the hassle of wrapping things in T.tasks. If this pattern works out, it would serve as a great alternative to the "pass tasks as arguments to command" pattern we've used in the past. This makes the 11-module-run-task example much nicer

Also more CI optimizations

@lihaoyi lihaoyi changed the title Use OS-Lib's pwdDynamicFunction to allow sandboxing of os.pwd Use OS-Lib's pwdDynamicFunction to allow sandboxing of os.pwd, write sandboxing doc page Sep 7, 2024
@lihaoyi lihaoyi marked this pull request as ready for review September 7, 2024 13:47
@lihaoyi lihaoyi changed the title Use OS-Lib's pwdDynamicFunction to allow sandboxing of os.pwd, write sandboxing doc page Use OS-Lib's pwdDynamicFunction to allow sandboxing of os.pwd, write sandboxing doc page, introduce RunModule#runner Sep 7, 2024
@@ -39,8 +39,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
Copy link
Member

Choose a reason for hiding this comment

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

We need this, to derive the version from git reliably.

Copy link
Member Author

Choose a reason for hiding this comment

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

We dont need it jn every job, we just need it i the jobs that do publishing, which arent affected by this change

Comment on lines 318 to 331

// Remove any empty `.dest/` folders to tidy up the filesystem. Otherwise
// tasks that call `os.proc` or `T.dest` without actually doing anything with
// the folder will leave empty folders around cluttering the disk
this.synchronized {
for {
p <- usedDest
if os.list.stream(p).headOption.isEmpty
// workers can be used after they return their value and
// may need to continue working with their `T.dest`,
if !isWorker
} os.remove(p)
}

Copy link
Member

@lefou lefou Sep 7, 2024

Choose a reason for hiding this comment

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

I think this could break tasks, that export their dest dir on purpose. E.g. I use this sometimes to refer to working directories used by other task. Also the GenIdea uses empty dest dirs as unique output dirs when configuring the Java/Scala compiler.

def ideaCompileOutput: T[PathRef] = T.persistent {
PathRef(T.dest / "classes")
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah i noticed that. The use cases i hit was in 11-module-run-task, and in how we used to save a folder for running Mill's own integrstion tests. Both were hacks and i found solutions. We always tell people not to write to upstream dest folders after all.

Could there be another way of marking those tasks that need the folder? e.g. putting a marker file in the folder like git requires (https://www.theserverside.com/), or defining another variant of Task that is just a scratchspace that preserves the folder for usage

Copy link
Member Author

@lihaoyi lihaoyi Sep 7, 2024

Choose a reason for hiding this comment

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

another alternstive is to create a folder inside .dest and export that instead, just to tell Mill that you have something in dest tou want to keep. But we really should have a more principled stance on mutating upstream dest folders, just like T.persistent adds some structure around keeping them around

Copy link
Member Author

Choose a reason for hiding this comment

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

decided to revert this for now, can discuss it in a follow up

@lihaoyi lihaoyi merged commit bdaa359 into com-lihaoyi:main Sep 8, 2024
25 checks passed
@lefou lefou added this to the 0.12.0-RC1 milestone Sep 8, 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