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

Adding clean as a default task #253

Closed
wants to merge 1 commit into from
Closed

Conversation

msoule
Copy link

@msoule msoule commented Mar 21, 2018

No description provided.

@msoule
Copy link
Author

msoule commented Mar 21, 2018

First time submitting a PR for this project. I have a few questions:

  1. Unit tests for MainModule? I didn't see any.
  2. Is it acceptable that I used ammonite.ops.%%?
  3. Can ammonite.ops.%% throw an exception?
  4. I opted for multi clean targets because it gave me an elegant way to do clean all (by passing no arguments). Is there a use case for nested clean or transitive dependency clean?
  5. What are the styling standards for this project?

@msoule
Copy link
Author

msoule commented Mar 21, 2018

Also, one quirk is that clean does not clean up after itself. So after running clean you are left with out/clean. Not sure if there is anything I can do about that.

@msoule
Copy link
Author

msoule commented Mar 21, 2018

Fixes #227

def clean(targets: String*) = mill.T.command {
val result = targets match {
case Nil =>
List(ammonite.ops.%%('rm, "-rf", OutDir)(ammonite.ops.pwd).out.string.trim())
Copy link
Member

Choose a reason for hiding this comment

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

probably should use ammonite.ops.rm here

Copy link
Author

Choose a reason for hiding this comment

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

Aw okay didn't even know that was a thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know it sounds silly, but maybe we should do some kind of validation on the paths to be cleaned so that we make sure to avoid this kind of scenario even if the code changes in future?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. I did note that other functions in this file do the following:

    val resolved = RunScript.resolveTasks(
      mill.main.ResolveMetadata, evaluator, targets, multiSelect = true
    )

And then I extract the names from resolved. Would that be sufficient? I will play with it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

would it not be enough to validate that what you pass to rm -rf contains out?

Copy link
Contributor

Choose a reason for hiding this comment

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

And maybe that the parent folder contains build.sc?

Copy link
Author

Choose a reason for hiding this comment

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

Yes you're right. I guess I'm wondering if there is also value is validating that the passed targets are indeed valid targets.

Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to convert the path to a absolute path first before applying tests.

case Nil =>
List(ammonite.ops.%%('rm, "-rf", OutDir)(ammonite.ops.pwd).out.string.trim())
case _ =>
targets.map(cleanTarget => ammonite.ops.%%('rm, "-rf", s"$OutDir/$cleanTarget")(ammonite.ops.pwd).out.string.trim())
Copy link
Member

Choose a reason for hiding this comment

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

This won't work for targets like foo.bar.baz

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I wanted to ask about this first to confirm that it is desirable. Will mark as WIP until I've added this.

@msoule msoule changed the title Adding clean as a default task WIP: Adding clean as a default task Mar 21, 2018
@msoule msoule changed the title WIP: Adding clean as a default task Adding clean as a default task Mar 23, 2018
*/
def clean(targets: String*) = mill.T.command {
val result = Try {
if (ammonite.ops.ls(ammonite.ops.pwd).contains(ammonite.ops.pwd / BuildFile)) {
Copy link
Member

Choose a reason for hiding this comment

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

This can just be exists(pwd / "build.sc")

Copy link
Contributor

Choose a reason for hiding this comment

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

You are doing validation on ammonite.ops.pwd instead of the paths you are going to delete

Copy link
Author

Choose a reason for hiding this comment

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

Will do.

remove(List(ammonite.ops.pwd / OutDir))
case _ =>
remove(targets
.map(_.replace(".", "/"))
Copy link
Member

Choose a reason for hiding this comment

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

You should use resolveDestPaths (https://github.com/lihaoyi/mill/blob/master/core/src/mill/eval/Evaluator.scala#L342) to figure out what targets to clean, to ensure it stays in sync with any future changes

* Deletes the given targets from the out directory. Providing no targets will clean everything.
*/
def clean(targets: String*) = mill.T.command {
val result = Try {
Copy link
Member

Choose a reason for hiding this comment

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

No idea why you are wrapping this in a Try; you just need to return a simple Result object

Copy link
Author

Choose a reason for hiding this comment

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

The ammonite functions call things which can throw exceptions. Is it acceptable to let those exceptions be thrown?

}

private def remove(paths: List[Path]): Result[String] = {
paths.filter(ammonite.ops.exists).foreach(ammonite.ops.rm)
Copy link
Member

Choose a reason for hiding this comment

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

You don't need the filter; rm already just ignores a path if there' nothing to remove

Copy link
Author

Choose a reason for hiding this comment

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

Oh nice.

@lihaoyi
Copy link
Member

lihaoyi commented Mar 23, 2018

This should have at least one unit test somewhere before merging

@msoule
Copy link
Author

msoule commented Mar 23, 2018

@lihaoyi Where are the unit tests for the other functions in this file? Are there any?

@msoule
Copy link
Author

msoule commented Mar 23, 2018

Also @lihaoyi Can you explain the build failures I'm seeing. The same test passes locally.

@lihaoyi
Copy link
Member

lihaoyi commented Apr 6, 2018

Closing due to inactivity

@lihaoyi lihaoyi closed this Apr 6, 2018
@msoule
Copy link
Author

msoule commented Apr 6, 2018

@lihaoyi Can you answer some of the questions I have above?

@guilgaly guilgaly mentioned this pull request May 8, 2018
5 tasks
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