-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add support for rules defined/compiled within the same build #100
Conversation
@@ -13,12 +13,13 @@ val rules = project | |||
.disablePlugins(ScalafixPlugin) | |||
.settings( | |||
scalaVersion := Versions.scala212, | |||
crossPaths := false, |
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.
That does not seem to be enough, as I see org.scala-lang:scala-library:2.13.1
in service/Scalafix/externalDependencyClasspath
, which would probably cause all sorts of errors if the rule was not dummy. Investigating.
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.
Actually, I can't write a test to show this is a problem, so I am going to assume it's not. I can find 2 explanations for that (I am not sure about them though):
scala-library is binary-compatible across minor releasessorry for the mixup, I checked again since I couldn't understand how it was possible, and it's only for patch release of course...- the parent classloader already has a 2.12 library (brought-in by
scalafix-cli
), so the 2.13 one in the bottom will effectively be ignored
@@ -21,6 +21,9 @@ object ScalafixPlugin extends AutoPlugin { | |||
object autoImport { | |||
val Scalafix = Tags.Tag("scalafix") | |||
|
|||
val ScalafixConfig = config("scalafix") |
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.
This is the third type of "scalafix config" after the function returning sbt settings applied to Compile
/Test
& the sbt setting referencing the actual configuration file for scalafix... I initially considered naming it simply Scalafix
to match its id, and deleting/renaming the current one 2 lines above since it's not used internally since 4dbaf1e, but that would be a breaking change.
I have added a questionable commit (1efa0cf) that enables and demonstrates declaration of a custom, local rule within the same project as the target code - mostly to honor/extend the description of the I say questionable, as we don't use this but have a multi-project setup as initially tested, and most importantly this has the strong consequence of coupling the scala version of the project with the one of the rules. In scalacenter/scalafix#1108, I have noted
I guess the "by default" imply that it would be possible to switch version anyway, so maybe it wouldn't be that much of a problem as sbt-scalafix could adapt to the rules scala version? |
Rebased and updated the first commit to clarify and improve the classloading layering. |
* Handle internalDependencyClasspath & externalDependencyClasspath separately, so that Coursier resolves transitive dependencies of local & remote rules together and evicts as needed * Tweak classloader hierarchy to keep core & global external dependencies warm across projects & invocations
Merging, as discussed in https://gitter.im/scalacenter/scalafix?at=5ec3f53d8fe27138ba6e01de |
In our fairly big sbt build, we have decided to collocate custom rule definitions with the sources they run against, using a separate sbt project of the same root build, in order to make the process of adding/updating them as seamless as possible (since they are not meant to be distributed or used anywhere else). It's working, but requires a quite hacky use of
--tool-classpath
which can only be passed once, with a lot of coursier-based code from here inlined.This is an attempt at bringing the feature upstream (that I refer to in the code as "local rules"), although I assume it's not a very common use-case.
I chose to implement it using an ivy configuration (which might have some side-effects I didn't think of!). That led me to 2 interesting thoughts:
scalafixDependencies
(see 72cd47c). I assume this has a tiny extra cost for sbt builds not running coursier (<1.3 or with >=1.3 with coursier explicitly disabled), since these dependencies end up being fetched/stored twice on disk (once into the ivy cache, once into the coursier one) as far as I understand. But it makes it possible to bring some rules only for some modules (not necessarilyThisBuild
likescalafixDependencies
). I am not sure it's worth documenting/advertizing though...dependency:*
, and I wouldn't know how to do that without coursier...