Commit Graph

5295 Commits

Author SHA1 Message Date
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 239280f137 Merge pull request #3216 from scalacenter/macro-usability-improvements
Add first round of DSL checks to sbt
2017-05-25 14:30:40 -04:00
jvican bd59f64727
Rename `sbt.unchecked` to `sbt.sbtUnchecked`
As per Eugene's suggestion.
2017-05-25 19:05:27 +02:00
jvican 7b8e8cadf4
Execute macro tests in Travis 2017-05-25 18:39:24 +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 2692bec21d
Reformat sbt source (minor changes) 2017-05-24 11:17:45 +02:00
jvican fd4bf0e635
Replace previous scalafmt plugin by neo-scalafmt
The previous scalafmt plugin had two problems:

* Caching with Coursier did not work correctly
* It failed after the upgrade to 1.0 in my computer (from a clean fork):

```
[error] (testingProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (runProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (taskProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (stdTaskProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (actionsProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (protocolProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (commandProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (mainSettingsProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (mainProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (sbtProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (scriptedPluginProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] (scriptedSbtProj/compile:scalafmtInc) java.lang.NoClassDefFoundError: Could not initialize class scala.meta.package$
[error] Total time: 19 s, completed May 24, 2017 10:44:56 AM
```

This commit replaces the previous scalafmt integration by the one
created by Lucidsoftware, big shoutout! (/cc @pauldraper)

https://github.com/lucidsoftware/neo-sbt-scalafmt
2017-05-24 11:15:22 +02:00
jvican e846f72ff3
Tell neg test suite the classpath via sbt 2017-05-24 10:27:51 +02:00
jvican 03daae49e2
Add test util to check neg macro tests 2017-05-24 10:21:52 +02:00
eugene yokota 88b2e84559 Merge pull request #3211 from scalacenter/move-sbt-util-second-attempt
Move `util-appmacro` to sbt as `core-macros`
2017-05-23 22:05:23 -04:00
jvican 10c737ae20
Move to `core-macros` and depend on it 2017-05-24 00:16:26 +02:00
jvican d2f019a47a
Reformat all util-appmacro 2017-05-24 00:16:23 +02:00
jvican ed38fcd695
Move `util-appmacro` to sbt as `core-macros`
This commit moves everything behind the old util-appmacro over to
sbt/sbt.

appmacro has been renamed as core-macros. It is indeed the project
that defines the main logic to manipulate macros, and defines interfaces
that are then implemented by main-settings. Because of this strong
relationship between these two modules, I find that they have to stay
together and be able to be modified in one commit. I've realised this
while hacking on the macro changes for the usability of sbt.

The reason for this change is because the logic of this module is really
tight to the implementation of sbt and, I would even say, essentially
define the sbt DSL.
2017-05-24 00:16:21 +02:00
jvican db88e89c42
Merge HEAD, branch 'move-util-2' of ../sbt-util into move-sbt-util-second-attempt 2017-05-24 00:13:52 +02:00
Dale Wijnand 5e585e50da Merge pull request #3200 from eed3si9n/wip/testlog2
Fixes content log not showing up on test task
2017-05-19 07:55:24 +01:00
Eugene Yokota 2b5637270a update TestFramework
- update reset.sh for debugging
- use Vector around TestFramework
- unbind existing appdenders from newLog
- register string codec for TestStringEvent
2017-05-19 00:16:19 -04:00
Eugene Yokota b013c30c30 Fix content log not showing up on `test`
Fixes #3198

Bump util to 1.0.0-M24. This fixes content log not showing up on `test`
2017-05-19 00:15:19 -04:00
eugene yokota b5cc77ef75 Merge pull request #3193 from dwijnand/better-toError-migration-notes
Better toError migration notes [ci skip]
2017-05-16 16:42:54 -04:00
Dale Wijnand 859b334a51
Better toError migration notes [ci skip] 2017-05-16 10:21:14 +01:00
eugene yokota d3ff3fb63a migrate PluginTrigger and ProjectOrigin to Contraband (#3191)
and move TestFramework to a non case class.
2017-05-13 13:01:51 +01:00
Dale Wijnand 50cc045a70 Merge pull request #3189 from eed3si9n/wip/more-case-class
[sbt 1.0] migrate ForkOptions to Contraband
2017-05-12 11:12:48 +01:00
Eugene Yokota 3724277704 migrate ForkOptions to Contraband 2017-05-12 05:22:08 -04:00
Dale Wijnand 0b2081bc3c Merge pull request #3184 from dwijnand/sbt-1-on-1
Upgrade the build to use sbt 1.0.0-M5
2017-05-11 10:31:21 +01:00
Dale Wijnand 0b33c195ef
Upgrade the build to sbt 1.0.0-M5
Some plugins remain commented out, for now.

sbt-doge is no longer needed because a variant of it has been folded
into sbt 1.

For some reason scripted requires src/doc jars of sbt, so switch back to
using `publishAll` rather than `publishLocalBinAll`. :(

Also, the sys.prop change in scripted is to force log4j2 to not use a
thread context classloader, and avoid the following:

    ERROR StatusLogger Unable to create custom ContextSelector. Falling back to default.
     java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.async.AsyncLoggerContextSelector to org.apache.logging.log4j.core.selector.ContextSelector
    	at java.lang.Class.cast(Class.java:3369)
    	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:201)
    	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:226)
    	at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:97)
    	at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:58)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    	at java.lang.Class.newInstance(Class.java:442)
    	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94)
    	at org.apache.logging.log4j.spi.ThreadContextMapFactory.createThreadContextMap(ThreadContextMapFactory.java:73)
    	at org.apache.logging.log4j.ThreadContext.init(ThreadContext.java:223)
    	at org.apache.logging.log4j.ThreadContext.<clinit>(ThreadContext.java:202)
    	at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:83)
    	at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:67)
    	at org.apache.logging.log4j.core.lookup.ContextMapLookup.<init>(ContextMapLookup.java:34)
    	at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:117)
    	at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:125)
    	at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:46)
    	at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:650)
    	at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:487)
    	at sbt.internal.util.ConsoleAppender.<init>(ConsoleAppender.scala:245)
    	at sbt.internal.util.ConsoleAppender$.apply(ConsoleAppender.scala:196)
    	at sbt.internal.util.ConsoleLogger.<init>(ConsoleAppender.scala:42)
    	at sbt.internal.util.ConsoleLogger$.apply(ConsoleAppender.scala:34)
    	at sbt.test.ScriptedRunner.run(ScriptedTests.scala:221)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at Scripted$.doScripted(Scripted.scala:125)
    	at $0483e89d182e9d240274$.$anonfun$scriptedTask$5(build.sbt:301)
