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

Unify sbt shell and build.sbt syntax (scope path syntax) #3434

Merged
merged 2 commits into from Sep 28, 2017

Conversation

Projects
None yet
3 participants
@eed3si9n
Member

eed3si9n commented Aug 14, 2017

Fixes #1812

This adds scope path syntax (fka unified slash syntax) for both sbt shell and the build.sbt DSL.

Scope path syntax in shell

Instead of the current <project-id>/config:intask::key, this adds <project-id>/<config-ident>/intask/key where <config-ident> is the Scala identifier notation for the configurations like Compile and Test. (The old shell syntax will continue to function)

Scope path syntax in build.sbt

This also adds a series of implicits called SlashSyntax that adds / operators to project references, configuration, and keys such that the same syntax works in build.sbt.

Examples

These examples work both from the shell and in build.sbt.

Global / cancelable
ThisBuild / scalaVersion
Test / test
root / Compile / compile / scalacOptions
ProjectRef(uri("file:/xxx/helloworld/"),"root")/Compile/scalacOptions
Zero / Zero / name

The inspect command now outputs something that can be copy-pasted:

> inspect compile
[info] Task: sbt.inc.Analysis
[info] Description:
[info] 	Compiles sources.
[info] Provided by:
[info] 	ProjectRef(uri("file:/xxx/helloworld/"), "root") / Compile / compile
[info] Defined at:
[info] 	(sbt.Defaults) Defaults.scala:326
[info] Dependencies:
[info] 	Compile / manipulateBytecode
[info] 	Compile / incCompileSetup
[info] Reverse dependencies:
[info] 	Compile / printWarnings
[info] 	Compile / products
[info] 	Compile / discoveredSbtPlugins
[info] 	Compile / discoveredMainClasses
[info] Delegates:
[info] 	Compile / compile
[info] 	compile
[info] 	ThisBuild / Compile / compile
[info] 	ThisBuild / compile
[info] 	Zero / Compile / compile
[info] 	Global / compile
[info] Related:
[info] 	Test / compile

slash

@jvican

This comment has been minimized.

Show comment
Hide comment
@jvican

jvican Sep 15, 2017

Member

Two questions:

  1. What's missing on this front for this to be merged?
  2. Is there any chance this can make it into the next sbt release?
Member

jvican commented Sep 15, 2017

Two questions:

  1. What's missing on this front for this to be merged?
  2. Is there any chance this can make it into the next sbt release?
@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Sep 15, 2017

Member
  1. I need to add mima exclusion, I think to pass Travis.
  2. I am hoping it will be in sbt 1.1.0, 1.2.0 or some feature release. Immediately next one will be sbt 1.0.2 (hotfix release).
Member

eed3si9n commented Sep 15, 2017

  1. I need to add mima exclusion, I think to pass Travis.
  2. I am hoping it will be in sbt 1.1.0, 1.2.0 or some feature release. Immediately next one will be sbt 1.0.2 (hotfix release).

@dwijnand dwijnand added this to the 1.1.0 milestone Sep 22, 2017

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Sep 22, 2017

Member

I've added this to the 1.1.0 milestone as it would be a good highlight feature of sbt 1.1.

Member

dwijnand commented Sep 22, 2017

I've added this to the 1.1.0 milestone as it would be a good highlight feature of sbt 1.1.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Sep 26, 2017

Member

Rebased to the latest 1.x branch, and added Mima exclusion.

Member

eed3si9n commented Sep 26, 2017

Rebased to the latest 1.x branch, and added Mima exclusion.

@dwijnand

This comment has been minimized.

Show comment
Hide comment
@dwijnand

dwijnand Sep 26, 2017

Member

Could you squash the commits?

Member

dwijnand commented Sep 26, 2017

Could you squash the commits?

@jvican

Comments in tests.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican @dwijnand Thanks guys for the review.

Member

eed3si9n commented Sep 27, 2017

@jvican @dwijnand Thanks guys for the review.

