Commit Graph

56 Commits

Author SHA1 Message Date
Eugene Yokota 3f958a5bce enable -deprecation for Scala 2.10
Enable -deprecation flag to catch old code being use when we migrate
things.
In this commit I moved error to sys.error.
2014-10-10 15:42:26 -04:00
Eugene Yokota f318436725 Deprecate parseScopedKey 2014-08-05 11:28:28 -04:00
Eugene Yokota ee01908369 Fixes #1384. Fixes Scope.parseScopedKey
Scope.parseScopedKey now supports full range of legal keys
described in the documentation including {.} and other
notation for ProjectRef, BuildRef, and ThisBuild.
2014-08-05 11:28:28 -04:00
Dan Sanduleac 5deb103ef6 Fix resolving Select(ThisProject) 2014-05-21 01:16:15 +01:00
Josh Suereth 244abd3b6f Scalariforming test code 2014-05-07 11:52:23 -04:00
Eugene Yokota 785b0274ee some more source getting formatted 2014-05-02 18:07:05 -04:00
Eugene Yokota adb41611cf added scalariform 2014-05-01 12:50:07 -04:00
Dan Sanduleac 512494cd04 Couple of fixes 2014-05-01 01:35:48 +01:00
Dan Sanduleac 0377a40cf8 Optimise scope intersection for GlobalScope 2014-05-01 01:35:48 +01:00
Josh Suereth a8ab2f3db9 Merge pull request #1115 from metasim/Structure-docs
Added basic documentation for DefinableSetting, inferring behavior from implementation.
2014-03-03 14:16:21 -05:00
Jason Zaugg bd943b8e83 using compat._ to plug source compatibility breakages
This commit makes the code source compatible across Scala 2.10.3
and https://github.com/scala/scala/pull/3452, which is proposed
for inclusion in Scala 2.11.0-RC1.

We only strictly need the incremental compiler to build on Scala
2.11, as that is integrated into the IDE. But we gain valuable
insight into compiler regressions by building *all* of SBT with
2.11.

We only got there recently (the 0.13 branch of SBT now fully cross
compiles with 2.10.3 and 2.11.0-SNAPSHOT), and this aims to keep
things that way.

Once 2.10 support is dropped, SBT macros will be able to exploit
the new reflection APIs in 2.11 to avoid the need for casting
to compiler internals, which aren't governed by binary compatibility.
This has been prototyped by @xeno-by: https://github.com/sbt/sbt/pull/1121
2014-02-17 14:53:59 +01:00
Simeon H.K. Fitch 9f43d0660d Revised documentation based on feedback from @jsuereth 2014-02-12 15:37:49 -05:00
Simeon H.K. Fitch 7f6abbaf35 Added basic documentation for DefinableSetting, inferring behavior from implementation. 2014-02-12 12:31:15 -05:00
Jason Zaugg 264e49a912 Avoid compiler crash for naked `key.value` calls.
Untyped trees underneath typed trees makes Jack and sad boy.
And they make superaccessors a sad phase.

The recent refactoring to retain original types in the trees
representing the argument to the task macro meant that the `value`
macro also was changed to try to avoid this untyped-under-typed
problem. However, it didn't go deep enough, and left the child
trees of the placeholder tree `InputWrapper.wrap[T](key)` untyped.

This commit uses `c.typeCheck` to locally typeheck that tree fully
instead.

Fixes #1031
2014-01-28 10:45:15 +01:00
Mark Harrah c669606999 TaskKey[T].previous: Option[T], which returns the value of the task the last time it executed.
This requires a Format[T] to be implicitly available at the call site and requires the task
to be referenced statically (not in a settingDyn call).  References to previous task values
in the form of a ScopedKey[Task[T]] + Format[T] are collected at setting load time in the
'references' setting.  These are used to know which tasks should be persisted (the ScopedKey)
and how to persist them (the Format).

When checking/delegating previous references, rules are slightly different.

A normal reference from a task t in scope s cannot refer to t in s unless
there is an earlier definition of t in s.  However, a previous reference
does not have this restriction.  This commit modifies validateReferenced
to allow this.

TODO: user documentation
TODO: stable selection of the Format when there are multiple .previous calls on the same task
TODO: make it usable in InputTasks, specifically Parsers
2013-12-06 20:45:01 -05:00
Mark Harrah fcb35f3b8f Add Initialize[Task[T]].taskValue: Task[T] to allow selecting the Task for use by *Generators. Fixes #866. 2013-11-24 18:24:15 -05:00
Mark Harrah 3b213e59ca Remove the need for resetLocalAttrs. Fixes #994, #952.
The fix was made possible by the very helpful information provided by @retronym.

This commit does two key things:
 1. changes the owner when splicing original trees into new trees
 2. ensures the synthetic trees that get spliced into original trees do not need typechecking

Given this original source (from Defaults.scala):

  ...
  lazy val sourceConfigPaths = Seq(
    ...
    unmanagedSourceDirectories := Seq(scalaSource.value, javaSource.value),
    ...
  )
  ...

After expansion of .value, this looks something like:

    unmanagedSourceDirectories := Seq(
      InputWrapper.wrapInit[File](scalaSource),
      InputWrapper.wrapInit[File](javaSource)
    )

where wrapInit is something like:

    def wrapInit[T](a: Any): T

After expansion of := we have (approximately):

    unmanagedSourceDirectories <<=
      Instance.app( (scalaSource, javaSource) ) {
        $p1: (File, File) =>
          val $q4: File = $p1._1
          val $q3: File = $p1._2
          Seq($q3, $q4)
      }

So,

 a) `scalaSource` and `javaSource` are user trees that are spliced into a tuple constructor after being temporarily held in `InputWrapper.wrapInit`
 b) the constructed tuple `(scalaSource, javaSource)` is passed as an argument to another method call (without going through a val or anything) and shouldn't need owner changing
 c) the synthetic vals $q3 and $q4 need their owner properly set to the anonymous function
 d) the references (Idents) $q3 and $q4 are spliced into the user tree `Seq(..., ...)` and their symbols need to be the Symbol for the referenced vals
 e) generally, treeCopy needs to be used when substituting Trees in order to preserve attributes, like Types and Positions

changeOwner is called on the body `Seq($q3, $q4)` with the original owner sourceConfigPaths to be changed to the new anonymous function.
In this example, no owners are actually changed, but when the body contains vals or anonymous functions, they will.

An example of the compiler crash seen when the symbol of the references is not that of the vals:

symbol value $q3 does not exist in sbt.Defaults.sourceConfigPaths$lzycompute
	at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:49)
	at scala.tools.nsc.Global.abort(Global.scala:254)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadIdent$1(GenICode.scala:1038)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1044)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1246)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1244)
   ...

Other problems with the synthetic tree when it is spliced under the original tree often result in type mismatches or some other compiler error that doesn't result in a crash.

If the owner is not changed correctly on the original tree that gets spliced under a synthetic tree, one way it can crash the compiler is:

java.lang.IllegalArgumentException: Could not find proxy for val $q23: java.io.File in List(value $q23, method apply, anonymous class $anonfun$globalCore$5, value globalCore, object Defaults, package sbt, package <root>) (currentOwner= value dir )
   ...
     while compiling: /home/mark/code/sbt/main/src/main/scala/sbt/Defaults.scala
        during phase: global=lambdalift, atPhase=constructors
   ...
  last tree to typer: term $outer
              symbol: value $outer (flags: <synthetic> <paramaccessor> <triedcooking> private[this])
   symbol definition: private[this] val $outer: sbt.BuildCommon
                 tpe: <notype>
       symbol owners: value $outer -> anonymous class $anonfun$87 -> value x$298 -> method derive -> class BuildCommon$class -> package sbt
      context owners: value dir -> value globalCore -> object Defaults -> package sbt
   ...

The problem here is the difference between context owners and the proxy search chain.
2013-11-22 13:08:10 -05:00
Mark Harrah 9dcb8727d8 New method `toTask` on `Initialize[InputTask[T]]` to apply the full input and get a plain task out. 2013-10-18 16:49:34 -04:00
Mark Harrah 0507a2a1a9 Deprecate implicit RootProject/LocalProject calls on URI/File/String
Builds are using explicit calls anyway, so reduce the implicits.
2013-07-10 18:15:30 -04:00
Mark Harrah 284cddff70 set position on parameter references in task/setting macros 2013-06-19 11:53:11 -04:00
Mark Harrah 60b714e8de require dynamic initialization to be explicitly enabled for derived settings 2013-05-09 17:28:39 -04:00
Mark Harrah dfe418b3c3 Derived settings, which allows injecting settings wherever their dependencies are defined.
This is an advanced feature initially intended for internal sbt use.
2013-05-09 17:27:43 -04:00
Mark Harrah 5b80e8c941 use .evaluated instead of .value for InputTasks 2013-03-08 14:23:31 -05:00
Mark Harrah 387f06e73a partialInput/fullInput methods on InputTask to apply input programmatically. ref #407. 2013-03-08 14:23:31 -05:00
Mark Harrah d6f78db0c9 Construct input tasks in multiple steps to allow input task reuse. Fixes #407. 2013-03-08 14:23:30 -05:00
Mark Harrah 1fdf3fa38c support explicit types on lazy vals in definingValName
lazy val x: Project = project has a rather different enclosing tree
 than lazy val x = project.