2017-05-11 09:44:42 +01:00
eugene yokota b1a1d03009 Merge pull request #3180 from eed3si9n/wip/zero2
[sbt 1.0] Rename scope component Global to Zero (`in Global` stays the same)
2017-05-10 16:48:40 -04:00
eugene yokota a265600154 Merge pull request #3151 from scalacenter/parallel-scripted-tests
Add parallel batch mode to scripted tests
2017-05-10 16:46:01 -04:00
jvican f967f6c1d7
Split project and aggregate project-load 2017-05-10 21:40:23 +02:00
jvican 272afa9d73
Try another travis structure + build tweaks
I've tried to put together some scripted tests to remove the overhead of
compiling the whole sbt, which is around 3 minutes every time.

This new structure *should* make the scripted tests run faster.

Aside from this, we do some more tweaks:

* Increase memory.
* Fork processes to compile and run (to see if it makes a difference).
* Pass in the server flag to sbt.
2017-05-10 21:40:23 +02:00
jvican 6813eb47af
Up memory for every scripted instance 2017-05-10 21:40:23 +02:00
jvican 3d6e0f9327
Handle empty case in `labelsAndDirs` 2017-05-10 21:40:22 +02:00
jvican 5e44ec7c53
Fix string-to-command to ignore existing commands
The scripted batch executor injects a command and the operation
performed in this test checks all the commands, assuming only `noop` is
declared.
2017-05-10 21:40:22 +02:00
jvican e01f5f5ef1
Fix auto-plugins temporarily until #3163 is fixed
Unfortunately, I think this uncovers a bug in duplicated computation of
settings in the `ThisBuild` and `Global` axis.
2017-05-10 21:40:22 +02:00
jvican 388ed641fb
Create a compiler plugin for scripted
The compiler plugin is more appropriate than running a series of
commands because of the effects of `set`.
2017-05-10 21:40:22 +02:00
jvican 80c8883219
Reboot to ditch state produced by scripted reload 2017-05-10 21:40:22 +02:00
jvican 628517e60c
Try travis with 3 cores and 725M per instance 2017-05-10 21:40:21 +02:00
jvican 7519e63f50
Set name of root project if no name is known
This commit makes sure that between every run in batch mode the local
root project name is updated if no name is set.

This fixes project/generated-root-no-project that was assuming that the
root directory name was `generated-root-no-project`. This invariant does
not hold anymore with the batch-mode. Now one sbt dir is shared for lots
of scripted tests.
2017-05-10 21:40:21 +02:00
jvican 9b3a2e6f0f
Fix project/binary-plugin: Reload was implied
The first `>` that appears kickstarts the execution of sbt, so it
implies a reload. This is no longer true for the batch test execution.
2017-05-10 21:40:21 +02:00
jvican 8aee628297
Fix #3610: project/old-ops
`compile` does nothing in this test, what we need to do is `reload`.
2017-05-10 21:40:21 +02:00
jvican 0ebf2d14a3
Fix more tests using compiler iterations 2017-05-10 21:40:21 +02:00
jvican 6191f35f1c
Fix java options for scripted
* Remove MaxPermSize from another scripted opts
* Reduce memory of sbt host to 1g instead of 2g
* Add Xms java options to scripted
* Enable parallelism with 512M for sbt tests
* Parallelism + batch mode
2017-05-10 21:40:03 +02:00
jvican 5a23fa0e9a
Fix #3160: Newline after comment line 2017-05-10 21:40:03 +02:00
jvican dc048926c7
Fix fancy uses of analysis
Clean up first analysis to make sure that test utilities using
information from analysis have correct information that does not collide
with the compilation analysis of the previous runs (batch tests).
2017-05-10 21:40:03 +02:00
jvican 927910aa72
Fix compile tests using `checkIterations`
Those tests using `checkIterations` were not working because an
invariant was working: the first iterations number is 0. As we reuse
sbt for running several tests, this is no longer true, so this commit
makes sure that they are updated with the pertinent infrastructure to
compute the performed iterations from the latest known number of
iterations.
2017-05-10 21:40:02 +02:00
jvican c94a445737
Use scripted hook to run reload
This saves us from duplicating error handling logic to correctly manage
`pending` tests whose projects don't even load (and make our reload)
fail.
2017-05-10 21:40:02 +02:00
jvican 210dcde822
Run pre hook only after checking disabled tests 2017-05-10 21:40:02 +02:00