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

Fix CrossVersion.Disabled compat #280

Merged
merged 1 commit into from
Nov 25, 2018
Merged

Fix CrossVersion.Disabled compat #280

merged 1 commit into from
Nov 25, 2018

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Nov 21, 2018

Fixes sbt/sbt#4977

@dwijnand
Copy link
Member Author

Need to add MiMa exclusions for these. I doubt anyone's used them seeing how they're wrong, but also they're inlined constants, so even if they're binary API has changed there are no call sites in bytecode because the values got inlined.

@dwijnand
Copy link
Member Author

Reported the false positive in MiMa: lightbend-labs/mima#266

@dwijnand
Copy link
Member Author

@eed3si9n WDYT?

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Currently the final vals are pointing to the companion objects, and I think we should encourage ppl to use the lowercase versions like full and binary in sbt 0.13.
The only odd duck is Disabled, which was an object in sbt 0.13, so if you want to make this change for better source compat, I think we should limit it to Disabled.

Also could we target develop branch first?

final val Constant = sbt.librarymanagement.Constant
final val Full = sbt.librarymanagement.Full
final val Patch = sbt.librarymanagement.Patch
final val Disabled = sbt.librarymanagement.Disabled()
Copy link
Member

Choose a reason for hiding this comment

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

The corresponding construct in sbt 0.13 https://github.com/sbt/sbt-zero-thirteen/blob/v0.13.17/ivy/src/main/scala/sbt/CrossVersion.scala#L19:

  object Disabled extends CrossVersion { override def toString = "disabled" }

so the above change could be considered valid for source compat with sbt 0.13, but in general we probably should recommend migrating to lowercase CrossVersion.disabled.

final val Full = sbt.librarymanagement.Full
final val Patch = sbt.librarymanagement.Patch
final val Disabled = sbt.librarymanagement.Disabled()
final val Binary = sbt.librarymanagement.Binary()
Copy link
Member

Choose a reason for hiding this comment

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

Binary and Full were classes in sbt 0.13, but had lower case value binary and full.
So keeping Binary as the companion object of sbt.librarymanagement.Binary kind of makes sense to me.

@dwijnand dwijnand changed the base branch from 1.2.x to develop November 24, 2018 09:32
@dwijnand dwijnand changed the title [1.2.x] Fix the CrossVersion compat Fix CrossVersion.Disabled compat Nov 24, 2018
@dwijnand
Copy link
Member Author

Yep CrossVersion.Disabled was what lead me to this change, so I'm happy to restrict this PR to just that. Also, it's needn't be on the bugfix highway, so I'm happy to re-target it to develop.

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks @dwijnand

@eed3si9n eed3si9n merged commit a01c43e into sbt:develop Nov 25, 2018
@dwijnand dwijnand deleted the fix-the-CrossVersion-compat branch November 25, 2018 07:26
eed3si9n added a commit to eed3si9n/librarymanagement that referenced this pull request Nov 27, 2018
Not sure how but sbt#280 has slipped through with Mima failing.
eed3si9n added a commit to eed3si9n/librarymanagement that referenced this pull request Nov 27, 2018
Not sure how but sbt#280 has slipped through with Mima failing.
@eed3si9n eed3si9n mentioned this pull request Nov 27, 2018
eed3si9n added a commit that referenced this pull request Nov 27, 2018
@eed3si9n
Copy link
Member

@dwijnand We might need to revert this PR since @cunei found breakage in the community build:

[cats] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
[cats-effect] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
[circe] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
[coursier] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
[scalacheck] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
[scalaz] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;

@dwijnand
Copy link
Member Author

It's a false positive because it's a folded constant.

But MiMa isn't aware of those... lightbend-labs/mima#266

@@ -157,6 +157,12 @@ lazy val lmCore = (project in file("core"))
exclude[DirectMissingMethodProblem]("sbt.librarymanagement.ArtifactExtra.extension"),
exclude[DirectMissingMethodProblem]("sbt.librarymanagement.ArtifactTypeFilterExtra.types"),

