diff --git a/daml-assistant/daml-sdk/BUILD.bazel b/daml-assistant/daml-sdk/BUILD.bazel index 3e35f47f25b..161a88cdb80 100644 --- a/daml-assistant/daml-sdk/BUILD.bazel +++ b/daml-assistant/daml-sdk/BUILD.bazel @@ -43,6 +43,5 @@ da_scala_binary( ":sdk-lib", "//navigator/backend:backend-resources", "//navigator/backend:frontend-resources", - "//navigator/backend:version-resource", ], ) diff --git a/language-support/codegen-common/BUILD.bazel b/language-support/codegen-common/BUILD.bazel index c392595f750..ed670d1013b 100644 --- a/language-support/codegen-common/BUILD.bazel +++ b/language-support/codegen-common/BUILD.bazel @@ -14,6 +14,7 @@ da_scala_library( visibility = ["//visibility:public"], deps = [ "//daml-assistant/scala-daml-project-config", + "//libs-scala/build-info", "@maven//:ch_qos_logback_logback_classic", "@maven//:com_github_scopt_scopt_2_12", "@maven//:io_circe_circe_core_2_12", diff --git a/language-support/codegen-common/src/main/scala/com/digitalasset/daml/lf/codegen/conf/Conf.scala b/language-support/codegen-common/src/main/scala/com/digitalasset/daml/lf/codegen/conf/Conf.scala index d0cf8616406..eeb6938292c 100644 --- a/language-support/codegen-common/src/main/scala/com/digitalasset/daml/lf/codegen/conf/Conf.scala +++ b/language-support/codegen-common/src/main/scala/com/digitalasset/daml/lf/codegen/conf/Conf.scala @@ -6,11 +6,9 @@ package com.digitalasset.daml.lf.codegen.conf import java.nio.file.{Path, Paths} import ch.qos.logback.classic.Level +import com.digitalasset.buildinfo.BuildInfo import scopt.{OptionParser, Read} -import scala.io.Source -import scala.util.Try - /** * * @param darFiles The [[Set]] of DAML-LF [[Path]]s to convert into code. It MUST contain @@ -35,7 +33,7 @@ object Conf { parser.parse(args, Conf(Map.empty, Paths.get("."))) def parser: OptionParser[Conf] = new scopt.OptionParser[Conf]("codegen") { - head("codegen", Version) + head("codegen", BuildInfo.Version) note("Code generator for the DAML ledger bindings.\n") arg[(Path, Option[String])]("...")( @@ -104,8 +102,4 @@ object Conf { } } - lazy val Version: String = - Try(Source.fromResource("MVN_VERSION").getLines.reduce((t, u) => t + u).trim) - .getOrElse("{component version not found on classpath}") - } diff --git a/language-support/java/codegen/BUILD.bazel b/language-support/java/codegen/BUILD.bazel index 2102fdb19d8..e19baee655e 100644 --- a/language-support/java/codegen/BUILD.bazel +++ b/language-support/java/codegen/BUILD.bazel @@ -32,7 +32,6 @@ load("@os_info//:os_info.bzl", "is_windows") da_scala_binary( name = "codegen", - data = ["//:MVN_VERSION"], main_class = "com.digitalasset.daml.lf.codegen.StandaloneMain", visibility = ["//visibility:public"], deps = [":lib"], @@ -43,7 +42,6 @@ da_scala_library( srcs = glob(["src/main/**/*.scala"]), resources = [ "src/main/resources/logback.xml", - "//:MVN_VERSION", ], tags = ["maven_coordinates=com.daml.java:codegen-lib:__VERSION__"], visibility = ["//visibility:public"], diff --git a/ledger/sandbox/BUILD.bazel b/ledger/sandbox/BUILD.bazel index 78ea442a658..a75f6e6e489 100644 --- a/ledger/sandbox/BUILD.bazel +++ b/ledger/sandbox/BUILD.bazel @@ -35,6 +35,7 @@ compile_deps = [ "//ledger/participant-state", "//ledger/participant-state-index", "//ledger/participant-state/kvutils", + "//libs-scala/build-info", "//libs-scala/contextualized-logging", "//libs-scala/direct-execution-context", "//libs-scala/ports", @@ -83,9 +84,7 @@ da_scala_library( # Do not include logback.xml into the library: let the user # of the sandbox-as-a-library decide how to log. exclude = ["src/main/resources/logback.xml"], - ) + [ - "//:MVN_VERSION", - ], + ), tags = ["maven_coordinates=com.digitalasset.platform:sandbox:__VERSION__"], visibility = [ "//visibility:public", @@ -103,9 +102,7 @@ da_scala_library( # Do not include logback.xml into the library: let the user # of the sandbox-as-a-library decide how to log. exclude = ["src/main/resources/logback.xml"], - ) + [ - "//:MVN_VERSION", - ], + ), tags = ["maven_coordinates=com.daml.ledger:ledger-api-server:__VERSION__"], visibility = [ "//visibility:public", @@ -197,8 +194,6 @@ alias( visibility = ["//visibility:public"], ) -#TODO: generate dynamic BuildInfo.scala - da_scala_library( name = "sandbox-scala-tests-lib", srcs = glob(["src/test/lib/**/*.scala"]), diff --git a/ledger/sandbox/src/main/scala/com/digitalasset/platform/apiserver/StandaloneApiServer.scala b/ledger/sandbox/src/main/scala/com/digitalasset/platform/apiserver/StandaloneApiServer.scala index 5c65fafcdb1..a47afa4465b 100644 --- a/ledger/sandbox/src/main/scala/com/digitalasset/platform/apiserver/StandaloneApiServer.scala +++ b/ledger/sandbox/src/main/scala/com/digitalasset/platform/apiserver/StandaloneApiServer.scala @@ -14,6 +14,7 @@ import com.codahale.metrics.MetricRegistry import com.daml.ledger.participant.state.v1.SeedService.Seeding import com.daml.ledger.participant.state.v1.{ParticipantId, ReadService, SeedService, WriteService} import com.digitalasset.api.util.TimeProvider +import com.digitalasset.buildinfo.BuildInfo import com.digitalasset.daml.lf.engine.Engine import com.digitalasset.grpc.adapter.ExecutionSequencerFactory import com.digitalasset.ledger.api.auth.interceptor.AuthorizationInterceptor @@ -23,7 +24,6 @@ import com.digitalasset.ledger.api.health.HealthChecks import com.digitalasset.logging.{ContextualizedLogger, LoggingContext} import com.digitalasset.platform.apiserver.StandaloneApiServer._ import com.digitalasset.platform.configuration.{ - BuildInfo, CommandConfiguration, PartyConfiguration, SubmissionConfiguration diff --git a/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/SandboxServer.scala b/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/SandboxServer.scala index fd6837f3b8e..1d8e0d652d6 100644 --- a/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/SandboxServer.scala +++ b/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/SandboxServer.scala @@ -14,6 +14,7 @@ import com.codahale.metrics.MetricRegistry import com.daml.ledger.participant.state.v1.{ParticipantId, SeedService} import com.daml.ledger.participant.state.{v1 => ParticipantState} import com.digitalasset.api.util.TimeProvider +import com.digitalasset.buildinfo.BuildInfo import com.digitalasset.daml.lf.data.{ImmArray, Ref} import com.digitalasset.daml.lf.engine.Engine import com.digitalasset.dec.DirectExecutionContext @@ -30,7 +31,6 @@ import com.digitalasset.platform.apiserver.{ LedgerApiServer, TimeServiceBackend } -import com.digitalasset.platform.configuration.BuildInfo import com.digitalasset.platform.packages.InMemoryPackageStore import com.digitalasset.platform.sandbox.SandboxServer._ import com.digitalasset.platform.sandbox.banner.Banner diff --git a/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/cli/Cli.scala b/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/cli/Cli.scala index caf9bfa398a..f7ee7c20166 100644 --- a/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/cli/Cli.scala +++ b/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandbox/cli/Cli.scala @@ -9,13 +9,13 @@ import java.time.Duration import ch.qos.logback.classic.Level import com.auth0.jwt.algorithms.Algorithm import com.daml.ledger.participant.state.v1.SeedService.Seeding +import com.digitalasset.buildinfo.BuildInfo import com.digitalasset.daml.lf.data.Ref import com.digitalasset.jwt.{ECDSAVerifier, HMAC256Verifier, JwksVerifier, RSA256Verifier} import com.digitalasset.ledger.api.auth.AuthServiceJWT import com.digitalasset.ledger.api.domain.LedgerId import com.digitalasset.ledger.api.tls.TlsConfiguration import com.digitalasset.platform.common.LedgerIdMode -import com.digitalasset.platform.configuration.BuildInfo import com.digitalasset.platform.sandbox.config.SandboxConfig import com.digitalasset.platform.services.time.TimeProviderType import com.digitalasset.ports.Port diff --git a/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandboxnext/Runner.scala b/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandboxnext/Runner.scala index b83dafe666a..11f6367e2ad 100644 --- a/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandboxnext/Runner.scala +++ b/ledger/sandbox/src/main/scala/com/digitalasset/platform/sandboxnext/Runner.scala @@ -16,6 +16,7 @@ import com.daml.ledger.on.sql.SqlLedgerReaderWriter import com.daml.ledger.participant.state.kvutils.api.KeyValueParticipantState import com.daml.ledger.participant.state.v1 import com.digitalasset.api.util.TimeProvider +import com.digitalasset.buildinfo.BuildInfo import com.digitalasset.daml.lf.archive.DarReader import com.digitalasset.daml.lf.data.Ref import com.digitalasset.daml_lf_dev.DamlLf.Archive @@ -30,7 +31,6 @@ import com.digitalasset.platform.apiserver.{ TimeServiceBackend } import com.digitalasset.platform.common.LedgerIdMode -import com.digitalasset.platform.configuration.BuildInfo import com.digitalasset.platform.indexer.{ IndexerConfig, IndexerStartupMode, diff --git a/libs-scala/build-info/BUILD.bazel b/libs-scala/build-info/BUILD.bazel new file mode 100644 index 00000000000..094aaaf4483 --- /dev/null +++ b/libs-scala/build-info/BUILD.bazel @@ -0,0 +1,20 @@ +# Copyright (c) 2020 The DAML Authors. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +load( + "//bazel_tools:scala.bzl", + "da_scala_library", +) + +da_scala_library( + name = "build-info", + srcs = glob(["src/main/scala/**/*.scala"]), + resources = [ + "//:mvn_version_file", + ], + tags = ["maven_coordinates=com.digitalasset:build-info:__VERSION__"], + visibility = [ + "//:__subpackages__", + ], + deps = [], +) diff --git a/ledger/sandbox/src/main/scala/com/digitalasset/platform/configuration/BuildInfo.scala b/libs-scala/build-info/src/main/scala/com/digitalasset/buildinfo/BuildInfo.scala similarity index 63% rename from ledger/sandbox/src/main/scala/com/digitalasset/platform/configuration/BuildInfo.scala rename to libs-scala/build-info/src/main/scala/com/digitalasset/buildinfo/BuildInfo.scala index 4123e8fc028..bc1936a4c18 100644 --- a/ledger/sandbox/src/main/scala/com/digitalasset/platform/configuration/BuildInfo.scala +++ b/libs-scala/build-info/src/main/scala/com/digitalasset/buildinfo/BuildInfo.scala @@ -1,19 +1,20 @@ // Copyright (c) 2020 The DAML Authors. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -package com.digitalasset.platform.configuration +package com.digitalasset.buildinfo import java.io.{BufferedReader, InputStreamReader} +import scala.collection.JavaConverters.asScalaIteratorConverter + object BuildInfo { val Version: String = - Option(this.getClass.getClassLoader.getResourceAsStream("MVN_VERSION")).fold { + Option(getClass.getClassLoader.getResourceAsStream("MVN_VERSION")).fold { "{component version not found on classpath}" } { is => try { val reader = new BufferedReader(new InputStreamReader(is)) - reader.lines().reduce("", (t: String, u: String) => t + u).trim - + reader.lines.iterator.asScala.mkString.trim } finally { is.close() } diff --git a/navigator/backend/BUILD.bazel b/navigator/backend/BUILD.bazel index 60ff7581112..cbe43938521 100644 --- a/navigator/backend/BUILD.bazel +++ b/navigator/backend/BUILD.bazel @@ -30,15 +30,6 @@ java_import( visibility = ["//visibility:public"], ) -# Version file, as a top level resources. -java_library( - name = "version-resource", - resources = [ - "//:MVN_VERSION", - ], - visibility = ["//visibility:public"], -) - # Static backend resources. java_library( name = "backend-resources", @@ -73,6 +64,7 @@ da_scala_library( "//ledger/ledger-api-client", "//ledger/ledger-api-common", "//ledger/ledger-api-domain", + "//libs-scala/build-info", "//libs-scala/grpc-utils", "@maven//:com_chuusai_shapeless_2_12", "@maven//:com_github_pureconfig_pureconfig_2_12", @@ -146,7 +138,6 @@ da_scala_binary( ":backend-resources", ":frontend-resources", ":navigator-library", - ":version-resource", ], ) @@ -168,13 +159,13 @@ da_scala_test_suite( ":navigator-library", ":navigator-tests-library", ":test-resources", - ":version-resource", "//daml-lf/data", "//daml-lf/interface", "//daml-lf/transaction", "//language-support/scala/bindings", "//ledger-service/lf-value-json", "//ledger/ledger-api-common", + "//libs-scala/build-info", "@maven//:com_typesafe_akka_akka_actor_2_12", "@maven//:com_typesafe_akka_akka_http_2_12", "@maven//:com_typesafe_akka_akka_http_core_2_12", diff --git a/navigator/backend/src/main/scala/com/digitalasset/navigator/NavigatorBackend.scala b/navigator/backend/src/main/scala/com/digitalasset/navigator/NavigatorBackend.scala index a19e3ce2cd0..bda4e46760e 100644 --- a/navigator/backend/src/main/scala/com/digitalasset/navigator/NavigatorBackend.scala +++ b/navigator/backend/src/main/scala/com/digitalasset/navigator/NavigatorBackend.scala @@ -6,11 +6,10 @@ package com.digitalasset.navigator import java.nio.file.{Files, Paths} import java.util.UUID -import scala.io.Source - import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route +import com.digitalasset.buildinfo.BuildInfo object NavigatorBackend extends UIBackend { @@ -20,7 +19,7 @@ object NavigatorBackend extends UIBackend { override def applicationInfo: ApplicationInfo = ApplicationInfo( id = s"Navigator-${UUID.randomUUID().toString}", name = "Navigator", - version = Source.fromResource("MVN_VERSION").mkString("").trim(), + version = BuildInfo.Version, ) override def banner: Option[String] = Some( diff --git a/release/artifacts.yaml b/release/artifacts.yaml index bf79a2d7064..f03c2fae36f 100644 --- a/release/artifacts.yaml +++ b/release/artifacts.yaml @@ -221,4 +221,6 @@ mavenUpload: false - target: //triggers/runner:trigger-runner-lib type: jar-scala +- target: //libs-scala/build-info:build-info + type: jar-scala