These are chat archives for sbt/sbt

1st
Sep 2015
Harmeet Singh(Taara)
@harmeetsingh0013
Sep 01 2015 03:59
@jsuereth which compile space you talk about?
the output is so huge, it is ambiguous to put whole output on chat.
matanster
@matanster
Sep 01 2015 12:42

Good morning.. How would you get all projects of a multi-project build, through the api, outside of a Task? within a task, it can be done like so

val projects = Project.extract(state).structure.allProjectRefs

But outside a task, not sure how I can get a state for calling extract.

This is for an sbt plugin I am writing (which needs to pass the name of each project to the compiler plugin I develop, on each compiler invocation, so that the compiler plugin can keep its outputs organized by project names).
This message was deleted
matanster
@matanster
Sep 01 2015 13:11
I'd also have to then set scalacOptions with the project's name, per project, rather than uniformly set it for all projects as in a typical scalacOptions in(Compile, compile).
Can these be accomplished with the api? I spent a couple of hours scanning the api docs and fiddling the api, for no avail.
Many thanks!
Sam Halliday
@fommil
Sep 01 2015 13:14
how can I set the default values for a TaskKey? Specifically I want to be able to allow the user to provide the initial values for https://github.com/ensime/ensime-sbt/blob/master/src/main/scala/EnsimePlugin.scala#L22
matanster
@matanster
Sep 01 2015 13:15
@fommil is this in an sbt plugin?
Sam Halliday
@fommil
Sep 01 2015 13:15
@matanster yes
Sam Halliday
@fommil
Sep 01 2015 13:18
are my projectSettings the defaults and anything the user provides will override it? I just don't understand which one wins
matanster
@matanster
Sep 01 2015 13:19
nope, sorry. don't know.
I think so, but I never saw this applied for task keys. Maybe give it a shot until people come online here.
Dale Wijnand
@dwijnand
Sep 01 2015 13:20
Yeah projectSettings will be applied first then user settings, but from http://www.scala-sbt.org/0.13/docs/Plugins.html#projectSettings+and+buildSettings it looks like globalSettings might be better for defaults
Sam Halliday
@fommil
Sep 01 2015 13:22
@dwijnand ok, then it sounds like I need to have two keys. Because I wanted one to depend on the other. I basically want to have a "base set" of strings and then the "ones derived from your project". And I want the user to be able to define the base set separately.
Dale Wijnand
@dwijnand
Sep 01 2015 13:24
sounds like how resolvers is set up, where resolvers is for users, but then combined with system defaults, so the final list of resolvers is fullResolvers
Sam Halliday
@fommil
Sep 01 2015 13:25
yup
Sam Halliday
@fommil
Sep 01 2015 13:54
in the ensime-sbt plugin we'd like to iterate through all the Configs that the user has defined, in order to find all the source directories and so on. How can we do that?
one of the biggest bugs at the moment (which also affects IntelliJ users, btw) is that custom test configs are completely ignored
this is seriously hurting the adoption of Fun test stages
If I could filter the Configs for things that look like tests, that would be even better
Dale Wijnand
@dwijnand
Sep 01 2015 13:58
@fommil looks like there's a ivyConfigurations key
Sam Halliday
@fommil
Sep 01 2015 13:59
@dwijnand cool! now, how do I get that? which setting is it in?
(ivyConfigurations in ....).value
Dale Wijnand
@dwijnand
Sep 01 2015 13:59
ivyConfigurations.value ?
scala> ivyConfigurations.eval
res0: Seq[sbt.Configuration] = List(compile, runtime, test, provided, optional, compile-internal, runtime-internal, test-internal, plugin, sources, docs, pom, scala-tool)
that's consoleProject where .value is .eval
Sam Halliday
@fommil
Sep 01 2015 14:01
cool, now to filter
Dale Wijnand
@dwijnand
Sep 01 2015 14:01
also, stop trying to make test stages fun, they're not :^)
Sam Halliday
@fommil
Sep 01 2015 14:01
any ideas how to filter on ones that look like tests?
hehe
this is common:
  lazy val Fun = config("fun") extend(Test)
Dale Wijnand
@dwijnand
Sep 01 2015 14:02
no idea what would qualify as "look like tests" or what the end goal is
Sam Halliday
@fommil
Sep 01 2015 14:02
so detecting that extend bit sounds feasible
matanster
@matanster
Sep 01 2015 14:03
@fommil "looks like" can be sorted in a compiler plugin that matches syntax patterns, but that would really be an overkill to go down to, unless you really have to.
Sam Halliday
@fommil
Sep 01 2015 14:03
@dwijnand end goal above, we want to print the source directories and dependency jars like we would for a built-in config phase
Dale Wijnand
@dwijnand
Sep 01 2015 14:04
Configuration has a "extendsConfigs: List[Configuration]" so you can traverse that
Sam Halliday
@fommil
Sep 01 2015 14:11
@dwijnand cool, that seems to be working, sort of. It's picking up a test-internal config, I'm not sure we want that.
Dale Wijnand
@dwijnand
Sep 01 2015 14:17
yeah not sure what that is, I think not though
Sam Halliday
@fommil
Sep 01 2015 14:20
@dwijnand sweet, this is working! I can take it from here, thanks
I can really tell this is the Right Thing To Do, because the original plugin code is now getting cleaner
Sam Halliday
@fommil
Sep 01 2015 14:34
who writes the SBT integration for IntelliJ these days? I want to ping them about this change I'm making in ensime-sbt because they should also implement the same thing.
(IntelliJ also ignores user defined test phases)
I'd open a ticket on YouTrack
Sam Halliday
@fommil
Sep 01 2015 14:39
@dwijnand I don't use IntelliJ. I've created a ticket on their issue tracker, ball is in their court now.
matanster
@matanster
Sep 01 2015 14:40
Sorry for not being helpful there.. my first sbt api usage.
Can anyone say how should I go from this (non-compiling) code that demonstrates the intent, to code that appends a variable scalac option to each project?
private def instrument(): State => State = { state =>
    Project.extract(state).structure.allProjectRefs foreach { projRef =>
      println("instrumenting project " + projRef.project + " (defined in " + projRef.build + ")")
      val scalacOption = Seq(s"-P:sbt-canve:projname:${projRef.project}")
      Project.extract(state).append(scalacOption, state)  
    }
    state
  }
I know that append is typically used to append settings.
However here I wish to append my compiler flag to scalacOptions, not override or add a duplicate scalacOptions.
Sam Halliday
@fommil
Sep 01 2015 14:43
@matanster have a look at ensime-sbt for almost exactly what you want. I assume you have to use the command API instead of the standard setting stuff? Because then you could just do scalacOptions += "my flag here"
matanster
@matanster
Sep 01 2015 14:44
@fommil I'll have a deep look
Sam Halliday
@fommil
Sep 01 2015 14:44
in particular look at our CommandSupport class which tries to make it easier to work with State
I should also imagine the scoverage plugin does something similar
Sam Halliday
@fommil
Sep 01 2015 14:53
I'm on an sbt plugin updating roll today, so got the confidence to tackle this ensime/ensime-sbt#89
I'd like to be able to launch main methods and tests with a temporary addition to the javaOptions. Is that possible? @jsuereth's suggestion to create a complementary Configuration for each existing configuration is a bit heavy handed.
assume the user already has fork in Foo := true
Sam Halliday
@fommil
Sep 01 2015 14:59
the user experience would work something like this:
enableExternalDebugging
module/test-only *FooTest
then when they are done doing all their debugging, they can either restart sbt or type
disableExternalDebugging
and I'd expect some flags to be added to javaFlags for every single Configuration during that period
matanster
@matanster
Sep 01 2015 15:05
@fommil I am still unsure how to append to a sub-project's scalacOptions, after having reviewed those projects and additional ones. Appending to the globally scoped scalacOptions only takes a call to Project.extract(state).append. but for a resolved subproject, Project.getProject(projRef, structure).get. and for a project ref, there is no such method. How did you get a grip over the api? do you append to sbt build settings there in the ensime plugin? I am beginning to lose track.
matanster
@matanster
Sep 01 2015 15:17
Is this where scope setting should come into play? I couldn't find an example of manipulating settings in project scope....
Sam Halliday
@fommil
Sep 01 2015 15:26
@matanster the sbt API is a nightmare. I find it incredibly frustrating to get anything done.
matanster
@matanster
Sep 01 2015 15:27
I hope someone from the dev team will chime in here later today...
I did all in my power to explore the api for this last task. This is all for improving user experience for my compiler plugin, in the case of a multi-project build definition.
Sam Halliday
@fommil
Sep 01 2015 15:51
@matanster I'm actually wanting to do exactly the same thing now. I want to mutate the javaOptions for each module
so whoever works it out first, tells the other one, deal? :smile:
Sam Halliday
@fommil
Sep 01 2015 16:04
@matanster yeah, .append not working for me either.
@sksamuel any hints on mutating the javaOptions like you do with the coverage task?
Sam Halliday
@fommil
Sep 01 2015 16:09
yes! It works
Sam Halliday
@fommil
Sep 01 2015 16:31
@matanster check the commit that closes this ticket ensime/ensime-sbt#89 (it's doing almost exactly what you want)
Sam Halliday
@fommil
Sep 01 2015 19:44
in ensime/ensime-sbt#88 I need to get the javadocs and sources associated to each jar for a LoadedBuildUnit, which I would normally get from an UpdateReport. But it doesn't seem to be possible to get an update report for a build unit... how can I do that?
Josh Suereth
@jsuereth
Sep 01 2015 19:54
not sure we expose that.....
The mechanism I commented on one of your other tickets for grabbing classpath is basically the thing we "erase" an update report into
if it doesn't ahve ModuleID attaached to a Seq[Attributed[File]] then it may not be exposed at all
it's tricky to know what they are doing but they seem to be able to do this
btw, this is the ticket you commented on. I just moved the ticket.
btw, if you deprecate Build.scala files, I hope that comes along with a PR to ENSIME to support .sbt files :-P
Sam Halliday
@fommil
Sep 01 2015 20:02
I'm trying to work out where the implicit ProjectRef is coming from
Josh Suereth
@jsuereth
Sep 01 2015 20:04
you'd have to see where they use it, I guess
Sam Halliday
@fommil
Sep 01 2015 20:40
@jsuereth oh for goodness sake, it's trivial! updateSbtClassifiers
Greg Symons
@gregsymons
Sep 01 2015 20:41
There's no way to make an AutoPlugin depend on a Plugin is there?
As in there's no way to put it in the list of requires.
Sam Halliday
@fommil
Sep 01 2015 21:45
how can I get the version of scala that sbt is using (not my project's version)?
oh, hold on, that's a stupid question. It's in the standard place, I don't need to inspect the structure