libraryDependencies += uTest % Test,
testFrameworks += new TestFramework("utest.runner.Framework"),
commands += Command("inspectCheck", inspectBrief, inspectDetailed)(Inspect.parser) {

This comment has been minimized.

@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican Added the inspect output test here.
Since the parser is shared, I didn't feel the need to test various modes for inspect, but the default mode has displays the keys, so I've added the test.

@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican Added the inspect output test here.
Since the parser is shared, I didn't feel the need to test various modes for inspect, but the default mode has displays the keys, so I've added the test.

$ mkdir target
> Test/test
# Check the side-effect of executing uTest
$ exists target/foo

This comment has been minimized.

@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican Added a small "test" that should check that that uTest in fact ran.

@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican Added a small "test" that should check that that uTest in fact ran.

> show Global / cancelable
# "ThisBuild" now works in shell.
> show ThisBuild/scalaVersion

This comment has been minimized.

@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican Added variants with and without whitespace around /.

@eed3si9n

eed3si9n Sep 27, 2017

Member

@jvican Added variants with and without whitespace around /.

Show outdated Hide outdated main-settings/src/main/scala/sbt/Reference.scala Outdated
Show outdated Hide outdated main-settings/src/main/scala/sbt/Def.scala Outdated
Show outdated Hide outdated main-settings/src/main/scala/sbt/Scope.scala Outdated
Show outdated Hide outdated main-settings/src/main/scala/sbt/Scope.scala Outdated
val thisRef = thisProjectRef.value
val label =
if (isPlugin) Reference.display(thisRef)
else Def.displayRelativeReference(extracted.currentRef, thisRef)

This comment has been minimized.

@dwijnand

dwijnand Sep 27, 2017

Member

huh, TIL that thisProjectRef != "the current project"

@dwijnand

dwijnand Sep 27, 2017

Member

huh, TIL that thisProjectRef != "the current project"

Show outdated Hide outdated main/src/main/scala/sbt/SlashSyntax.scala Outdated
/*
* data contains the mapping between a configuration and keys.
* identData contains the mapping between a configuration and its identifier.

This comment has been minimized.

@dwijnand

dwijnand Sep 27, 2017

Member

why is this necessary?

@dwijnand

dwijnand Sep 27, 2017

Member

why is this necessary?

This comment has been minimized.

@eed3si9n

eed3si9n Sep 27, 2017

Member

We can't change the type of Def.ScopeKey[_], which binds to sbt.Scope, which includes sbt.ConfigKey, a wrapper around a String that represents the name of configuration. The mapping information between the Scala identifier and String thus needs to be available during conversion back and forth. For example, if the user types in IntegrationTest/test, the new parser needs to parse it as ConfigKey("it") and AttributeKey[Unit]("test").

@eed3si9n

eed3si9n Sep 27, 2017

Member

We can't change the type of Def.ScopeKey[_], which binds to sbt.Scope, which includes sbt.ConfigKey, a wrapper around a String that represents the name of configuration. The mapping information between the Scala identifier and String thus needs to be available during conversion back and forth. For example, if the user types in IntegrationTest/test, the new parser needs to parse it as ConfigKey("it") and AttributeKey[Unit]("test").

Show outdated Hide outdated main/src/test/scala/ParseKey.scala Outdated
Show outdated Hide outdated main/src/test/scala/ParseKey.scala Outdated
Show outdated Hide outdated main/src/test/scala/ParseKey.scala Outdated
@dwijnand

2 requests, 1 more typo

Show outdated Hide outdated main-settings/src/main/scala/sbt/Scope.scala Outdated

eed3si9n added some commits Sep 27, 2017

Unified slash syntax
Fixes #1812

This adds unified slash syntax for both sbt shell and the build.sbt DSL.
Instead of the current `<project-id>/config:intask::key`,
this adds `<project-id>/<config-ident>/intask/key` where <config-ident> is the Scala identifier notation for the configurations like `Compile` and `Test`.

This also adds a series of implicits called `SlashSyntax` that adds `/` operators to project refererences, configuration, and keys such that the same syntax works in build.sbt.

These examples work for both from the shell and in build.sbt.

    Global / cancelable
    ThisBuild / scalaVersion
    Test / test
    root / Compile / compile / scalacOptions
    ProjectRef(uri("file:/xxx/helloworld/"),"root")/Compile/scalacOptions
    Zero / Zero / name

The inspect command now outputs something that can be copy-pasted:

    > inspect compile
    [info] Task: sbt.inc.Analysis
    [info] Description:
    [info] 	Compiles sources.
    [info] Provided by:
    [info] 	ProjectRef(uri("file:/xxx/helloworld/"),"root")/Compile/compile
    [info] Defined at:
    [info] 	(sbt.Defaults) Defaults.scala:326
    [info] Dependencies:
    [info] 	Compile/manipulateBytecode
    [info] 	Compile/incCompileSetup
    [info] Reverse dependencies:
    [info] 	Compile/printWarnings
    [info] 	Compile/products
    [info] 	Compile/discoveredSbtPlugins
    [info] 	Compile/discoveredMainClasses
    [info] Delegates:
    [info] 	Compile/compile
    [info] 	compile
    [info] 	ThisBuild/Compile/compile
    [info] 	ThisBuild/compile
    [info] 	Zero/Compile/compile
    [info] 	Global/compile
    [info] Related:
    [info] 	Test/compile
Add whitespaces in Show of scoped keys
```
Provided by:
    ProjectRef(uri("...."), "root") / Test / test
Dependencies:
    Test / executeTests
    Test / test / streams
    Test / state
    Test / test / testResultLogger
```

@dwijnand dwijnand merged commit 21bd7c3 into sbt:1.x Sep 28, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@eed3si9n eed3si9n deleted the eed3si9n:wip/slash branch Sep 28, 2017

@eed3si9n eed3si9n changed the title from Unify sbt shell and build.sbt syntax (unified slash syntax redux) to Unify sbt shell and build.sbt syntax (scope path syntax) Oct 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment