typelevel / sbt-tpolecat

scalac options for the enlightened
Apache License 2.0
394 stars 54 forks source link

a number of options are being set in (Compile, doc) #36

Open yurique opened 3 years ago

yurique commented 3 years ago
sbt> show doc / scalacOptions
[info] * -encoding
[info] * utf8
[info] * -deprecation
[info] * -explaintypes
[info] * -feature
[info] * -language:existentials
[info] * -language:experimental.macros
[info] * -language:higherKinds
[info] * -language:implicitConversions
[info] * -unchecked
[info] * -Xcheckinit
[info] * -Xfatal-warnings
[info] * -Xlint:adapted-args
[info] * -Xlint:by-name-right-associative
[info] * -Xlint:constant
[info] * -Xlint:delayedinit-select
[info] * -Xlint:doc-detached
[info] * -Xlint:inaccessible
[info] * -Xlint:infer-any
[info] * -Xlint:missing-interpolator
[info] * -Xlint:nullary-override
[info] * -Xlint:nullary-unit
[info] * -Xlint:option-implicit
[info] * -Xlint:package-object-classes
[info] * -Xlint:poly-implicit-overload
[info] * -Xlint:private-shadow
[info] * -Xlint:stars-align
[info] * -Xlint:type-parameter-shadow
[info] * -Xlint:unsound-match
[info] * -Yno-adapted-args
[info] * -Ywarn-dead-code
[info] * -Ywarn-extra-implicit
[info] * -Ywarn-nullary-override
[info] * -Ywarn-nullary-unit
[info] * -Ywarn-numeric-widen
[info] * -Ywarn-unused:implicits
[info] * -Ywarn-unused:imports
[info] * -Ywarn-unused:locals
[info] * -Ywarn-unused:params
[info] * -Ywarn-unused:patvars
[info] * -Ywarn-unused:privates
[info] * -Ypartial-unification
[info] * -Xplugin:/Users/yurique/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-compiler_2.12.12/1.3.1/scalajs-compiler_2.12.12-1.3.1.jar

when publishing, this results in warnings:

[warn] bad option '-scalajs' was ignored
[warn] bad option '-deprecation' was ignored
[warn] bad option '-explain-types' was ignored
[warn] bad option '-explain' was ignored
[warn] bad option '-feature' was ignored
[warn] bad option '-language:existentials,experimental.macros,higherKinds,implicitConversions' was ignored
[warn] bad option '-unchecked' was ignored
[warn] bad option '-Xfatal-warnings' was ignored
[warn] bad option '-Ykind-projector' was ignored
[warn] bad option '-from-tasty' was ignored
[warn] bad option '-no-link-warnings' was ignored
[warn] Setting -encoding is currently not supported.

without the plugin:

sbt> show doc / scalacOptions
[info] * -Xplugin:/Users/yurique/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-js/scalajs-compiler_2.13.4/1.3.1/scalajs-compiler_2.13.4-1.3.1.jar
solarmosaic-kflorence commented 3 years ago

I noticed this too. Needs:

    scalacOptions in (Compile, doc) ~= (_.filterNot(
      Set(
        "-scalajs",
        "-deprecation",
        "-explain-types",
        "-explain",
        "-feature",
        "-language:existentials,experimental.macros,higherKinds,implicitConversions",
        "-unchecked",
        "-Xfatal-warnings",
        "-Ykind-projector",
        "-from-tasty",
        "-encoding",
        "utf8"
      )
    ))

Thank you for this fix Yurique.

solarmosaic-kflorence commented 3 years ago

FYI we are now using the https://github.com/ThoughtWorksInc/sbt-api-mappings plugin and have been able to reduce our necessary configuration to just:

Compile / doc / scalacOptions += "-no-link-warnings"
DavidGregory084 commented 2 years ago

I wonder if we can ask an sbt expert like @eed3si9n about this one?

At the moment this plugin simply sets scalacOptions without reference to any specific scope.

It seems like the best solution to this is to set those options only in the compile task, but I don't know enough about how sbt works to know whether that would prevent these options from being applied in other tasks that users would currently expect them to be applied to.

Are there other tasks than compile and doc that are relevant for scalacOptions?

eed3si9n commented 2 years ago

The plugin currently appends to unscoped scalacOptions or Zero / Zero / Zero / scalacOptions. As long as other scoped usages keep appending using += your settings will be picked up.

The three major usages of scalacOptions are: <Config>/compile/scalacOptions, <Config>/doc/scalacOptions, and <Config>/console/scalacOptions where <Config> may be Compile, Test, or some custom dependency configuration.

Looks like the plugin already handles Compile / console / scalacOptions and Test / console / scalacOptions. You could probably take a similar approach with Compile / doc / scalacOptions and Test / doc / scalacOptions.

If you only append to Compile / compile / scalacOptions, then Compile / doc and Compile / console won't get the flags, which might be ok. It would also mean that compile task in custom dependency configurations like IntegrationTest won't also get the flags.

Appending to Zero / compile / scalacOptions likely won't work due to scope axis precedence:

  • Rule 1: Scope axes have the following precedence: the subproject axis, the configuration axis, and then the task axis.
objektwerks commented 2 years ago

I just stumbled across this issue via this project ( github.com/objektwerks/scalajs/blob/master/build.sbt ). To avoid getting this error during sbt clean test ( java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val ), I had to add scalacOptions ++= Seq("-scalajs") to the build.sbt. Apparently sbt-tpolecat was removing the -scalajs option added by the Scalajs plugin ( addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1") ).

DavidGregory084 commented 2 years ago

@objektwerks looks like you are running into #102

objektwerks commented 2 years ago

Very well, then.:) I'll repost the above to #102. Should I remove the above post? Thanks!

DavidGregory084 commented 2 years ago

No that's ok, it's good to see the history of these bugs and the underlying discussion on the tickets :D

BusyByte commented 7 months ago

I've recently been having issues with doc command and I think -encoding utf8 is getting garbled with other scalac arguments. There's also another -encoding UTF-8 higher up which looks like it's correct. It's in there but getting garbled I think:

