-
Notifications
You must be signed in to change notification settings - Fork 22
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
Support sbt 1.4.0 #73
Conversation
c951e32
to
4f27bbc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this!
But I'm a bit confused about how your changes would solve the reported issue: java.lang.ClassCastException: sbt.internal.inc.MappedVirtualFile cannot be cast to java.io.File
. Can you explain whatever you've learned from your investigation so far?
project/build.properties
Outdated
@@ -1 +1 @@ | |||
sbt.version=1.3.13 | |||
sbt.version=1.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do this (from the release notes):
Note to plugin authors
If you build and publish a plugin using sbt 1.4.0, your users will also be forced to upgrade to sbt 1.4.0 immediately. >To prevent this you can cross build your plugin against sbt 1.2.8 (while using sbt 1.4.0) as follows:
pluginCrossBuild / sbtVersion := "1.2.8"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this project uses a custom release process, do you want me to update this line?
- releaseStepCommandAndRemaining(s"^^$latestSbt_1_x_version publish"),
+ releaseStepCommandAndRemaining(s"^^1.3.13 publish"),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err... yes I think so 😅
I'll try to explain using the diff in sbt/zinc@v1.3.5...v1.4.0 The major change comes in Relations.scala where allLibraryDeps changed from
Relations.scala sbt/zinc@v1.3.5...v1.4.0#diff-8f19e01c26867080078f05c80f07ae4c This PR simply converts the |
I see, I didn't spot the call to So conceptually what we want to do is: def toFile(x: AnyRef): File = x match {
case virtual: xsbti.VirtualFileRef =>
// sbt 1.4.0 or newer
val path = virtual.id().replaceAllLiterally("${CSR_CACHE}", csrCacheDirectoryValue)
new java.io.File(path)
case file: java.io.File =>
// sbt 1.3.x or older
file
}
val allLibraryDeps = analysis.relations.allLibraryDeps.map(toFile) But I think that will probably blow up in sbt 1.3.x or older because the As for compatibility with sbt 1.2.x and older, where the val extracted: Extracted = Project.extract(state.value)
val settings = extracted.session.original
settings.find(_.key.key.label == "csrCacheDirectory") match {
case Some(csrCacheDirectorySetting) =>
// sbt 1.3.0 or newer
val csrCacheDirectoryValue = csrCacheDirectorySetting.init.evaluate(extracted.structure.data)
...
case None =>
// sbt 1.2.x or older so the key doesn't exist
} Does this make sense? |
Makes perfect sense, I'll try doing your suggestions and see how it goes. |
1937f01
to
4cf5e47
Compare
@cb372 thanks for your help and review, now the PR is backward compatible and build passes for sbt 0.13.x, 1.2.x, 1.3.x and 1.4.x! I've marked it as ready for review, take another look when you get a chance |
However there is something wrong, it doesn't work locally for me. I'll check what's wrong |
Interestingly, if i use |
LGTM. As soon as I get a chance I'd like to do some manual testing with various sbt versions before merging. |
Unfortunately the reflection approach didn't work if we publish using 1.3.13 and run against 1.4.0. It throws a ClassCastException as soon as we do `analysis.relations.allLibraryDeps.map(...)`, because the type signature of `allLibraryDeps` it was built against (`Set[File]`) doesn't match the signature of `allLibraryDeps` on the classpath (`Set[VirtualFileRef]`). Worked around this by casting to `Set[AnyRef]`, but that means we can't use a type tag anymore. So I gave up on reflection and used `getClass` instead. Pretty nasty but it works. Confirmed manually that if we publish using 1.4.0 we can only run against 1.4.0, so we need to publish using 1.3.13.
This is a bit more robust than relying on the `toString` implementation
I played around with various sbt versions locally and ended up making some small changes. See my commit comments for the details. Once Travis is done, I'll merge and make a release. Thank you for your work on this fix! By the way, Travis doesn't catch this kind of compatibility issue because it runs |
Thanks for taking care of this! |
PR to address #70 and makes the plugin work with sbt 1.4.0
However this is a hack and doesn't address backward compatibility or has blunders. Reviews, comments or better versions welcome.