// by mistake we aliased the companion object instead of an instance of Disabled
// but it was aliased as a constant expression, so even if the binary API has changed
// there are no call sites in bytecode because the value got inlined
Copy link
Member Author

Choose a reason for hiding this comment

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

More precisely "constant folded" not "inlined".

@eed3si9n
Copy link
Member

@cunei Do you have a stacktrace? I am guessing some plugin out there is actually calling Disabled().

@dwijnand
Copy link
Member Author

True, it must be. Going to ask the Scala team about constant folding.

@eed3si9n
Copy link
Member

I wonder if we can keep the bincompat by adding def apply() = this.

@dwijnand
Copy link
Member Author

Yeah, I wondered that too, but there's no apply in those java method signatures.

@eed3si9n
Copy link
Member

ok so Disabled is the name of the static method on CrossVersion$ class.

@eed3si9n
Copy link
Member

Change val to def?

eed3si9n added a commit to eed3si9n/librarymanagement that referenced this pull request Jan 22, 2019
Ref sbt#280

This is to workaround bincompat error detected by sbt community build.

```
[cats] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
```
@eed3si9n
Copy link
Member

#290

eed3si9n added a commit to eed3si9n/librarymanagement that referenced this pull request Jan 23, 2019
Ref sbt#280

This is to workaround bincompat error detected by sbt community build.

```
[cats] [error] java.lang.NoSuchMethodError: sbt.librarymanagement.CrossVersion$.Disabled()Lsbt/librarymanagement/Disabled$;
```
eed3si9n added a commit to eed3si9n/librarymanagement that referenced this pull request Apr 2, 2019
Fixes sbt/sbt#4595
Ref sbt#290
Ref sbt#280

This is bit of an odd one.

To keep bincompat and also to fix sbt 0.13 compatibility issue we have made `Disabled` companion object extend `Disabled` type.
This actually created a subtle deserialization issue:

```
[error] scala.MatchError: Disabled() (of class sbt.librarymanagement.Disabled$)
[error] 	at sjsonnew.FlatUnionFormats$$anon$5.write(FlatUnionFormats.scala:220)
[error] 	at sjsonnew.JsonWriter.addField(JsonFormat.scala:40)
[error] 	at sjsonnew.JsonWriter.addField$(JsonFormat.scala:37)
[error] 	at sjsonnew.FlatUnionFormats$$anon$5.addField(FlatUnionFormats.scala:208)
[error] 	at sjsonnew.Builder.addField(Builder.scala:43)
[error] 	at sbt.librarymanagement.ModuleIDFormats$$anon$1.write(ModuleIDFormats.scala:46)
```

This is because Contraband generates `flatUnionFormat5[CrossVersion, Disabled, ...]` for all of the subtypes of `CrossVersion`, which uses the runtime type information. Now that `Disabled` object is also in the mix, this created JSON that `CrossVersionFormats` cannot deserialize. This brings the code into src/ so we can write this part manually.
eed3si9n added a commit to eed3si9n/librarymanagement that referenced this pull request Aug 22, 2019
Fixes sbt/sbt#4975

This makes `CrossVersion.Disabled` a stable identifier by reverting `final def` back to `final val`.

This is to fix Scala.JS build

```
[error] ScalaJSCrossVersion.scala:34:23: stable identifier required, but sbt.`package`.CrossVersion.Disabled found.
[error]     case CrossVersion.Disabled =>
[error]                       ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
```

### notes

- sbt#121 added `final val Disabled = sbt.librarymanagement.Disabled` but it was just a companion object
- sbt#280 actually made it `final val Disabled = sbt.librarymanagement.Disabled()`, but this broke Cat's build that was calling `CrossVersion.Disabled()`
- sbt#290 changed to `final def Disabled = sbt.librarymanagement.Disabled` and `object Disabled extends sbt.librarymanagement.Disabled`
- This changes back to `final val Disabled = sbt.librarymanagement.Disabled` (but because we changed the companion object in sbt#290 that's ok)
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.

[1.2.x] CrossVersion.Disabled doesn't work
2 participants