IJ]last Compile/doc
[info] Main Scala API documentation to /Users/myuser/projects/my-gh-org/my-project/target/scala-2.13/api...
[debug] Returning already retrieved and compiled bridge: /Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala2-sbt-bridge/2.13.13/scala2-sbt-bridge-2.13.13.jar.
[debug] Calling Scaladoc with arguments:
[debug]     -d
[debug]     /Users/myuser/projects/my-gh-org/my-project/target/scala-2.13/api
[debug]     -release
[debug]     9
[debug]     -encoding
[debug]     UTF-8
[debug]     -explaintypes
[debug]     -feature
[debug]     -language:existentials
[debug]     -language:experimental.macros
[debug]     -language:higherKinds
[debug]     -language:implicitConversions
[debug]     -unchecked
[debug]     -Xcheckinit
[debug]     -Xlint:adapted-args
[debug]     -Xlint:constant
[debug]     -Xlint:delayedinit-select
[debug]     -Xlint:deprecation
[debug]     -Xlint:doc-detached
[debug]     -Xlint:inaccessible
[debug]     -Xlint:infer-any
[debug]     -Xlint:missing-interpolator
[debug]     -Xlint:nullary-unit
[debug]     -Xlint:option-implicit
[debug]     -Xlint:package-object-classes
[debug]     -Xlint:poly-implicit-overload
[debug]     -Xlint:private-shadow
[debug]     -Xlint:stars-align
[debug]     -Xlint:strict-unsealed-patmat
[debug]     -Xlint:type-parameter-shadow
[debug]     -Xlint:-byname-implicit
[debug]     -Wunused:nowarn
[debug]     -Wdead-code
[debug]     -Wextra-implicit
[debug]     -Wnumeric-widen
[debug]     -Wunused:implicits
[debug]     -Wunused:explicits
[debug]     -Wunused:imports
[debug]     -Wunused:locals
[debug]     -Wunused:params
[debug]     -Wunused:patvars
[debug]     -Wunused:privates
[debug]     -Wvalue-discard
[debug]     -Vimplicits
[debug]     -Vtype-diffs
[debug]     -Xsource:3-cross
[debug]     -quickfix:cat=scala3-migration
[debug]     -Xplugin:target/scala-2.13/compiler_plugins/wartremover_2.13.13-3.1.6.jar
[debug]     utf8
[debug]     -Xlint:implicit-recursion
[debug]     -Xlint:implicit-not-found
[debug]     -Wnonunit-statement
[debug]     -bootclasspath
[debug]     /Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.13/scala-library-2.13.13.jar
[debug]     -classpath
[debug]     /Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-core_2.13/2.10.0/cats-core_2.13-2.10.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalacheck/scalacheck_2.13/1.17.0/scalacheck_2.13-1.17.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/github/chocpanda/scalacheck-magnolia_2.13/0.6.0/scalacheck-magnolia_2.13-0.6.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/sbt.myco.com/com/mycopackage/core_2.13/2.15.15/core_2.13-2.15.15.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_2.13/2.10.0/cats-kernel_2.13-2.10.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/propensive/magnolia_2.13/0.17.0/magnolia_2.13-0.17.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-effect_2.13/3.6-0142603/cats-effect_2.13-3.6-0142603.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-core_2.13/0.14.6/circe-core_2.13-0.14.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-generic_2.13/0.14.6/circe-generic_2.13-0.14.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-generic-extras_2.13/0.14.3/circe-generic-extras_2.13-0.14.3.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-parser_2.13/0.14.6/circe-parser_2.13-0.14.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-literal_2.13/0.14.6/circe-literal_2.13-0.14.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/sbt.myco.com/com/mycopackage/shared-proto-scala_2.13/1.0.354/shared-proto-scala_2.13-1.0.354.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/propensive/mercator_2.13/0.2.1/mercator_2.13-0.2.1.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-effect-kernel_2.13/3.6-0142603/cats-effect-kernel_2.13-3.6-0142603.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/cats-effect-std_2.13/3.6-0142603/cats-effect-std_2.13-3.6-0142603.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-numbers_2.13/0.14.6/circe-numbers_2.13-0.14.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/chuusai/shapeless_2.13/2.3.10/shapeless_2.13-2.3.10.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/io/circe/circe-jawn_2.13/0.14.6/circe-jawn_2.13-0.14.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/thesamet/scalapb/scalapb-runtime_2.13/0.11.15/scalapb-runtime_2.13-0.11.15.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/thesamet/scalapb/lenses_2.13/0.11.15/lenses_2.13-0.11.15.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/typelevel/jawn-parser_2.13/1.4.0/jawn-parser_2.13-1.4.0.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.19.6/protobuf-java-3.19.6.jar:/Users/myuser/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_2.13/2.11.0/scala-collection-compat_2.13-2.11.0.jar
[debug]     /Users/myuser/projects/my-gh-org/my-project/src/main/scala/com/my_co_package/models/package.scala
[error] IO error while decoding utf8 with UTF-8: utf8 (No such file or directory)
[error] Please try specifying another one using the -encoding option
[error] one error found
[error] Scaladoc generation failed
[error]     at scala.tools.xsbt.Runner.run(ScaladocBridge.scala:54)
[error]     at scala.tools.xsbt.ScaladocBridge.run(ScaladocBridge.scala:25)
[error]     at sbt.internal.inc.AnalyzingCompiler.doc(AnalyzingCompiler.scala:154)
[error]     at sbt.internal.inc.AnalyzingCompiler.doc(AnalyzingCompiler.scala:133)
[error]     at sbt.Doc$.$anonfun$scaladoc$1(Doc.scala:53)
[error]     at sbt.Doc$.$anonfun$scaladoc$1$adapted(Doc.scala:41)
[error]     at sbt.RawCompileLike$.$anonfun$prepare$1(RawCompileLike.scala:80)
[error]     at sbt.RawCompileLike$.$anonfun$prepare$1$adapted(RawCompileLike.scala:73)
[error]     at sbt.RawCompileLike$.$anonfun$cached$4(RawCompileLike.scala:64)
[error]     at sbt.RawCompileLike$.$anonfun$cached$4$adapted(RawCompileLike.scala:62)
[error]     at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:220)
[error]     at sbt.RawCompileLike$.$anonfun$cached$1(RawCompileLike.scala:69)
[error]     at sbt.RawCompileLike$.$anonfun$cached$1$adapted(RawCompileLike.scala:53)
[error]     at sbt.Defaults$.$anonfun$docTaskSettings$4(Defaults.scala:2164)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]     at sbt.Execute.work(Execute.scala:292)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]     at java.base/java.lang.Thread.run(Thread.java:833)
[error] (Compile / doc) Scaladoc generation failed

The only workaround I've found is not to publish docs (Compile / packageDoc / publishArtifact := false).

Here's my relevant settings:

tpolecatScalacOptions += ScalacOptions.release(ScalaSettings.scala213ReleaseValue),
    Compile / tpolecatExcludeOptions += ScalacOptions.fatalWarnings
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1")

cc @DavidGregory084

BusyByte commented 7 months ago

I think I figured out what is going on, we're adding scalac options outside of the plugin. Ignore the above ^^ it is not a problem if you don't do this.