2013-03-03 19:43:37 -05:00
Mark Harrah f6d73128fc deprecations 2013-02-25 09:24:04 -05:00
Mark Harrah 9ab1b98d2a Use @compileTimeOnly for .value and .parsed methods.
Needed to set position on wrapper method for correct error message position.
2013-02-19 08:54:40 -05:00
Mark Harrah a57407375e Implement InputTask.~= to operate directly on the result type T instead of an InputTask[T]. 2013-01-28 18:01:35 -05:00
Mark Harrah 13ea342b7a use standard Context.weakTypeOf 2013-01-28 17:14:53 -05:00
Mark Harrah 076480b50a Reduce InputTask to the ideal wrapper around 'State => Parser[Initialize[Task[T]]]'
Ref #407.
2013-01-28 17:14:53 -05:00
Mark Harrah 9013e00fdd Remove InputStatic and parsedResult.
This cleans up the InputTask implementation.  It no longer requires the hook
in setting loading (Load.finalTransforms) and has better types.
2013-01-18 18:49:26 -05:00
Mark Harrah aefad9c033 when looking for the enclosing val definition in definingValName, allow the macro to be in an expression 2013-01-10 16:06:12 -05:00
Mark Harrah f388b07632 fix inputTask construction method and put sbt package object in proper directory 2012-12-09 20:40:41 -05:00
Grzegorz Kossakowski ef39aeb9c1 Follow source layout convention supported by Eclipse.
Moved source files so directory structure follow package
structure. That makes it possible to use Scala Eclipse plugin
with sbt's source code.
2012-12-07 10:27:08 -08:00
Mark Harrah 005b2b356f fix IO tests, which needed scala-compiler.jar on the classpath 2012-12-04 13:20:03 -05:00
Mark Harrah cdd2e72cdf move top-level settingKey,taskKey,inputKey objects to Def and package object
avoids class file name collision on case insensitive filesystem
2012-12-04 13:08:52 -05:00
Mark Harrah 2598a8f1a9 extend source positions to all setting creation methods 2012-12-02 03:17:20 -05:00
Mark Harrah 2f2596c133 record source name or full path for settings/tasks depending on whether the enclosing package is the empty package 2012-12-02 03:17:20 -05:00
Mark Harrah a8d0af9464 split out KeyMacro.enclosingTrees 2012-12-02 03:17:20 -05:00
Mark Harrah 8400b992af source positions for settings/tasks in .scala files 2012-12-02 03:17:20 -05:00
Mark Harrah 3bff14d77a taskKey,settingKey,inputKey macros to get name from the defining val 2012-12-02 03:17:20 -05:00
Mark Harrah 538f687208 Use and methods instead of mapR,mapFailure,flatFailure,flatMapR 2012-12-02 03:17:19 -05:00
Mark Harrah a9289ad0ce Explicitly specify type parameters in calls to KCons in KList builder.
scalac couldn't infer the type constructor otherwise.
2012-11-18 09:20:26 -05:00
Mark Harrah 49e7214fe3 InputTask macro
Similar to task macros, the parsed value is accessed by calling `parsed`
on a Parser[T], Initialize[Parser[T]], or Initialize[State => Parser[T]].
Values of tasks and settings may be accessed as usual via `value`.
2012-11-17 20:23:07 -05:00
Mark Harrah 522414cd99 AbsTypeTag -> WeakTypeTag and converted more settings 2012-11-17 20:23:06 -05:00
Mark Harrah 4cc5bece70 address a valid unchecked warning
In order to correctly pattern match Tree subclasses in reflection/macros,
scalac needs the corresponding implicit for *Tag available because the types
are only abstract types.
2012-11-17 20:23:06 -05:00
Mark Harrah 2c7e9cd893 Scala 2.10.0-M7 2012-11-17 20:23:06 -05:00
Mark Harrah b453af7c45 Properly apply transformations to dynamic tasks.
That is, implement Initialize[Task[T]].flatten correctly.
This requires preserving the transformations applied in a scope so that
they can be applied to an Initialize value after static settings have been
evaluated.
2012-11-17 20:23:06 -05:00
Mark Harrah 0a642f2283 move explicit task/setting macros to Def, move to AbsTypeTag 2012-11-17 20:23:06 -05:00