Commit Graph

69 Commits

Author SHA1 Message Date
Dale Wijnand d3d105515a
Don't warn on by-name keys
.. which is apparently what the type of bare vals in *.sbt files are.

Fixes #3299, again.
2017-09-11 14:46:33 +01:00
Dale Wijnand 8d9a3a35d2
Fix warnings in TaskLinterDSL.scala 2017-09-11 14:45:40 +01:00
eugene yokota 33d3ba9d7c Merge pull request #3438 from Duhemm/source-appender
[1.0.x] `Append` instance to add `File` to `Seq[Source]`
2017-08-23 18:31:58 -04:00
Dale Wijnand 4f0d2f9ffd
Scalafmt 1.2.0 2017-08-14 15:47:52 +01:00
Martin Duhem 5815f1db0a
`Append` instance to add `File` to `Seq[Source]` 2017-08-14 15:47:17 +02:00
Dale Wijnand 805b76f3d4
Add back, re-configure & re-enable Scalafmt 2017-08-10 16:35:23 +01:00
Eugene Yokota 467617a4b9 Implement withRank 2017-07-25 01:50:53 -04:00
Martin Duhem 9dfe1a8406
Allow `.value` on SettingKey inside ifs & lambdas
Calling `.value` on a SettingKey doesn't trigger any execution and
doesn't have any side effect, so we can safely allow calls to `.value`
inside conditionals and lambdas.

Fixes #3299
2017-07-21 16:26:45 +02:00
Martin Duhem 347914191a Adapt to new library management API 2017-07-15 18:09:40 -04:00
Martin Duhem 3fe068a4c1 Adapt to changes in ConsoleAppender 2017-07-15 17:15:42 +02:00
Eugene Yokota 42a1e2a291 Improve the default prompt
Fixes #3313

This changes the default prompt to include "sbt:" + current project name.
See https://twitter.com/eed3si9n/status/884914670351659009
2017-07-13 14:58:10 -04:00
Dale Wijnand 0fe0de5fb3
Move the tuple enrichments into sbt.TupleSyntax
This undeprecates the syntax, but at the same times moves it out of
implicit scope, therefore requiring a 'import TupleSyntax._' to opt-in
to the old syntax.
2017-06-27 12:42:46 +01:00
Dale Wijnand c5b21ab9d9
Format Structure 2017-06-26 13:49:18 +01:00
jvican c85fb95851
Remove unnecessary infra for .value DSL check 2017-05-28 18:36:14 +02:00
jvican 6a31251a01
Add tests that check `sbtUnchecked` is respected 2017-05-28 18:31:45 +02:00
jvican b017eaee39
Support DSL detection for nested ifs and anons
Before, we were not preserving the value `insideXXX`. This commit makes
sure that we handle much more complex scenarios and we report them
successfully. Have a look at the tests.
2017-05-28 18:31:44 +02:00
jvican ded281b5c2
Add missing .value DSL check
The missing .value analysis is dumb on purpose because it's expensive.

Detecting valid use cases of idents whose type is an sbt key is
difficult and dangerous because we may miss some corner cases. Instead,
we report on the easiest cases in which we are certain that the user
does not want to have a stale key reference. Those are idents in the rhs
of val definitions with `_` as name and idents in statement position
inside blocks.

In the future, we can cover all val definitions no matter what their
name is. Unfortunately, doing so will come at the cost of speed: we have
to run the unused name analysis in `TypeDiagnostics` and expose it from
the power context in `ContextUtil`.

This is good enough for now. If users express interest in having a
smarter analysis, we can always consider trying the unused name
analysis. I am not sure how slow it will be -- hopefully it won't be
that much.
2017-05-28 18:08:58 +02:00
eugene yokota acf4a5ffc2 Merge pull request #3220 from eed3si9n/fport/3135
[fport] Fix += interference with sbt-buildinfo
2017-05-27 00:15:32 -04:00
Eugene Yokota bfc2d85d54 Fix += interference with sbt-buildinfo
The macro pattern match was too general. This makes it tighter.

Fixes #3132
2017-05-26 21:04:33 -04:00
Eugene Yokota 5dc46e3cf2 fix restligeist macro
Fixes sbt/sbt#3157

