Skip to content
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

Add warning for upload of daml-script #20704

Draft
wants to merge 1 commit into
base: release/3.2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,24 @@ class PackageUpgradeValidator(
(oldPkgId2, oldPkg2),
)
}

def warnDamlScriptUpload(
mainPackage: (Ref.PackageId, Ast.Package),
allPackages: List[(Ref.PackageId, Ast.Package)],
)(implicit
loggingContext: LoggingContextWithTrace
): Unit = {
def showPackage(pkg: (Ref.PackageId, Ast.Package)): String =
s"${pkg._1} (${pkg._2.metadata.name}-${pkg._2.metadata.version})"

allPackages.foreach{case (pkgId, pkg) => pkg.metadata.name match {
case "daml-script" | "daml3-script" | "daml-script-lts" | "daml-script-lts-stable" =>
logger.warn(
"Upload of daml-script is deprecated, and will be prevented in Daml 3.3+. " +
s"Please remove the package ${showPackage((pkgId, pkg))} " +
s"from the dependencies of ${showPackage(mainPackage)}, and move any script tests to a separate package."
)
case _ =>
}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class PackageUploader(
dependencies <- dar.dependencies.parTraverse(archive =>
catchUpstreamErrors(Decode.decodeArchive(archive))
)
_ <- validatePackages(mainPackage :: dependencies)
allPackages = mainPackage :: dependencies
_ = packageUpgradeValidator.warnDamlScriptUpload(mainPackage, allPackages)(LoggingContextWithTrace(loggerFactory))
_ <- validatePackages(allPackages)
} yield hash
}

Expand Down Expand Up @@ -118,6 +120,7 @@ class PackageUploader(
catchUpstreamErrors(Decode.decodeArchive(archive)).map(archive -> _)
)
allPackages = mainPackage :: dependencies
_ = packageUpgradeValidator.warnDamlScriptUpload(mainPackage._2, allPackages.map(_._2))(LoggingContextWithTrace(loggerFactory))
hash <- EitherT(
uploadDarExecutionQueue.executeUS(
uploadDarSequentialStep(
Expand Down
4 changes: 4 additions & 0 deletions sdk/daml-lf/validation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ da_scala_test_suite(
"//test-common:upgrades-SucceedsWhenDepsDowngradeVersionsWithoutUsingDatatypes-dep-v2.dar",
"//test-common:upgrades-SucceedsWhenDepsDowngradeVersionsWithoutUsingDatatypes-v1.dar",
"//test-common:upgrades-SucceedsWhenDepsDowngradeVersionsWithoutUsingDatatypes-v2.dar",

# Tests for daml-script upload warning
"//test-common:upload-depends-on-script.dar",
"//test-common:upload-depends-on-script3.dar",
],
flaky = True,
scala_deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ object UpgradeCheckMain {
archive
}

dars.foreach(dar => validator.warnDamlScriptUpload(dar.main, dar.all))

val validation = validator.validateUpgrade(archives.toList)
Await.result(validation.value, Duration.Inf) match {
case Left(err: Validation.Upgradeability.Error) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.scalatest.{Assertion, Inside}

import java.io.{File, FileInputStream}
import scala.concurrent.Future
import scala.io.Source
import scala.util.{Failure, Success}

abstract class UpgradesSpecAdminAPI(override val suffix: String) extends UpgradesSpec(suffix) {
Expand Down Expand Up @@ -803,6 +804,28 @@ trait LongTests { this: UpgradesSpec =>
}
}
}

s"Uploading daml-script in gives a warning" in {
for {
res1 <- uploadPackage("test-common/upload-depends-on-script.dar")
res2 <- uploadPackage("test-common/upload-depends-on-script3.dar")
} yield {
val cantonLog = Source.fromFile(s"$cantonTmpDir/canton.log").mkString
def expectedMessageRegex(
res: (PackageId, Option[Throwable]),
scriptSuffix: String,
): Assertion = {
val actual = filterLog(cantonLog, res._1)
val expected =
s"Please remove the package [a-z0-9]+ \\(daml$scriptSuffix\\-script\\-[^\\)]*\\) " +
s"from the dependencies of ${res._1} \\(upload\\-depends\\-on\\-script$scriptSuffix\\-1\\.0\\.0\\)"
actual should include regex (expected)
res._2 shouldBe empty
}
expectedMessageRegex(res1, "")
expectedMessageRegex(res2, "3")
}
}
}

abstract class UpgradesSpec(val suffix: String)
Expand Down
15 changes: 15 additions & 0 deletions sdk/test-common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,21 @@ da_scala_dar_resources_library(
),
]

[
daml_compile(
name = "upload-depends-on-script{}".format(scriptSuffix),
srcs = ["src/main/daml/upgrades/DependsOnScript/Main.daml"],
data_dependencies = ["//daml-script/daml{scriptSuffix}:daml{scriptSuffix}-script.dar".format(scriptSuffix = scriptSuffix)],
target = "2.1",
version = "1.0.0",
visibility = ["//visibility:public"],
)
for scriptSuffix in [
"",
"3",
]
]

[
[
filegroup(
Expand Down
12 changes: 12 additions & 0 deletions sdk/test-common/src/main/daml/upgrades/DependsOnScript/Main.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

module Main where

import Daml.Script

main : Script ()
main = pure ()

data SomeSerializableType = SomeSerializableType

Loading