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

The "Generating files" HOWTO is broken for 0.13.0 #971

Closed
Blaisorblade opened this issue Nov 11, 2013 · 5 comments
Closed

The "Generating files" HOWTO is broken for 0.13.0 #971

Blaisorblade opened this issue Nov 11, 2013 · 5 comments

Comments

@Blaisorblade
Copy link
Contributor

According to http://www.scala-sbt.org/0.13.0/docs/Howto/generatefiles.html:

sourceGenerators in Compile += <your Task[Seq[File]] here>

But this simply doesn't work. It's obvious why when comparing with the 0.12.4 version, which gives:

sourceGenerators in Compile <+= <your Task[Seq[File]] here>

Now, that's just not the kind of change which happened between 0.12 and 0.13. Edit: I spoke a bit too soon; you can replace <+= with += if the type on the right changes, and loses the Initialize part, but it's not the case here, probably because it's a setting containing a task.

This is visible in the example. Example given for 0.12.4:

sourceGenerators in Compile <+= sourceManaged in Compile map { dir =>
  val file = dir / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}

Example given for 0.13.0, but non-working:

sourceGenerators in Compile += Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}

After replacing += with <+=, we get a example that works:

sourceGenerators in Compile <+= Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}

Error from the given 0.13.0 code (not very self-explanatory, I'd say):

> reload
[info] Loading project definition from /Users/pgiarrusso/Documents/Research/PhD/Teaching/SLE2013/public-material-repo/lectures/sbt-sample/project
/Users/pgiarrusso/Documents/Research/PhD/Teaching/SLE2013/public-material-repo/lectures/sbt-sample/build.sbt:8: error: No implicit for Append.Value[Seq[sbt.Task[Seq[java.io.File]]], sbt.std.FullInstance.M[Seq[java.io.File]]] found,
  so sbt.std.FullInstance.M[Seq[java.io.File]] cannot be appended to Seq[sbt.Task[Seq[java.io.File]]]
sourceGenerators in Compile += Def.task {
                            ^
[error] Type error in expression

I'd open a further bug saying "example code in documentation is not tested", but I don't know if you'd care and/or if the technology for fixing it exists.

@Blaisorblade
Copy link
Contributor Author

This was introduced in:
132e294#diff-1600cb100cbc40b8d0237585c4cd625d

Blaisorblade added a commit to Blaisorblade/xsbt that referenced this issue Nov 11, 2013
Fix sbt#971.

Note that this is no complete fix, because this solution uses an
operator which is not any more described in the guide for 0.13.
@Blaisorblade
Copy link
Contributor Author

The above fix uses <+= which is not currently explained by the docs.

I also tried using value; however, the problem is that while I need to convert an Initialize[Task[T]] to a Task[T], .value will go all the way down to T, thanks to overloading resolution (see from Def.scala):

  implicit def macroValueI[T](in: Initialize[T]): MacroValue[T] = ???
  implicit def macroValueIT[T](in: Initialize[Task[T]]): MacroValue[T] = ???

I guess I could disambiguate the call by invoking the implicit explicitly, but the implicit name is not part of the documented API, so it does not sound like a good idea. However, an ascription on the return value does not work:

sourceGenerators in Compile <+= Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}

//Works
sourceGenerators in Compile += (Def.macroValueI(Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}).value: Task[Seq[File]])

//Also works
sourceGenerators in Compile += (Def.macroValueI(Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}).value)
//Doesn't work.
/*sourceGenerators in Compile += ((Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}).value: Task[Seq[File]])
 */

@harrah
Copy link
Member

harrah commented Nov 11, 2013

Your analysis is correct and sorry for the trouble. The underlying bug is #866.

@harrah harrah closed this as completed in 09fc6c1 Nov 11, 2013
harrah pushed a commit that referenced this issue Nov 11, 2013
Fix #971.

Note that this is no complete fix, because this solution uses an
operator which is not any more described in the guide for 0.13.
@Blaisorblade
Copy link
Contributor Author

Thanks for the prompt fix!

@harrah
Copy link
Member

harrah commented Nov 11, 2013

No problem. It will be a bit delayed getting pushed to the site due to being in an RC cycle.

harrah pushed a commit that referenced this issue Nov 13, 2013
Fix #971.

Note that this is no complete fix, because this solution uses an
operator which is not any more described in the guide for 0.13.
eed3si9n pushed a commit that referenced this issue Mar 21, 2014
Fix #971.

Note that this is no complete fix, because this solution uses an
operator which is not any more described in the guide for 0.13.

Conflicts:
	src/sphinx/Howto/generatefiles.rst
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

No branches or pull requests

2 participants