Before:

    PgpSettings.scala:99: exception during macro expansion:
    [error] java.lang.RuntimeException: Unexpected macro application tree (class scala.reflect.internal.Trees$Apply): PgpKeys.pgpStaticContext.<<=(sbt.this.Scoped.t2ToApp2[sbt.File, sbt.File](scala.Tuple2.apply[sbt.SettingKey[sbt.File], sbt.SettingKey[sbt.File]](PgpKeys.pgpPublicRing, PgpKeys.pgpSecretRing)).apply[com.jsuereth.pgp.cli.PgpStaticContext]({
    [error]   ((publicKeyRingFile: sbt.File, secretKeyRingFile: sbt.File) => SbtPgpStaticContext.apply(publicKeyRingFile, secretKeyRingFile))

After:

    build.sbt:18: error: `<<=` operator is removed. Use `key := { x.value }` or `key ~= (old => { newValue })`.
    See http://www.scala-sbt.org/1.0/docs/Migrating-from-sbt-012x.html
        publishLocal <<= foo // publishLocal.dependsOn(foo)
                     ^
    [error] sbt.compiler.EvalException: Type error in expression
2017-05-26 01:03:26 -04:00
jvican bd59f64727
Rename `sbt.unchecked` to `sbt.sbtUnchecked`
As per Eugene's suggestion.
2017-05-25 19:05:27 +02:00
jvican ca3acc4e52
Improve if check and prohibit value inside anon
This commit does the following things:

* Removes the boolean from the instance context passes to the linter.
* Prohibits the use of value inside anonymous functions.
* Improves the previous check of `value` inside if.

The improvements have occurred thanks to the fix of an oversight in the
traverser. As a result, several implementation of tasks have been
rewritten because of new compilation failures by both checks.

Note that the new check that prohibits the use of value inside anonymous
functions ignores all the functions whose parameters have been
synthesized by scalac (that can happen in a number of different
scenarios, like for comprehensions). Other scripted tests have also been
fixed.

Running `.value` inside an anonymous function yields the following
error:

```
[error] /data/rw/code/scala/sbt/main-settings/src/test/scala/sbt/std/TaskPosSpec.scala:50:24: The evaluation of `foo` inside an anonymous function is prohibited.
[error]
[error] Problem: Task invocations inside anonymous functions are evaluated independently of whether the anonymous function is invoked or not.
[error]
[error] Solution:
[error]   1. Make `foo` evaluation explicit outside of the function body if you don't care about its evaluation.
[error]   2. Use a dynamic task to evaluate `foo` and pass that value as a parameter to an anonymous function.
[error]
[error]       val anon = () => foo.value + " "
[error]                        ^
```
2017-05-25 17:21:29 +02:00
jvican 41dce9e568
Make sure that macro linter doesn't fail spuriously 2017-05-25 15:33:06 +02:00
jvican 8de2bfe461
Fix error message 2017-05-25 15:33:06 +02:00
jvican 2b12721a68
Add fully-fledged macro check for value inside if
`.value` inside the if of a regular task is unsafe. The wrapping task
will always execute the value, no matter what the if predicate yields.

This commit adds the infrastructure to lint code for every sbt DSL
macro. It also adds example of neg tests that check that the DSL checks
are in place.

The sbt checks yield error for this specific case because we may want to
explore changing this behaviour in the future. The solutions to this are
straightforward and explained in the error message, that looks like
this:

```
EXPECTED: The evaluation of `fooNeg` happens always inside a regular task.

PROBLEM: `fooNeg` is inside the if expression of a regular task.
  Regular tasks always evaluate task inside the bodies of if expressions.

SOLUTION:
  1. If you only want to evaluate it when the if predicate is true, use a dynamic task.
  2. Otherwise, make the static evaluation explicit by evaluating `fooNeg` outside the if expression.
```

Aside from those solutions, this commit also adds a way to disable any
DSL check by using the new `sbt.unchecked` annotation. This annotation,
similar to `scala.annotation.unchecked` disables compiler output. In our
case, it will disable any task dsl check, making it silent.

Examples of positive checks have also been added.

There have been only two places in `Defaults.scala` where this check has
made compilation fail.

The first one is inside `allDependencies`. To ensure that we still have
static dependencies for `allDependencies`, I have hoisted up the value
invocation outside the if expression. We may want to explore adding a
dynamic task in the future, though. We are doing unnecessary work there.

The second one is inside `update` and is not important because it's not
exposed to the user. We use a `taskDyn`.
2017-05-25 15:33:00 +02:00
jvican b4299e7f34
Add check of task invocation inside `if`
This commit adds the first version of the checker that will tell users
if they are doing something wrong.

The first version warns any user that write `.value` inside an if
expression.

As the test integration is not yet working correctly and messages are
swallowed, we have to println to get info from the test.
2017-05-24 17:27:18 +02:00
jvican 5b7180cfa7
Reorganize test structure for `mainSettings` 2017-05-24 11:27:04 +02:00
jvican 03daae49e2
Add test util to check neg macro tests 2017-05-24 10:21:52 +02:00
Eugene Yokota 2082f37e2a Rename Global as scope component to Zero
Fixes #3178

While working on the Scopes and Scope Delegation document, I noticed that the term Global in sbt is used for two different meaning.

1. Universal fallback scope component `*`
2. An alias for GlobalScope

This disambiguates the two by renaming ScopeAxis instance to Zero.
Since this is mostly internal to sbt code, the impact to the user should be minimal.
2017-05-08 11:41:48 -04:00
Eugene Yokota da046791e0 Apply Scalafmt formatting 2017-04-21 04:48:31 -04:00
Eugene Yokota 1ec7e8d975 format: off / format: on 2017-04-21 03:11:48 -04:00
Eugene Yokota 9e02995ac0 Bump to Zinc 1.0.0-X14 2017-04-18 00:56:22 -04:00
Dale Wijnand 91354497ab
Drop deprecated InputTask apply method 2017-04-11 16:44:53 +01:00
Dale Wijnand 0d32f6fc76
Drop File/Seq[File] setting enrichments 2017-04-11 16:42:43 +01:00
Dale Wijnand 4a08b65cb2
Drop ProjectReference implicit lifts 2017-04-11 16:40:38 +01:00
Dale Wijnand a6015793e2
Code formatting only changes 2017-04-11 14:32:38 +01:00
Dale Wijnand be3fa7e66d
Just whitespace & comment changes 2017-04-11 11:48:24 +01:00
eugene yokota 42b8da18c3 Merge pull request #3076 from eed3si9n/fport/2908
[fport] Fix triggeredBy/storeAs/etc using :=
2017-04-04 20:08:05 -07:00
Dale Wijnand f77eeed77e Avoid missleading, link the syntax migration guide
Fixes #2818
2017-04-04 16:52:31 -04:00
Dale Wijnand 7d5dd9999d
Remove some code duplication between TaskInstance and MultiInTask 2017-04-03 17:34:17 +01:00
Dale Wijnand ece85b44bd Merge pull request #3032 from dwijnand/setting-query-json
Start handling default types when serialising query setting values
2017-03-28 10:45:46 +01:00
Dale Wijnand 2bc5ba02f3
Add three more missing WeakTypeTags
.. accidentally removed in 12c2734052
2017-03-27 14:36:56 +01:00
Dale Wijnand 52de082b2e
Add OptJsonWriter to SettingKey 2017-03-27 14:15:11 +01:00
Dale Wijnand ad2f91e357
Extra getName/getImplicit in KeyMacro 2017-03-27 14:15:11 +01:00
Guillaume Martres 747aa48c9c Fix inputTaskDyn not working
This fixes the following error when trying to use inputTaskDyn in a build:

[error] /tmp/sbt_8316130f/input-task-dyn/build.sbt:11: error: Macro
expansion contains free type variable T defined by wrap in
InputConvert.scala:76:20. Have you forgotten to use c.WeakTypeTag
annotation for this type parameter? If you
have troubles tracking free type variables, consider using -Xlog-free-types (out-1)
[error]     runFoo := Def.inputTaskDyn { (out-1)
[error]                                ^ (out-1)
[info] [error] sbt.compiler.EvalException: Type error in expression (out-3) (out-1)

I have no idea what the error means, I just implemented the suggested fix.
2017-03-24 17:41:14 +01:00
Eugene Yokota 180bdfd129 Bump underlying modules to latest 2017-03-23 12:41:24 -04:00
Dale Wijnand 206c3e6d4d
Introduce Def displayBuildRelative/showBuildRelativeKey 2017-03-05 13:42:15 +00:00
Dale Wijnand e67cd6948b
Fix a bunch but not all compile warnings 2017-03-03 01:33:44 +01:00
Eugene Yokota 51f7d2e24a Adds an Append instance that extracts taskValue
This adds a macro-level hack to support += op for sourceGenerators and resourceGenerators using RHS of Initialize[Task[Seq[File]]].
When the types match up, the macro now calls `.taskValue` automatically.
2017-01-22 22:53:27 -05:00
Josh Soref 66ec720884 spelling: specify 2017-01-20 08:27:28 +00:00