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

Ensure -D property passing correctly resets when -D is later removed #1514

Merged
merged 4 commits into from
Oct 5, 2021

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Oct 5, 2021

The issue here is that we were not properly resetting the system property when -D was removed, resulting in it incorrectly hanging around with the last set value.

This PR stores the initial value of every system property, along with the keys for the system properties set with -D for each run. Now when a -D key-value pair is removed, we can compare the key against the initialSystemProperties to decide whether we need to either remove the key value or to restore it to its original value

Tested manually using a simple build.sc:

val foo = interp.watchValue(sys.props.get("foo"))

val osname = interp.watchValue(sys.props.get("os.name"))

def bar() = T.command{ println(s"$foo $osname") }

On main, removing -D flags leaves the properties hanging around with the last set value:

lihaoyi mill$ ./mill -i dev.run ../test -D foo=a -D os.name=lols bar
...
Some(a) Some(lols)

lihaoyi mill$ ./mill -i dev.run ../test  bar
...
Some(a) Some(lols)

With this PR, removing the `-D flags has the properties either cleared or reset to their initial value:

lihaoyi mill$ ./mill -i dev.run ../test -D foo=a -D os.name=lols bar
...
Some(a) Some(lols)

lihaoyi mill$ ./mill -i dev.run ../test  bar
...
None Some(Mac OS X)

Review by @lefou

@lihaoyi lihaoyi requested a review from lefou October 5, 2021 09:58
@lihaoyi
Copy link
Member Author

lihaoyi commented Oct 5, 2021

Not sure what the mima tests are complaining about, but the failure in the CaffeineTests looks like a flake

@lefou
Copy link
Member

lefou commented Oct 5, 2021

Not sure what the mima tests are complaining about, but the failure in the CaffeineTests looks like a flake

Changing a case class is always binary incompatible. This is OK I think in your case. We currently check all modules, to be aware of any change.

@lefou
Copy link
Member

lefou commented Oct 5, 2021

Evaluator is part of the API which is used in build.sc (no binary issue, as this is always recompiled) but also by plugins. Maybe, we should provide a compatibility apply/copy method. And deprecate it immediately.

@lihaoyi
Copy link
Member Author

lihaoyi commented Oct 5, 2021

@lefou we're only touching Evaluator.State though. Do any plugins really instantiate this? I mean in theory it's not private, but we've never been disciplined about privatizing things in the past. This definitely seems like something I expect Mill to use and nobody else

@lefou
Copy link
Member

lefou commented Oct 5, 2021

Evaluator is part of the documentation (https://com-lihaoyi.github.io/mill/mill/Extending_Mill.html#_evaluator_commands_experimental) and also used outside mill main/core, e.g. contrib plugins make use of it, but probably also thirdparty plugins (e.g. scala steward). As we copy the evaluator, it's fair th assume, others do it, too.

I belief providing a nice binary compatibility story is one of the (many) fundatental things to create a nice user experience. It's hard to get right and easily to screw up. Deprecation is a nice tool to show API removal/changes before it's too late.

@lefou
Copy link
Member

lefou commented Oct 5, 2021

@lihaoyi Sorry, I didn't looked carefully. You're right, Evaluator.State can be considered as internal.

Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@lihaoyi lihaoyi merged commit ec959a8 into main Oct 5, 2021
@lefou lefou added this to the after 0.10.0-M3 milestone Oct 5, 2021
@lefou lefou deleted the props branch October 5, 2021 13:41
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