From fb4f10f3ae83e14c97f30a7e08f65704e65869c5 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Fri, 1 Jul 2022 13:34:43 +0200 Subject: [PATCH 1/2] bump compiler-interface and capture the diagnosticCode NOTE: It's important that in `Problem` we don't construct the actual `DiagnosticCode` _unless_ the method is called to get it. By doing this we keep compatibility ensuring that older build tools can still use the bridge just fine. That's what the `sbt-test/sbt-bridge` tests ensuring that this is still usable by an older tool using the old `Problem`. This then unlocks forwarding the diagnostic code on for tools to use. refs: https://github.com/lampepfl/dotty/issues/14904 --- project/Dependencies.scala | 2 +- .../dotty/tools/xsbt/DelegatingReporter.java | 3 ++- .../src/dotty/tools/xsbt/DiagnosticCode.java | 23 +++++++++++++++++++ sbt-bridge/src/dotty/tools/xsbt/Problem.java | 15 ++++++++++-- .../simple/project/Reporter.scala | 5 ++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 23ee5b7b0427..0d1e4f2786dc 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -25,6 +25,6 @@ object Dependencies { "com.vladsch.flexmark" % "flexmark-ext-yaml-front-matter" % flexmarkVersion, ) - val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.4.3" + val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.7.1" val oldCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.3.5" } diff --git a/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java b/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java index 6bf161fafebf..20cdfb720538 100644 --- a/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java +++ b/sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java @@ -39,12 +39,13 @@ public void doReport(Diagnostic dia, Context ctx) { StringBuilder rendered = new StringBuilder(); rendered.append(messageAndPos(dia, ctx)); Message message = dia.msg(); + String diagnosticCode = String.valueOf(message.errorId().errorNumber()); boolean shouldExplain = Diagnostic.shouldExplain(dia, ctx); if (shouldExplain && !message.explanation().isEmpty()) { rendered.append(explanation(message, ctx)); } - delegate.log(new Problem(position, message.msg(), severity, rendered.toString())); + delegate.log(new Problem(position, message.msg(), severity, rendered.toString(), diagnosticCode)); } private static Severity severityOf(int level) { diff --git a/sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java b/sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java new file mode 100644 index 000000000000..1a78ce73aa43 --- /dev/null +++ b/sbt-bridge/src/dotty/tools/xsbt/DiagnosticCode.java @@ -0,0 +1,23 @@ +package dotty.tools.xsbt; + +import java.util.Optional; + +final public class DiagnosticCode implements xsbti.DiagnosticCode { + private final String _code; + private final Optional _explanation; + + public DiagnosticCode(String code, Optional explanation) { + super(); + this._code = code; + this._explanation = explanation; + } + + public String code() { + return _code; + } + + public Optional explanation() { + return _explanation; + } + +} diff --git a/sbt-bridge/src/dotty/tools/xsbt/Problem.java b/sbt-bridge/src/dotty/tools/xsbt/Problem.java index 2f1a7acec00b..b88b2637d314 100644 --- a/sbt-bridge/src/dotty/tools/xsbt/Problem.java +++ b/sbt-bridge/src/dotty/tools/xsbt/Problem.java @@ -9,13 +9,15 @@ final public class Problem implements xsbti.Problem { private final String _message; private final Severity _severity; private final Optional _rendered; + private final String _diagnosticCode; - public Problem(Position position, String message, Severity severity, String rendered) { + public Problem(Position position, String message, Severity severity, String rendered, String diagnosticCode) { super(); this._position = position; this._message = message; this._severity = severity; this._rendered = Optional.of(rendered); + this._diagnosticCode = diagnosticCode; } public String category() { @@ -38,8 +40,17 @@ public Optional rendered() { return _rendered; } + public Optional diagnosticCode() { + // NOTE: It's important for compatibility that we only construct a + // DiagnosticCode here to maintain compatibility with older versions of + // zinc while using this newer version of the compiler. If we would + // contstruct it earlier, you'd end up with ClassNotFoundExceptions for + // DiagnosticCode. + return Optional.of(new DiagnosticCode(_diagnosticCode, Optional.empty())); + } + @Override public String toString() { - return "Problem(" + _position + ", " + _message + ", " + _severity + ", " + _rendered + ")"; + return "Problem(" + _position + ", " + _message + ", " + _severity + ", " + _rendered + ", " + _diagnosticCode + ")"; } } diff --git a/sbt-test/compilerReporter/simple/project/Reporter.scala b/sbt-test/compilerReporter/simple/project/Reporter.scala index f67d1ec51d91..6c3b60cebb3a 100644 --- a/sbt-test/compilerReporter/simple/project/Reporter.scala +++ b/sbt-test/compilerReporter/simple/project/Reporter.scala @@ -36,6 +36,11 @@ object Reporter { assert(line.isPresent() == true) assert(line.get() == 9) + val diagnosticCode = mainProblem.diagnosticCode() + assert(diagnosticCode.isPresent() == true) + val code = diagnosticCode.get() + assert(diagnosticCode.get().code() == "6") + val pointer = mainProblem.position().pointer() assert(pointer.isPresent() == true) assert(pointer.get() == 10) From a5414017e0bd01a651ac3231b7591e5ba91a81ca Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Thu, 28 Jul 2022 04:02:10 +0200 Subject: [PATCH 2/2] Update sbt to 1.7.1 (#15728) * dep: update fs2 submodule This is needed due to some scalablytyped stuff that changed in fs2. Without it, you'll get an error when updating the sbt 1.7.x that scalably typed doesn't support 1.7.x * dep: sync with latest staging http4s * dep: sync with latest scala-java8-compat This also allows us to get rid of the fnGen stuff and simplify the sbtTestCommand and sbtPublishCommand * dep: sync with latest cats in staging * dep: sync with latest munit-cats-effect * dep: sync with latest discipline and discipline-munit * dep: lock munit at 0.7.29 If not you'll have issues with http4s tests since http4s isn't using the 1.x version of munit yet * disable `tlFatalWarnings` in http4s * dep: lock scalacheck at 1.16.0 Without doing this it was getting stuck in CI --- community-build/community-projects/cats | 2 +- community-build/community-projects/discipline | 2 +- .../community-projects/discipline-munit | 2 +- community-build/community-projects/fs2 | 2 +- community-build/community-projects/http4s | 2 +- .../community-projects/munit-cats-effect | 2 +- .../community-projects/scala-java8-compat | 2 +- community-build/community-projects/scalacheck | 2 +- .../scala/dotty/communitybuild/projects.scala | 19 ++++++++----------- project/build.properties | 2 +- .../project/build.properties | 2 +- semanticdb/project/build.properties | 2 +- .../project/build.properties | 2 +- .../project/build.properties | 2 +- 14 files changed, 21 insertions(+), 24 deletions(-) diff --git a/community-build/community-projects/cats b/community-build/community-projects/cats index 704c7fd5d207..771c6c802f59 160000 --- a/community-build/community-projects/cats +++ b/community-build/community-projects/cats @@ -1 +1 @@ -Subproject commit 704c7fd5d2079854637885514fccb62165e267f7 +Subproject commit 771c6c802f59c72dbc1be1898081c9c882ddfeb0 diff --git a/community-build/community-projects/discipline b/community-build/community-projects/discipline index afd001326789..09c975b18dc0 160000 --- a/community-build/community-projects/discipline +++ b/community-build/community-projects/discipline @@ -1 +1 @@ -Subproject commit afd00132678985341db210b56f3b2ead1a8405c2 +Subproject commit 09c975b18dc0b4e10499fb2922abac82ea8b5252 diff --git a/community-build/community-projects/discipline-munit b/community-build/community-projects/discipline-munit index 38ea89226b8d..4e61f1861956 160000 --- a/community-build/community-projects/discipline-munit +++ b/community-build/community-projects/discipline-munit @@ -1 +1 @@ -Subproject commit 38ea89226b8ddedc891b160f75d57ae5177f19a1 +Subproject commit 4e61f186195660529e7a6f7461b939477735e3f4 diff --git a/community-build/community-projects/fs2 b/community-build/community-projects/fs2 index 457c025ef506..ac5275baf33b 160000 --- a/community-build/community-projects/fs2 +++ b/community-build/community-projects/fs2 @@ -1 +1 @@ -Subproject commit 457c025ef506457fc8a7a8ba3abbf8b607decd4a +Subproject commit ac5275baf33b03da0a461b5de735ee6a1f5a524e diff --git a/community-build/community-projects/http4s b/community-build/community-projects/http4s index fc0a18dd0a80..c3d46f561ed1 160000 --- a/community-build/community-projects/http4s +++ b/community-build/community-projects/http4s @@ -1 +1 @@ -Subproject commit fc0a18dd0a8091f0b2cdc87b58953e76efa47426 +Subproject commit c3d46f561ed1026ae54e1acbd5e4730f0498ea93 diff --git a/community-build/community-projects/munit-cats-effect b/community-build/community-projects/munit-cats-effect index 248187bec8dc..40e442827669 160000 --- a/community-build/community-projects/munit-cats-effect +++ b/community-build/community-projects/munit-cats-effect @@ -1 +1 @@ -Subproject commit 248187bec8dc540e06950b7faf8d0e0be1ad31b1 +Subproject commit 40e44282766919a105e9dbbccbc3d14b79fee335 diff --git a/community-build/community-projects/scala-java8-compat b/community-build/community-projects/scala-java8-compat index 57e1f7ccaa67..eb16484fe841 160000 --- a/community-build/community-projects/scala-java8-compat +++ b/community-build/community-projects/scala-java8-compat @@ -1 +1 @@ -Subproject commit 57e1f7ccaa67dcac2b4227ab1a6ee0fcb5f42023 +Subproject commit eb16484fe8410643e157696421eeb79910ba36d5 diff --git a/community-build/community-projects/scalacheck b/community-build/community-projects/scalacheck index 976db31cd549..0ac8005753ab 160000 --- a/community-build/community-projects/scalacheck +++ b/community-build/community-projects/scalacheck @@ -1 +1 @@ -Subproject commit 976db31cd549328167a90ecc6f5f31efa83cd845 +Subproject commit 0ac8005753ab98b6494fd631502201b97a103638 diff --git a/community-build/src/scala/dotty/communitybuild/projects.scala b/community-build/src/scala/dotty/communitybuild/projects.scala index dc8047a95935..a74f5d0ca4a3 100644 --- a/community-build/src/scala/dotty/communitybuild/projects.scala +++ b/community-build/src/scala/dotty/communitybuild/projects.scala @@ -140,7 +140,7 @@ final case class SbtCommunityProject( case Some(ivyHome) => List(s"-Dsbt.ivy.home=$ivyHome") case _ => Nil extraSbtArgs ++ sbtProps ++ List( - "-sbt-version", "1.6.2", + "-sbt-version", "1.7.1", "-Dsbt.supershell=false", s"-Ddotty.communitybuild.dir=$communitybuildDir", s"--addPluginSbtFile=$sbtPluginFilePath" @@ -265,9 +265,8 @@ object projects: lazy val scalacheck = SbtCommunityProject( project = "scalacheck", - sbtTestCommand = "jvm/test;js/test", - sbtPublishCommand = "jvm/publishLocal;js/publishLocal", - sbtDocCommand = forceDoc("jvm") + sbtTestCommand = "coreJVM/test;coreJS/test", + sbtPublishCommand = "coreJVM/publishLocal;coreJS/publishLocal" ) lazy val scalatest: SbtCommunityProject = SbtCommunityProject( @@ -506,10 +505,8 @@ object projects: lazy val scalaJava8Compat = SbtCommunityProject( project = "scala-java8-compat", - // the fnGen subproject must be built with 2.12.x - sbtTestCommand = s"++2.12.14; ++$compilerVersion; set fnGen/dependencyOverrides := Nil; test", - sbtPublishCommand = s"++2.12.14; ++$compilerVersion; set fnGen/dependencyOverrides := Nil; publishLocal", - scalacOptions = Nil // avoid passing Scala 3 options to Scala 2.12 in fnGen subproject + sbtTestCommand = "test", + sbtPublishCommand = "publishLocal", ) lazy val verify = SbtCommunityProject( @@ -550,8 +547,8 @@ object projects: lazy val cats = SbtCommunityProject( project = "cats", - sbtTestCommand = "set Global/scalaJSStage := FastOptStage;buildJVM;validateAllJS", - sbtPublishCommand = "catsJVM/publishLocal;catsJS/publishLocal", + sbtTestCommand = "set Global/scalaJSStage := FastOptStage;rootJVM/test;rootJS/test", + sbtPublishCommand = "rootJVM/publishLocal;rootJS/publishLocal", dependencies = List(discipline, disciplineMunit, scalacheck, simulacrumScalafixAnnotations), scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ysafe-init") // disable -Ysafe-init, due to -Xfatal-warning @@ -755,7 +752,7 @@ object projects: lazy val http4s = SbtCommunityProject( project = "http4s", - sbtTestCommand = "tests/test; server/test; client/test; ember-core/test; ember-server/test; ember-client/test; circe/test", + sbtTestCommand = """set ThisBuild / tlFatalWarnings := false; server/test; client/test; ember-core/test; ember-server/test; ember-client/test; circe/test""", sbtPublishCommand = "publishLocal", scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ysafe-init"), dependencies = List(cats, catsEffect3, fs2, disciplineMunit, scalacheckEffect) diff --git a/project/build.properties b/project/build.properties index c8fcab543a9c..22af2628c413 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.7.1 diff --git a/sbt-test/sbt-dotty/dotty-knowledge.i17/project/build.properties b/sbt-test/sbt-dotty/dotty-knowledge.i17/project/build.properties index c8fcab543a9c..22af2628c413 100644 --- a/sbt-test/sbt-dotty/dotty-knowledge.i17/project/build.properties +++ b/sbt-test/sbt-dotty/dotty-knowledge.i17/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.7.1 diff --git a/semanticdb/project/build.properties b/semanticdb/project/build.properties index c8fcab543a9c..22af2628c413 100644 --- a/semanticdb/project/build.properties +++ b/semanticdb/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.7.1 diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline-api-hash/project/build.properties b/tests/cmdTest-sbt-tests/sourcepath-with-inline-api-hash/project/build.properties index c8fcab543a9c..22af2628c413 100644 --- a/tests/cmdTest-sbt-tests/sourcepath-with-inline-api-hash/project/build.properties +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline-api-hash/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.7.1 diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties b/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties index c8fcab543a9c..22af2628c413 100644 --- a/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties @@ -1 +1 @@ -sbt.version=1.6.2 +sbt.version=1.7.1