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

Cross build for SBT 1.0.0-RC3 #57

Merged
merged 9 commits into from
Jul 31, 2017
Merged

Cross build for SBT 1.0.0-RC3 #57

merged 9 commits into from
Jul 31, 2017

Conversation

liff
Copy link
Contributor

@liff liff commented Jun 5, 2017

Uses scalariform for 2.12 from com.github.machaval organization (see #55 and #36) so perhaps this is not the final form.

build.sbt Outdated
if (scalaVersion.value startsWith "2.10.")
"org.scalariform" %% "scalariform" % "0.1.8"
else
"com.github.machaval" %% "scalariform" % "0.2.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

"org.scalariform" %% "scalariform" % "0.2.0"

Has been released, includes changes from the com.github.machaval fork, cross published for 2.10/11/12.

Please amend PR accordingly. Thanks

build.sbt Outdated
libraryDependencies += "org.scalariform" %% "scalariform" % "0.1.8"
libraryDependencies += {
if (scalaVersion.value startsWith "2.10.")
"org.scalariform" %% "scalariform" % "0.1.8"
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks, the reason for mentioning cross publishing is that library dependencies can now simply be:

libraryDependencies += "org.scalariform" %% "scalariform" % "0.2.0"

Copy link
Contributor Author

@liff liff Jul 11, 2017

Choose a reason for hiding this comment

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

Yeah, seems I failed to properly parse your last comment, sorry. Update on its way.

I was trying to look for 0.2.0 for 2.10 on Maven Central but I suppose its indexing hasn't caught up yet or something.

Copy link
Collaborator

Choose a reason for hiding this comment

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

right, it's not yet up on maven central, but the dependency resolves (0.2.0 was published an hour or so ago)

@liff liff changed the title Cross build for SBT 1.0.0-M6 Cross build for SBT 1.0.0-RC2 Jul 18, 2017
@godenji
Copy link
Collaborator

godenji commented Jul 19, 2017

@liff thanks for the update.

Scala 2.12.3 will soon be released (likely within days), I'd like to hold off on publishing a new sbt-scalariform release until that time (we're also waiting on a PR that brings embedded scalariform in Scala IDE up-to-date with latest version of scalariform).

More later.

@liff liff changed the title Cross build for SBT 1.0.0-RC2 Cross build for SBT 1.0.0-RC3 Jul 29, 2017
@godenji godenji merged commit 61f6aab into sbt:master Jul 31, 2017
@godenji
Copy link
Collaborator

godenji commented Aug 1, 2017

@liff thanks for the contribution, will be part of the 1.8.0 release (probably in a couple of weeks when sbt 1.0 lands) .

@liff
Copy link
Contributor Author

liff commented Aug 1, 2017

From my understanding of the announcement you don't necessarily have to wait for 1.0 final to release for it.

@liff liff deleted the topic/sbt-1.0 branch August 1, 2017 06:19
@godenji
Copy link
Collaborator

godenji commented Aug 1, 2017

Sure, but latest changes need to be vetted before releasing 1.8.0 to make sure everything is working properly, which is not the case right now, seems to be broken.

Did you try out 1.0.0-RC3 + scala 2.12 against PR changes? Everything's fine for 0.13.16 + 2.10.6, but when doing a ^publishLocal from sbt-scalariform and creating a sample sbt project with:

build.properties > 1.0.0-RC3
project/plugins.sbt > addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.0-SNAPSHOT")
src/main/scala > Sample.scala

formatting fails with:

[error] jawn.IncompleteParseException: exhausted input
[error] at jawn.Parser.parse(Parser.scala:362)
[error] at jawn.SyncParser.parse(SyncParser.scala:24)
[error] at jawn.SupportParser.parseUnsafe(SupportParser.scala:12)
[error] at jawn.SupportParser.parseUnsafe$(SupportParser.scala:11)
[error] at sjsonnew.support.scalajson.unsafe.Parser$.parseUnsafe(Parser.scala:8)
[error] at sbt.util.CacheStore$.$anonfun$jvalueIsoString$2(CacheStore.scala:17)
[error] at sjsonnew.IsoString$$anon$1.from(IsoString.scala:27)
[error] at sbt.util.PlainInput.read(Input.scala:29)
[error] at sbt.util.FileBasedStore.$anonfun$read$1(CacheStore.scala:61)
[error] at sbt.io.Using.apply(Using.scala:23)
[error] at sbt.util.FileBasedStore.read(CacheStore.scala:61)
[error] at sbt.util.Changed.uptodate(Tracked.scala:225)
[error] at sbt.util.Changed.$anonfun$apply$1(Tracked.scala:214)
[error] at com.typesafe.sbt.Scalariform$.apply(Scalariform.scala:62)
...

@liff
Copy link
Contributor Author

liff commented Aug 2, 2017

I didn't try actually. Assumed it'd just work. I'll check it out in the evening.

@godenji
Copy link
Collaborator

godenji commented Aug 2, 2017

Assumed it'd just work

Famous last words ;-)

Think your code is fine, looks like real cause of the exception may be upstream in sjsonnew. There are at least two problems that I can see.

First, in sbt 1.0 the empty file case seems to not be properly encoded by sjsonnew for jawn to consume. See sbt 1.0 Changed[0] vs. sbt 0.13.16 Changed[0]. In the latter the uptodate method catches IO exception whereas the former optimistically assumes that the (potentially empty) file can be read in as the target type.

Second, to workaround the first problem, even when stuffing dummy data (like "alignParameters=false") into target/sbt-scalariform/streams/compile/scalariformFormat/\$global/streams/scalariform-preferences, the data is for some reason not cached -- compile and scalariformFormat format sources over and over despite the preferences not having been changed.

Please try to sort this out, will likely involve modifying your code to workaround upstream issues. If you issue a new PR, please do so against my fork in the 1.8.0 branch, have some new functionality built on top of current master that will go into 1.8.0 release. That or fixup your fork and I'll clone it to test out changes prior to your issuing a PR to master.

p.s. you can run ^scripted from my fork on 1.8.0; if the tests pass then we're good.

Thanks

@liff
Copy link
Contributor Author

liff commented Aug 2, 2017

Opened a PR about the caching issue. I think the exception handling thing might be just a regression in SBT 1.0. I'll ask around in gitter tomorrow or open an issue.

@godenji
Copy link
Collaborator

godenji commented Aug 2, 2017

We're getting there, your PR to my fork solves the caching issue. Now we need to sort out the empty cache file scenario (which is always the case on fresh project, or after an sbt clean).

SBT 1.0 final is scheduled to be released in a couple of weeks. Hopefully they can be more defensive here. That, or we try to workaround the issue by checking the empty file case on our end.

@liff
Copy link
Contributor Author

liff commented Aug 7, 2017

It looks like this is going to be more complicated than even fixing the SBT regression. Changed is going to be deprecated but apparently without fixing the exception behavior in 1.0.0.

The suggested replacement is to use Tracked.inputChanged but its innards have also changed beween 0.13 and 1.0. In 0.13 the Equiv provided for the cached type is used to find out if the object changed. In 1.0 the logic has been changed to use hash code. Due to the somewhat curious way Equiv is defined for IFormattingPreferences (i.e. empty Map and defaults are equivalent), using inputChanged doesn't really work in 1.0 either.

I suppose one option could be to always write out the preferences in full so that the Equiv trick is not needed. What do you think?

@godenji
Copy link
Collaborator

godenji commented Aug 8, 2017

Agreed, 0.13 to 1.0 is full of pitfalls (dealing with similar problems trying to port sbt-eclipse to 1.0).

I have tried with Tracked.inputChanged (see below), always returns true regardless of whether or not formatting preferences have changed. I am not sure what is happening here, ideally we could use inputChanged instead of the following workaround:

Use our own internal definition of Changed with try/catch clause added (works, have in place on local branch), and then remove it when 0.13 support is dropped. At that point everything can be moved back under src/main/scala and a 1.0-specific implementation can be used.

Tracked.inputChanged attempt

private[sbt] class Changed[O: Equiv: JsonFormat](store: File) {

  def apply(ifChanged: O => Boolean, ifUnchanged: O => Boolean): O => Boolean = value => {
      val f = Tracked.inputChanged[O, Boolean](store) { case (changed, _) =>
        changed
      }   
      f(value)
    }   
  }

  def changed[O: Equiv: JsonFormat](store: File) = new Changed[O](CacheStore(store))

@liff
Copy link
Contributor Author

liff commented Aug 8, 2017

Yeah, Tracked.inputChanged doesn't work because (from what I can tell, check the links in my post above) it doesn't really use the Equiv instance in 1.0.

Using a custom Changed implementation is something I tried as well earlier but deemed a bit too hacky. However, having gone through all this, it's starting to look like the easiest option :)

@godenji
Copy link
Collaborator

godenji commented Aug 8, 2017

Life is too short, let's just get this PR fixed up and deal with perfection later (i.e. when sbt 0.13 can be dropped). Unless you have time that is, feel free to try to get inputChanged working alongside 0.13 if you like ;-)

I pushed patched Changed implementation to my fork on 1.8.0 branch. When you get the chance can you pull my latest changes and confirm that ^scripted tests pass for both 0.13.16 and 1.0.0-RC3?

@godenji
Copy link
Collaborator

godenji commented Aug 10, 2017

@liff Tests pass, think we're good to go for 1.8.0

godenji added a commit to godenji/sbt-scalariform that referenced this pull request Aug 10, 2017
@liff
Copy link
Contributor Author

liff commented Aug 10, 2017

Sorry, I was busy with other stuff the past couple of days.

Perhaps the Travis build should still be updated? The matrix from sbt-pgp should be a good template.

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