diff --git a/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs b/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs index 974fee56dc0b..20bd18a00918 100644 --- a/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs +++ b/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs @@ -60,8 +60,7 @@ supportedOutputVersions :: [Version] supportedOutputVersions = [version1_14, versionDev] supportedInputVersions :: [Version] -supportedInputVersions = [version1_6, version1_7, version1_8, version1_11, version1_12, version1_13] ++ supportedOutputVersions - +supportedInputVersions = [version1_8, version1_11, version1_12, version1_13] ++ supportedOutputVersions data Feature = Feature { featureName :: !T.Text diff --git a/compiler/daml-lf-proto/BUILD.bazel b/compiler/daml-lf-proto/BUILD.bazel index 51165c17416d..26a7c6bf38c3 100644 --- a/compiler/daml-lf-proto/BUILD.bazel +++ b/compiler/daml-lf-proto/BUILD.bazel @@ -47,6 +47,7 @@ da_haskell_library( deps = [ ":daml-lf-util", "//compiler/daml-lf-ast", + "//compiler/damlc/stable-packages:stable-packages-list", "//daml-lf/archive:daml_lf_dev_archive_haskell_proto", "//libs-haskell/da-hs-base", ], diff --git a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Archive/Decode.hs b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Archive/Decode.hs index 32576dda8688..243157ceded6 100644 --- a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Archive/Decode.hs +++ b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Archive/Decode.hs @@ -55,7 +55,7 @@ decodePackage mode packageId payloadBytes = do DecodeAsMain -> LF.PRSelf DecodeAsDependency -> LF.PRImport packageId payload <- over _Left (ProtobufError . show) $ Proto.fromByteString payloadBytes - over _Left (ProtobufError. show) $ Decode.decodePayload selfPackageRef payload + over _Left (ProtobufError. show) $ Decode.decodePayload packageId selfPackageRef payload -- | Decode an LF archive header, returning the package-id and the payload decodeArchiveHeader :: BS.ByteString -> Either ArchiveError (LF.PackageId, BS.ByteString) diff --git a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Decode.hs b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Decode.hs index c35d8445e7ba..8ca24fc53f57 100644 --- a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Decode.hs +++ b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/Decode.hs @@ -7,13 +7,13 @@ module DA.Daml.LF.Proto3.Decode ) where import Com.Daml.DamlLfDev.DamlLf (ArchivePayload(..), ArchivePayloadSum(..)) -import DA.Daml.LF.Ast (Package, PackageRef) +import DA.Daml.LF.Ast (Package, PackageId, PackageRef) import DA.Daml.LF.Proto3.Error import qualified DA.Daml.LF.Proto3.DecodeV1 as DecodeV1 -decodePayload :: PackageRef -> ArchivePayload -> Either Error Package -decodePayload selfPackageRef payload = case archivePayloadSum payload of - Just (ArchivePayloadSumDamlLf1 package) -> DecodeV1.decodePackage minor selfPackageRef package +decodePayload :: PackageId -> PackageRef -> ArchivePayload -> Either Error Package +decodePayload pkgId selfPackageRef payload = case archivePayloadSum payload of + Just (ArchivePayloadSumDamlLf1 package) -> DecodeV1.decodePackage (Just pkgId) minor selfPackageRef package Nothing -> Left $ ParseError "Empty payload" where minor = archivePayloadMinor payload diff --git a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs index 6da7291f296a..a9f8cc96b6da 100644 --- a/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs +++ b/compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs @@ -21,6 +21,7 @@ import Control.Monad.Reader import Data.Int import Text.Read import Data.List +import DA.Daml.StablePackagesList import DA.Daml.LF.Mangling import qualified Com.Daml.DamlLfDev.DamlLf1 as LF1 import qualified Data.NameMap as NM @@ -170,8 +171,8 @@ decodePackageRef (LF1.PackageRef pref) = -- Decodings of everything else ------------------------------------------------------------------------ -decodeVersion :: T.Text -> Either Error Version -decodeVersion minorText = do +decodeVersion :: Maybe LF.PackageId -> T.Text -> Either Error Version +decodeVersion mbPkgId minorText = do let unsupported :: Either Error a unsupported = throwError (UnsupportedMinorVersion minorText) -- we translate "no version" to minor version 0, since we introduced @@ -183,16 +184,19 @@ decodeVersion minorText = do | Just minor <- LF.parseMinorVersion (T.unpack minorText) -> pure minor | otherwise -> unsupported let version = V1 minor - if version `elem` LF.supportedInputVersions then pure version else unsupported + if isStablePackage || version `elem` LF.supportedInputVersions then pure version else unsupported + where + isStablePackage = maybe False (`elem` stablePackages) mbPkgId decodeInternedDottedName :: LF1.InternedDottedName -> Decode ([T.Text], Either String [UnmangledIdentifier]) decodeInternedDottedName (LF1.InternedDottedName ids) = do (mangled, unmangledOrErr) <- unzip <$> mapM lookupString (V.toList ids) pure (mangled, sequence unmangledOrErr) -decodePackage :: TL.Text -> LF.PackageRef -> LF1.Package -> Either Error Package -decodePackage minorText selfPackageRef (LF1.Package mods internedStringsV internedDottedNamesV metadata internedTypesV) = do - version <- decodeVersion (decodeString minorText) +-- The package id is optional since we also call this function from decodeScenarioModule +decodePackage :: Maybe LF.PackageId -> TL.Text -> LF.PackageRef -> LF1.Package -> Either Error Package +decodePackage mbPkgId minorText selfPackageRef (LF1.Package mods internedStringsV internedDottedNamesV metadata internedTypesV) = do + version <- decodeVersion mbPkgId (decodeString minorText) let internedStrings = V.map decodeMangledString internedStringsV let internedDottedNames = V.empty let internedTypes = V.empty @@ -213,7 +217,7 @@ decodePackageMetadata LF1.PackageMetadata{..} = do decodeScenarioModule :: TL.Text -> LF1.Package -> Either Error Module decodeScenarioModule minorText protoPkg = do - Package { packageModules = modules } <- decodePackage minorText PRSelf protoPkg + Package { packageModules = modules } <- decodePackage Nothing minorText PRSelf protoPkg pure $ head $ NM.toList modules decodeModule :: LF1.Module -> Decode Module diff --git a/compiler/damlc/daml-lf-util/BUILD.bazel b/compiler/damlc/daml-lf-util/BUILD.bazel index 7200c335e376..89dea5f4159d 100644 --- a/compiler/damlc/daml-lf-util/BUILD.bazel +++ b/compiler/damlc/daml-lf-util/BUILD.bazel @@ -21,7 +21,6 @@ da_haskell_library( visibility = ["//visibility:public"], deps = [ "//compiler/daml-lf-ast", - "//compiler/daml-lf-proto", "//libs-haskell/da-hs-base", ], ) diff --git a/compiler/damlc/daml-lf-util/src/DA/Daml/UtilLF.hs b/compiler/damlc/daml-lf-util/src/DA/Daml/UtilLF.hs index b382d43ecd53..1b166e8b657e 100644 --- a/compiler/damlc/daml-lf-util/src/DA/Daml/UtilLF.hs +++ b/compiler/damlc/daml-lf-util/src/DA/Daml/UtilLF.hs @@ -9,10 +9,8 @@ module DA.Daml.UtilLF ( ) where import DA.Daml.LF.Ast -import qualified DA.Daml.LF.Proto3.Archive as Archive import DA.Pretty (renderPretty) -import qualified Data.ByteString.Char8 as BS import Data.Maybe import qualified Data.NameMap as NM import qualified Data.Text as T @@ -82,10 +80,6 @@ fromTCon t = error $ "fromTCon failed, " ++ show t synthesizeVariantRecord :: VariantConName -> TypeConName -> TypeConName synthesizeVariantRecord (VariantConName dcon) (TypeConName tcon) = TypeConName (tcon ++ [dcon]) -writeFileLf :: FilePath -> Package -> IO () -writeFileLf outFile lfPackage = do - BS.writeFile outFile $ Archive.encodeArchive lfPackage - -- | Fails if there are any duplicate module names buildPackage :: HasCallStack => Maybe PackageName -> Maybe PackageVersion -> Version -> [Module] -> Package buildPackage mbPkgName mbPkgVersion version mods = diff --git a/compiler/damlc/stable-packages/BUILD.bazel b/compiler/damlc/stable-packages/BUILD.bazel index fc65a2c9c220..850f2f6f47c1 100644 --- a/compiler/damlc/stable-packages/BUILD.bazel +++ b/compiler/damlc/stable-packages/BUILD.bazel @@ -126,3 +126,28 @@ filegroup( ], visibility = ["//visibility:public"], ) + +genrule( + name = "stable-packages-list-srcs", + outs = ["DA/Daml/StablePackagesList.hs"], + cmd = """ + $(location :generate-stable-package) gen-package-list -o $(location DA/Daml/StablePackagesList.hs) + """, + tools = [":generate-stable-package"], +) + +# We generate this as a library rather than depending on :stable-packages-lib +# to avoid a cyclical dependency between the daml-lf-proto and :stable-packages-lib +# and to avoid having to encode the packages at runtime to get their package id. +da_haskell_library( + name = "stable-packages-list", + srcs = ["DA/Daml/StablePackagesList.hs"], + hackage_deps = [ + "base", + "containers", + ], + visibility = ["//visibility:public"], + deps = [ + "//compiler/daml-lf-ast", + ], +) diff --git a/compiler/damlc/stable-packages/lib/DA/Daml/StablePackages.hs b/compiler/damlc/stable-packages/lib/DA/Daml/StablePackages.hs index 4e4bd6e236ff..580daae424c5 100644 --- a/compiler/damlc/stable-packages/lib/DA/Daml/StablePackages.hs +++ b/compiler/damlc/stable-packages/lib/DA/Daml/StablePackages.hs @@ -17,8 +17,10 @@ import DA.Daml.LF.Ast import DA.Daml.LF.Proto3.Archive.Encode import DA.Daml.UtilLF -allStablePackages :: [Package] +allStablePackages :: MS.Map PackageId Package allStablePackages = + MS.fromList $ + map (\pkg -> (encodePackageHash pkg, pkg)) [ ghcTypes , ghcPrim , ghcTuple @@ -43,18 +45,18 @@ allStablePackages = , daExceptionPreconditionFailed ] -allStablePackagesForVersion :: Version -> [Package] +allStablePackagesForVersion :: Version -> MS.Map PackageId Package allStablePackagesForVersion v = - filter (\p -> packageLfVersion p <= v) allStablePackages + MS.filter (\p -> packageLfVersion p <= v) allStablePackages numStablePackagesForVersion :: Version -> Int -numStablePackagesForVersion v = length (allStablePackagesForVersion v) +numStablePackagesForVersion v = MS.size (allStablePackagesForVersion v) stablePackageByModuleName :: MS.Map ModuleName Package stablePackageByModuleName = MS.fromListWithKey (\k -> error $ "Duplicate module among stable packages: " <> show k) [ (moduleName m, p) - | p <- allStablePackages + | p <- MS.elems allStablePackages , m <- NM.toList (packageModules p) ] ghcTypes :: Package diff --git a/compiler/damlc/stable-packages/src/GenerateStablePackage.hs b/compiler/damlc/stable-packages/src/GenerateStablePackage.hs index 32f7028cb0df..60f9af535dcb 100644 --- a/compiler/damlc/stable-packages/src/GenerateStablePackage.hs +++ b/compiler/damlc/stable-packages/src/GenerateStablePackage.hs @@ -9,12 +9,21 @@ import qualified Data.ByteString as BS import qualified Data.Map.Strict as MS import Options.Applicative import qualified Data.Text as T +import Data.Text.Extended (writeFileUtf8) import DA.Daml.LF.Ast import DA.Daml.LF.Proto3.Archive.Encode import DA.Daml.StablePackages -data Opts = Opts +data Opts + = PackageListCmd GenPackageListOpts + | PackageCmd GenPackageOpts + +data GenPackageListOpts = GenPackageListOpts + { optListOutputPath :: FilePath + } + +data GenPackageOpts = GenPackageOpts { optModule :: ModuleName -- ^ The module that we generate as a standalone package , optModuleDeps :: [ModuleDep] @@ -31,9 +40,18 @@ data ModuleDep = ModuleDep , depPackageId :: PackageId } deriving Show -optParser :: Parser Opts -optParser = - Opts +packageListOptsParser :: Parser GenPackageListOpts +packageListOptsParser = + subparser $ + command "gen-package-list" $ + info parser mempty + where + parser = GenPackageListOpts <$> option str (short 'o') + + +packageOptsParser :: Parser GenPackageOpts +packageOptsParser = + GenPackageOpts <$> option modNameReader (long "module") <*> many (option modDepReader (long "module-dep" <> help "Module.Name:packageid")) <*> option str (short 'o') @@ -47,14 +65,28 @@ optParser = } _ -> Nothing +optParser :: Parser Opts +optParser = + PackageListCmd <$> packageListOptsParser <|> PackageCmd <$> packageOptsParser + main :: IO () main = do - Opts{..} <- execParser (info optParser idm) - case MS.lookup optModule stablePackageByModuleName of - Nothing -> - fail $ "Unknown module: " <> show optModule - Just pkg -> - writePackage pkg optOutputPath + opts <- execParser (info optParser idm) + case opts of + PackageCmd GenPackageOpts{..} -> case MS.lookup optModule stablePackageByModuleName of + Nothing -> + fail $ "Unknown module: " <> show optModule + Just pkg -> + writePackage pkg optOutputPath + PackageListCmd GenPackageListOpts{..} -> + writeFileUtf8 optListOutputPath $ T.unlines + [ "module DA.Daml.StablePackagesList (stablePackages) where" + , "import DA.Daml.LF.Ast (PackageId(..))" + , "import qualified Data.Set as Set" + , "stablePackages :: Set.Set PackageId" + , "stablePackages = Set.fromList" + , " [" <> T.intercalate ", " (map (T.pack . show) $ MS.keys allStablePackages) <> "]" + ] writePackage :: Package -> FilePath -> IO () writePackage pkg path = do diff --git a/compiler/damlc/tests/BUILD.bazel b/compiler/damlc/tests/BUILD.bazel index f7c13cea3c6d..576583fa99bf 100644 --- a/compiler/damlc/tests/BUILD.bazel +++ b/compiler/damlc/tests/BUILD.bazel @@ -442,8 +442,6 @@ da_haskell_test( "//compiler/damlc", "@damlc_legacy", "//compiler/damlc/tests:generate-simple-dalf", - "//daml-lf/repl", - "@davl-v3//:released/davl-v3.dar", # Feel free to update this to 0.13.55 once that is frozen. ":dars/old-proj-0.13.55-snapshot.20200309.3401.0.6f8c3ad8-1.8.dar", ], diff --git a/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs b/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs index 365ed4b71395..3eda20d69555 100644 --- a/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs +++ b/compiler/damlc/tests/src/DA/Test/DamlcIntegration.hs @@ -11,7 +11,6 @@ module DA.Test.DamlcIntegration import DA.Bazel.Runfiles import DA.Daml.Options import DA.Daml.Options.Types -import DA.Daml.UtilLF import DA.Test.Util (standardizeQuotes) import DA.Daml.LF.Ast as LF hiding (IsTest) @@ -24,6 +23,7 @@ import Control.Exception.Extra import Control.Monad import Control.Monad.IO.Class import DA.Daml.LF.Proto3.EncodeV1 +import qualified DA.Daml.LF.Proto3.Archive.Encode as Archive import DA.Pretty hiding (first) import qualified DA.Daml.LF.ScenarioServiceClient as SS import qualified DA.Service.Logger as Logger @@ -34,6 +34,7 @@ import Development.IDE.Core.Shake (ShakeLspEnv(..), NotificationHandler(..)) import qualified Development.IDE.Types.Logger as IdeLogger import Development.IDE.Types.Location import qualified Data.Aeson.Encode.Pretty as A +import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy.Char8 as BSL import Data.Char import qualified Data.DList as DList @@ -383,7 +384,7 @@ mainProj service outdir log file = do -- NOTE (MK): For some reason ghcide’s `prettyPrint` seems to fall over on Windows with `commitBuffer: invalid argument`. -- With `fakeDynFlags` things seem to work out fine. let corePrettyPrint = timed log "Core pretty-printing" . liftIO . writeFile (outdir proj <.> "core") . showSDoc fakeDynFlags . ppr - let lfSave = timed log "LF saving" . liftIO . writeFileLf (outdir proj <.> "dalf") + let lfSave = timed log "LF saving" . liftIO . BS.writeFile (outdir proj <.> "dalf") . Archive.encodeArchive let lfPrettyPrint = timed log "LF pretty-printing" . liftIO . writeFile (outdir proj <.> "pdalf") . renderPretty let jsonSave pkg = let json = A.encodePretty $ JSONPB.toJSONPB (encodePackage pkg) JSONPB.jsonPBOptions diff --git a/compiler/damlc/tests/src/DA/Test/DataDependencies.hs b/compiler/damlc/tests/src/DA/Test/DataDependencies.hs index 03064f3dbb4d..12ef43a034ff 100644 --- a/compiler/damlc/tests/src/DA/Test/DataDependencies.hs +++ b/compiler/damlc/tests/src/DA/Test/DataDependencies.hs @@ -31,8 +31,6 @@ main = do setEnv "TASTY_NUM_THREADS" "3" True damlc <- locateRunfiles (mainWorkspace "compiler" "damlc" exe "damlc") damlcLegacy <- locateRunfiles ("damlc_legacy" exe "damlc_legacy") - repl <- locateRunfiles (mainWorkspace "daml-lf" "repl" exe "repl") - davlDar <- locateRunfiles ("davl-v3" "released" "davl-v3.dar") oldProjDar <- locateRunfiles (mainWorkspace "compiler" "damlc" "tests" "dars" "old-proj-0.13.55-snapshot.20200309.3401.0.6f8c3ad8-1.8.dar") let validate dar = callProcessSilent damlc ["validate-dar", dar] defaultMain $ tests Tools{..} @@ -40,9 +38,7 @@ main = do data Tools = Tools -- and places { damlc :: FilePath , damlcLegacy :: FilePath - , repl :: FilePath , validate :: FilePath -> IO () - , davlDar :: FilePath , oldProjDar :: FilePath } @@ -69,7 +65,7 @@ lfVersionTestPairs = in legacyPairs ++ zip versions (tail versions) tests :: Tools -> TestTree -tests tools@Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependencies" $ +tests tools@Tools{damlc,validate,oldProjDar} = testGroup "Data Dependencies" $ [ testCaseSteps ("Cross DAML-LF version: " <> LF.renderVersion depLfVer <> " -> " <> LF.renderVersion targetLfVer) $ \step -> withTempDir $ \tmpDir -> do let proja = tmpDir "proja" let projb = tmpDir "projb" @@ -156,56 +152,7 @@ tests tools@Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Depe (if targetLfVer /= depLfVer then 2 else 0) -- different daml-stdlib/daml-prim | (depLfVer, targetLfVer) <- lfVersionTestPairs ] <> - [ testCaseSteps "Cross-SDK dependency on DAVL" $ \step -> withTempDir $ \tmpDir -> do - step "Building DAR" - writeFileUTF8 (tmpDir "daml.yaml") $ unlines - [ "sdk-version: " <> sdkVersion - , "version: 0.0.1" - , "name: foobar" - , "source: ." - , "dependencies: [daml-prim, daml-stdlib]" - , "data-dependencies: [" <> show davlDar <> "]" - ] - writeFileUTF8 (tmpDir "Main.daml") $ unlines - [ "module Main where" - - , "import DAVL" - , "import DA.Assert" - , "import qualified OldStdlib.DA.Internal.Template as OldStdlib" - - -- We exploit internals of the template desugaring here - -- until we can reconstruct typeclasses or at least functions. - , "instance HasCreate EmployeeProposal where" - , " create = GHC.Types.primitive @\"UCreate\"" - , "instance HasFetch EmployeeProposal where" - , " fetch = GHC.Types.primitive @\"UFetch\"" - , "instance HasExercise EmployeeProposal OldStdlib.Archive () where" - , " exercise = GHC.Types.primitive @\"UExercise\"" - - , "test = scenario do" - , " alice <- getParty \"Alice\"" - , " bob <- getParty \"Bob\"" - , " eve <- getParty \"eve\"" - , " let role = EmployeeRole bob alice eve" - , " cid <- submit alice $ create (EmployeeProposal role 42)" - , " EmployeeProposal{employeeRole} <- submit bob $ fetch cid" - , " employee employeeRole === bob" - , " company employeeRole === alice" - , " () <- submit alice $ exercise cid OldStdlib.Archive" - , " pure ()" - ] - callProcessSilent damlc - [ "build" - , "--project-root", tmpDir - , "-o", tmpDir "foobar.dar" - -- We need to use the old stdlib for the Archive type - , "--package", "daml-stdlib-cc6d52aa624250119006cd19d51c60006762bd93ca5a6d288320a703024b33da (DA.Internal.Template as OldStdlib.DA.Internal.Template)" - ] - step "Validating DAR" - validate $ tmpDir "foobar.dar" - step "Testing scenario" - callProcessSilent repl ["test", "Main:test", tmpDir "foobar.dar"] - , testCaseSteps "Mixed dependencies and data-dependencies" $ \step -> withTempDir $ \tmpDir -> do + [ testCaseSteps "Mixed dependencies and data-dependencies" $ \step -> withTempDir $ \tmpDir -> do step "Building 'lib'" createDirectoryIfMissing True (tmpDir "lib") writeFileUTF8 (tmpDir "lib" "daml.yaml") $ unlines @@ -503,8 +450,8 @@ tests tools@Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Depe , "version: 0.1.0" , "source: ." , "dependencies: [daml-prim, daml-stdlib]" - , "data-dependencies: [simple-dalf-0.0.0.dalf]" - , "build-options: [--package=simple-dalf-0.0.0]" + , "data-dependencies: [simple-dalf-1.0.0.dalf]" + , "build-options: [--package=simple-dalf-1.0.0]" ] writeFileUTF8 (projDir "A.daml") $ unlines [ "module A where" @@ -542,7 +489,7 @@ tests tools@Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Depe ] callProcessSilent genSimpleDalf $ ["--with-archive-choice" | withArchiveChoice ] <> - [projDir "simple-dalf-0.0.0.dalf"] + [projDir "simple-dalf-1.0.0.dalf"] callProcess damlc [ "build" , "--project-root", projDir diff --git a/compiler/damlc/tests/src/DA/Test/GenerateSimpleDalf.hs b/compiler/damlc/tests/src/DA/Test/GenerateSimpleDalf.hs index 999ab8b52b44..78c460e8a170 100644 --- a/compiler/damlc/tests/src/DA/Test/GenerateSimpleDalf.hs +++ b/compiler/damlc/tests/src/DA/Test/GenerateSimpleDalf.hs @@ -26,7 +26,7 @@ main = do [file] -> (file,False) ["--with-archive-choice",file] -> (file,True) _ -> error $ "unexpected command line args: " <> show args - let version = V1 (PointStable 6) + let version = versionDefault let modName = ModuleName ["Module"] let modRef = Qualified PRSelf modName let tplFields = map FieldName ["this", "arg"] @@ -124,7 +124,7 @@ main = do let pkg = Package { packageLfVersion = version , packageModules = NM.fromList [mod] - , packageMetadata = Nothing + , packageMetadata = Just $ PackageMetadata (PackageName "simple-dalf") (PackageVersion "1.0.0") } let (bytes, PackageId hash) = encodeArchiveAndHash pkg BSL.writeFile file bytes diff --git a/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel b/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel deleted file mode 100644 index 844871262e9d..000000000000 --- a/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -load( - "//bazel_tools/client_server:client_server_build.bzl", - "client_server_build", -) -load( - "//bazel_tools:scala.bzl", - "da_scala_binary", -) -load( - "//bazel_tools/sh:sh.bzl", - "sh_inline_test", -) -load( - "//rules_daml:daml.bzl", - "daml_compile", -) - -daml_compile( - name = "lf16", - srcs = ["daml/LF16.daml"], - target = "1.6", - version = "1.0.0", -) - -da_scala_binary( - name = "lf16-export-client", - srcs = ["scala/com/daml/script/export/LF16ExportClient.scala"], - main_class = "com.daml.script.export.LF16ExportClient", - scala_deps = [ - "@maven//:com_github_scopt_scopt", - ], - deps = [ - "//:sdk-version-scala-lib", - "//daml-lf/archive:daml_lf_archive_reader", - "//daml-lf/data", - "//daml-lf/language", - "//daml-script/export", - "//language-support/scala/bindings", - "//language-support/scala/bindings-akka", - "//ledger-api/rs-grpc-bridge", - "//ledger/ledger-api-common", - "//libs-scala/auth-utils", - "//libs-scala/fs-utils", - ], -) - -client_server_build( - name = "lf16-export", - outs = [ - "lf16-export.zip", - ], - client = ":lf16-export-client", - client_args = [ - "--ledgerid=lf16-export-ledger", - "--target-port=%PORT%", - ], - client_files = ["lf16.build"], - data = ["lf16.build"], - output_env = "EXPORT_OUT", - server = "//ledger/sandbox:sandbox-binary", - server_args = [ - "--ledgerid=lf16-export-ledger", - "--port=0", - "--port-file=%PORT_FILE%", - ], - server_files = ["lf16.build"], -) - -sh_inline_test( - name = "lf16-export-build", - cmd = """\ -set -eoux pipefail -tmpdir=$$(mktemp -d) -trap "rm -rf $$tmpdir" EXIT -DAMLC=$$(canonicalize_rlocation $(rootpath //compiler/damlc)) -unzip $$(canonicalize_rlocation $(rootpath :lf16-export.zip)) -d $$tmpdir -cp -L $$(canonicalize_rlocation $(rootpath //daml-script/daml:daml-script-1.14.dar)) $$tmpdir/ -sed -i.bak 's/daml-script/daml-script-1.14.dar/' $$tmpdir/daml.yaml -cat $$tmpdir/daml.yaml -DAML_PROJECT=$$tmpdir $$DAMLC build -""", - data = [ - ":lf16-export.zip", - "//compiler/damlc", - "//daml-script/daml:daml-script-1.14.dar", - ], -) diff --git a/daml-script/export/integration-tests/export-lf-1.6/daml/LF16.daml b/daml-script/export/integration-tests/export-lf-1.6/daml/LF16.daml deleted file mode 100644 index a6fc092bfd36..000000000000 --- a/daml-script/export/integration-tests/export-lf-1.6/daml/LF16.daml +++ /dev/null @@ -1,18 +0,0 @@ --- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. --- SPDX-License-Identifier: Apache-2.0 - -module LF16 where - -template LF16 - with - issuer : Party - count : Int - where - signatory issuer - - key (issuer, count) : (Party, Int) - maintainer key._1 - - choice Increment : ContractId LF16 - controller issuer - do create this with count = count + 1 diff --git a/daml-script/export/integration-tests/export-lf-1.6/scala/com/daml/script/export/LF16ExportClient.scala b/daml-script/export/integration-tests/export-lf-1.6/scala/com/daml/script/export/LF16ExportClient.scala deleted file mode 100644 index 4bf366ab7d44..000000000000 --- a/daml-script/export/integration-tests/export-lf-1.6/scala/com/daml/script/export/LF16ExportClient.scala +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.script.export - -import java.io.{File, FileOutputStream} -import java.nio.file.{Files, Path, Paths} -import java.util.zip.{ZipEntry, ZipOutputStream} - -import akka.actor.ActorSystem -import com.daml.ledger.client.LedgerClient -import com.daml.ledger.client.configuration.{ - CommandClientConfiguration, - LedgerClientConfiguration, - LedgerIdRequirement, -} -import com.daml.fs.Utils.deleteRecursively -import com.daml.grpc.adapter.{AkkaExecutionSequencerPool, ExecutionSequencerFactory} -import com.daml.ledger.api.v1.command_service -import com.daml.ledger.api.v1.commands -import com.daml.ledger.api.v1.transaction -import com.daml.ledger.api.v1.value -import com.daml.ledger.api.domain -import com.daml.lf.archive.DarDecoder -import com.daml.SdkVersion -import com.daml.ledger.api.refinements.ApiTypes.Party - -import scala.concurrent.{Await, ExecutionContext, Future} -import scala.concurrent.duration.Duration -import scala.jdk.CollectionConverters._ - -case class LF16ExportClientConfig( - darPath: File, - targetPort: Int, - ledgerId: String, - outputZip: Path, -) - -object LF16ExportClientConfig { - def parse(args: Array[String]): Option[LF16ExportClientConfig] = - parser.parse( - args, - LF16ExportClientConfig( - darPath = null, - targetPort = -1, - ledgerId = null, - outputZip = null, - ), - ) - - private def parseExportOut( - envVar: String - ): Either[String, LF16ExportClientConfig => LF16ExportClientConfig] = { - envVar.split(" ").map(s => Paths.get(s)) match { - case Array(output_zip) => - Right(c => - c.copy( - outputZip = output_zip - ) - ) - case _ => Left("Environment variable EXPORT_OUT must contain one path") - } - } - - private val parser = new scopt.OptionParser[LF16ExportClientConfig]("lf16-export-client") { - help("help") - .text("Show this help message.") - opt[Int]("target-port") - .required() - .action((x, c) => c.copy(targetPort = x)) - .text("Daml ledger port to connect to.") - opt[String]("ledgerid") - .required() - .action((x, c) => c.copy(ledgerId = x)) - .text("Daml ledger identifier.") - opt[String]("output") - .hidden() - .withFallback(() => sys.env.getOrElse("EXPORT_OUT", "")) - .validate(x => parseExportOut(x).map(_ => ())) - .action { (x, c) => - parseExportOut(x) match { - case Left(msg) => - throw new RuntimeException(s"Failed to validate EXPORT_OUT environment variable: $msg") - case Right(f) => f(c) - } - } - arg[File]("dar") - .required() - .action((f, c) => c.copy(darPath = f)) - .text("Path to the dar file containing the initialization script") - } -} - -object LF16ExportClient { - def main(args: Array[String]): Unit = { - LF16ExportClientConfig.parse(args) match { - case Some(clientConfig) => main(clientConfig) - case None => sys.exit(1) - } - } - def main(clientConfig: LF16ExportClientConfig): Unit = { - setupLedger(clientConfig.targetPort, clientConfig.ledgerId, clientConfig.darPath) - generateExport( - clientConfig.targetPort, - clientConfig.outputZip.toFile, - ) - } - - private def setupLedger(ledgerPort: Int, ledgerId: String, darPath: File): Unit = { - implicit val sys: ActorSystem = ActorSystem("lf16-export-client") - implicit val ec: ExecutionContext = sys.dispatcher - implicit val seq: ExecutionSequencerFactory = new AkkaExecutionSequencerPool( - "lf16-export-client" - ) - val run: Future[Unit] = for { - dar <- Future.fromTry(DarDecoder.readArchiveFromFile(darPath).toTry) - mainPackageId = dar.main._1 - lf16TemplateId = value - .Identifier() - .withPackageId(mainPackageId) - .withModuleName("LF16") - .withEntityName("LF16") - lf16IncrementId = value - .Identifier() - .withPackageId(mainPackageId) - .withModuleName("LF16") - .withEntityName("Increment") - client <- ApiClient( - applicationId = "lf16-export-client", - ledgerId = ledgerId, - host = "localhost", - port = ledgerPort, - ) - alice <- client.allocateParty("Alice", "Alice") - // To generate an internalCreateCmd. - tx <- client.submit( - "create-LF16", - Seq(alice.party), - ApiCommand.create( - lf16TemplateId, - ApiValue.recordRec( - lf16TemplateId, - "issuer" -> ApiValue.party(alice.party), - "count" -> ApiValue.int(0), - ), - ), - ) - cid = tx.events(0).event.created.get.contractId - // To generate an internalExerciseCmd on the Increment choice. - tx <- client.submit( - "exercise-Lf16-Increment", - Seq(alice.party), - ApiCommand.exercise(lf16TemplateId, cid, "Increment", ApiValue.record(lf16IncrementId)), - ) - cid = tx.events.find(_.event.isCreated).get.event.created.get.contractId - // To generate an internalExerciseCmd on the Archive choice. - _ <- client.submit( - "archive-Lf16", - Seq(alice.party), - ApiCommand.archive(lf16TemplateId, cid), - ) - // To generate an internalCreateAndExerciseCmd followed by an internalExerciseByKeyCmd. - // Note the exerciseByKey should not directly follow a create command, - // otherwise the exporter will generate a createAndExerciseCmd instead of an exerciseByKeyCmd. - _ <- client.submit( - "createAndExercise-exerciseByKey-Lf16-Increment", - Seq(alice.party), - ApiCommand.createAndExercise( - lf16TemplateId, - ApiValue.recordRec( - lf16TemplateId, - "issuer" -> ApiValue.party(alice.party), - "count" -> ApiValue.int(0), - ), - "Increment", - ApiValue.record(lf16IncrementId), - ), - ApiCommand.exerciseByKey( - lf16TemplateId, - ApiValue.tuple(ApiValue.party(alice.party), ApiValue.int(1)), - "Increment", - ApiValue.record(lf16IncrementId), - ), - ) - } yield () - run.onComplete { _ => sys.terminate() } - val _ = Await.result(sys.whenTerminated, Duration.Inf) - Await.result(run, Duration.Inf) - } - - private def generateExport( - ledgerPort: Int, - outputZip: File, - ): Unit = { - withTemporaryDirectory { outputPath => - Main.main( - Config.Empty.copy( - ledgerHost = "localhost", - ledgerPort = ledgerPort, - partyConfig = PartyConfig( - parties = Seq.empty[Party], - allParties = true, - ), - exportType = Some( - Config.EmptyExportScript.copy( - sdkVersion = SdkVersion.sdkVersion, - outputPath = outputPath, - ) - ), - ) - ) - createZipArchive(outputPath.toFile, outputZip) - } - } - - /** Recursively archives all files contained in a directory. - * - * The generated zip archive is reproducible in that the order of entries and their timestamps are deterministic. - * - * @param src Archive all files underneath this directory. The paths of the entries will be relative to this directory. - * @param dst Write the zip archive to this file. - */ - private def createZipArchive(src: File, dst: File): Unit = { - val out = new FileOutputStream(dst) - val zipOut = new ZipOutputStream(out) - def addFile(file: File): Unit = { - val path = src.toPath.relativize(file.toPath) - // Section "4.4.17 file name" in ZIP specification https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.3.9.TXT - // > All slashes MUST be forward slashes '/' as opposed to backwards slashes '\' [...] - val entry = new ZipEntry(path.iterator.asScala.mkString("/")) - entry.setTime(0) - zipOut.putNextEntry(entry) - Files.copy(file.toPath, zipOut) - zipOut.closeEntry() - } - def addDirectory(dir: File): Unit = { - dir - .listFiles() - .sorted - .foreach(f => - if (f.isDirectory) { addDirectory(f) } - else { addFile(f) } - ) - } - addDirectory(src) - zipOut.close - } - - private def withTemporaryDirectory(f: Path => Unit): Unit = { - val tmpDir = Files.createTempDirectory("daml-ledger-export") - try { - f(tmpDir) - } finally { - deleteRecursively(tmpDir) - } - } -} - -object ApiValue { - def tupleId(n: Int): value.Identifier = - value - .Identifier() - .withPackageId("40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7") - .withModuleName("DA.Types") - .withEntityName(s"Tuple$n") - def recordRec(id: value.Identifier, fields: (String, value.Value)*): value.Record = - value - .Record() - .withRecordId(id) - .withFields(fields.map { case (lbl, v) => - value - .RecordField() - .withLabel(lbl) - .withValue(v) - }) - def record(id: value.Identifier, fields: (String, value.Value)*): value.Value = - value.Value().withRecord(recordRec(id, fields: _*)) - def tuple(vals: value.Value*): value.Value = { - record(tupleId(vals.size), vals.zipWithIndex.map { case (v, ix) => (s"_${ix + 1}", v) }: _*) - } - def party(p: String): value.Value = value.Value().withParty(p) - def int(i: Long): value.Value = value.Value().withInt64(i) -} - -object ApiCommand { - val archiveId = value - .Identifier() - .withPackageId("d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662") - .withModuleName("DA.Internal.Template") - .withEntityName("Archive") - def create(tplId: value.Identifier, args: value.Record): commands.Command = - commands - .Command() - .withCreate( - commands - .CreateCommand() - .withTemplateId(tplId) - .withCreateArguments(args) - ) - def exercise( - tplId: value.Identifier, - cid: String, - choice: String, - arg: value.Value, - ): commands.Command = - commands - .Command() - .withExercise( - commands - .ExerciseCommand() - .withTemplateId(tplId) - .withContractId(cid) - .withChoice(choice) - .withChoiceArgument(arg) - ) - def archive(tplId: value.Identifier, cid: String): commands.Command = - exercise(tplId, cid, "Archive", ApiValue.record(archiveId)) - def createAndExercise( - tplId: value.Identifier, - tplArgs: value.Record, - choice: String, - choiceArg: value.Value, - ): commands.Command = - commands - .Command() - .withCreateAndExercise( - commands - .CreateAndExerciseCommand() - .withTemplateId(tplId) - .withCreateArguments(tplArgs) - .withChoice(choice) - .withChoiceArgument(choiceArg) - ) - def exerciseByKey( - tplId: value.Identifier, - key: value.Value, - choice: String, - arg: value.Value, - ): commands.Command = - commands - .Command() - .withExerciseByKey( - commands - .ExerciseByKeyCommand() - .withTemplateId(tplId) - .withContractKey(key) - .withChoice(choice) - .withChoiceArgument(arg) - ) -} - -case class ApiClient(applicationId: String, ledgerId: String, ledgerClient: LedgerClient) { - def allocateParty(hint: String, displayName: String): Future[domain.PartyDetails] = { - ledgerClient.partyManagementClient.allocateParty(Some(hint), Some(displayName)) - } - def submit(commandId: String, actAs: Seq[String], cmds: commands.Command*)(implicit - ec: ExecutionContext - ): Future[transaction.Transaction] = { - ledgerClient.commandServiceClient - .submitAndWaitForTransaction( - command_service - .SubmitAndWaitRequest() - .withCommands( - commands - .Commands() - .withLedgerId(ledgerId) - .withApplicationId(applicationId) - .withCommandId(commandId) - .withActAs(actAs) - .withCommands(cmds) - ) - ) - .map(_.getTransaction) - } -} - -object ApiClient { - def apply( - applicationId: String, - ledgerId: String, - host: String, - port: Int, - )(implicit ec: ExecutionContext, esf: ExecutionSequencerFactory): Future[ApiClient] = { - val ledgerConfig = LedgerClientConfiguration( - applicationId = applicationId, - ledgerIdRequirement = LedgerIdRequirement.none, - commandClient = CommandClientConfiguration.default, - sslContext = None, - ) - LedgerClient - .singleHost(host, port, ledgerConfig) - .map(ledgerClient => new ApiClient(applicationId, ledgerId, ledgerClient)) - - } -} diff --git a/deps.bzl b/deps.bzl index 35910e0602c3..ae563779121e 100644 --- a/deps.bzl +++ b/deps.bzl @@ -314,30 +314,6 @@ def daml_deps(): executable = True, ) - if "davl-v3" not in native.existing_rules(): - http_archive( - name = "davl-v3", - strip_prefix = "davl-{}".format(davl_v3_version), - urls = ["https://github.com/digital-asset/davl/archive/{}.tar.gz".format(davl_v3_version)], - sha256 = davl_v3_sha256, - build_file_content = """ -package(default_visibility = ["//visibility:public"]) -exports_files(["released/davl-v3.dar"]) - """, - ) - - if "davl" not in native.existing_rules(): - http_archive( - name = "davl", - strip_prefix = "davl-{}".format(davl_version), - urls = ["https://github.com/digital-asset/davl/archive/{}.tar.gz".format(davl_version)], - sha256 = davl_sha256, - build_file_content = """ -package(default_visibility = ["//visibility:public"]) -exports_files(["released/davl-v4.dar", "released/davl-v5.dar", "released/davl-upgrade-v3-v4.dar", "released/davl-upgrade-v4-v5.dar"]) - """, - ) - if "daml-cheat-sheet" not in native.existing_rules(): http_archive( name = "daml-cheat-sheet", diff --git a/language-support/ts/codegen/tests/BUILD.bazel b/language-support/ts/codegen/tests/BUILD.bazel index 0f6b4ca9d948..de3a156889ff 100644 --- a/language-support/ts/codegen/tests/BUILD.bazel +++ b/language-support/ts/codegen/tests/BUILD.bazel @@ -177,19 +177,12 @@ da_haskell_test( name = "daml2js", size = "large", srcs = ["src/DA/Test/Daml2js.hs"], - args = [ - "$(location //:yarn)", - ], data = [ "//:yarn", "//compiler/damlc", "//language-support/ts/codegen:daml2js", "//language-support/ts/daml-ledger:npm_package", "//language-support/ts/daml-types:npm_package", - "@damlc_legacy", - "@davl//:released/davl-upgrade-v4-v5.dar", - "@davl//:released/davl-v4.dar", - "@davl//:released/davl-v5.dar", ], hackage_deps = [ "aeson", diff --git a/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs b/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs index 4fdbe8ca2b07..87856971af87 100644 --- a/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs +++ b/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs @@ -14,31 +14,21 @@ import qualified DA.Daml.LF.Ast.Version as LF import DA.Test.Daml2jsUtils import Data.List.Extra import qualified Data.Text.Extended as T -import qualified Data.ByteString.Lazy as BSL -import Data.Aeson import Test.Tasty import Test.Tasty.HUnit import DA.Test.Process import DA.Test.Util --- Version of eslint we use for linting the generated code. -eslintVersion :: T.Text -eslintVersion = "^6.8.0" - main :: IO () -main = withTempDir $ \yarnCache -> do - setEnv "YARN_CACHE_FOLDER" yarnCache True - yarnPath : args <- getArgs +main = do + args <- getArgs damlc <- locateRunfiles (mainWorkspace "compiler" "damlc" exe "damlc") - damlcLegacy <- locateRunfiles ("damlc_legacy" "damlc_legacy") daml2js <- locateRunfiles (mainWorkspace "language-support" "ts" "codegen" exe "daml2js") - yarn <- locateRunfiles (mainWorkspace yarnPath) - davl <- locateRunfiles ("davl" "released") oldPath <- getSearchPath withArgs args $ withEnv - [ ("PATH", Just $ intercalate [searchPathSeparator] $ takeDirectory yarn : oldPath) + [ ("PATH", Just $ intercalate [searchPathSeparator] oldPath) , ("TASTY_NUM_THREADS", Just "1") - ] $ defaultMain (tests yarn damlc damlcLegacy daml2js davl) + ] $ defaultMain (tests damlc daml2js) -- It may help to keep in mind for the following tests, this quick -- refresher on the layout of a simple project: @@ -65,8 +55,8 @@ main = withTempDir $ \yarnCache -> do -- ... -- daml-types <-- referred to by the "resolutions" field in package.json -tests :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath -> TestTree -tests yarn damlc damlcLegacy daml2js davl = testGroup "daml2js tests" +tests :: FilePath -> FilePath -> TestTree +tests damlc daml2js = testGroup "daml2js tests" [ testCaseSteps "Different package, same name test" $ \step -> withTempDir $ \here -> do let grover = here "grover" @@ -95,37 +85,6 @@ tests yarn damlc damlcLegacy daml2js davl = testGroup "daml2js tests" assertBool "daml2js is expected to fail but succeeded" (exitCode /= ExitSuccess) assertInfixOf "Duplicate name 'grover-1.0' for different packages detected" err - , testCaseSteps "Different name, same package test" $ \step -> withTempDir $ \here -> do - let daml2jsDir = here "daml2js" - let grover = here "grover" - groverDaml = grover "daml" - groverDar = grover ".daml" "dist" "grover-1.0.dar" - createDirectoryIfMissing True groverDaml - -- Locked to DAML-LF 1.7 since we get different package ids due to - -- package metadata in DAML-LF 1.8. - withCurrentDirectory grover $ do - writeFileUTF8 (groverDaml "Grover.daml") - "module Grover where data Grover = Grover" - writeDamlYaml "grover" ["Grover"] ["daml-prim", "daml-stdlib"] (Just LF.version1_7) - step "daml build..." - buildProjectLegacy [] - let superGrover = here "super-grover" - superGroverDaml = superGrover "daml" - superGroverDar = superGrover ".daml" "dist" "super-grover-1.0.dar" - createDirectoryIfMissing True superGroverDaml - withCurrentDirectory superGrover $ do - writeFileUTF8 (superGroverDaml "Grover.daml") - "module Grover where data Grover = Grover" - writeDamlYaml "super-grover" ["Grover"] ["daml-prim", "daml-stdlib"] (Just LF.version1_7) - step "daml build..." - buildProjectLegacy [] - withCurrentDirectory here $ do - step "daml2js..." - setupYarnEnvironment - (exitCode, _, err) <- readProcessWithExitCode daml2js ([groverDar, superGroverDar] ++ ["-o", daml2jsDir]) "" - assertBool "daml2js is expected to fail but succeeded" (exitCode /= ExitSuccess) - assertInfixOf "Different names ('grover-1.0' and 'super-grover-1.0') for the same package detected" err - , testCaseSteps "Same package, same name test" $ \step -> withTempDir $ \here -> do let grover = here "grover" groverDaml = grover "daml" @@ -187,61 +146,6 @@ tests yarn damlc damlcLegacy daml2js davl = testGroup "daml2js tests" assertFileLines ("A" "B" "index.d.ts") (reexportIndex "C" ++ reexportIndex "D") assertFileLines ("A" "B" "C" "index.d.ts") reexportModule assertFileLines ("A" "B" "D" "index.d.ts") reexportModule - - , testCaseSteps "DAVL test" $ \step -> withTempDir $ \here -> do - let daml2jsDir = here "daml2js" - withCurrentDirectory here $ do - step "daml2js..." - setupYarnEnvironment - callProcessSilent daml2js $ - [ davl "davl-v4.dar" - , davl "davl-v5.dar" - , davl "davl-upgrade-v4-v5.dar" ] ++ - ["-o", daml2jsDir] - mapM_ (assertTsFileExists (daml2jsDir "davl-0.0.4")) - [ "index" - , "DAVL" "index" - , "DAVL" "module" - ] - mapM_ (assertTsFileExists (daml2jsDir "davl-0.0.5")) - [ "index" - , "DAVL" "index" - , "DAVL" "V5" "index" - , "DAVL" "V5" "module" - ] - mapM_ (assertTsFileExists (daml2jsDir "davl-upgrade-v4-v5-0.0.5")) - [ "index" - , "Upgrade" "index" - , "Upgrade" "module" - ] - step "eslint..." - withCurrentDirectory daml2jsDir $ do - pkgs <- (\\ ["package.json", "node_modules"]) <$> listDirectory daml2jsDir - BSL.writeFile "package.json" $ encode $ - object - [ "private" .= True - , "devDependencies" .= object - [ "eslint" .= eslintVersion - ] - , "workspaces" .= pkgs - , "resolutions" .= object - [ "@daml/types" .= ("file:../daml-types" :: T.Text) - , "@daml/ledger" .= ("file:../daml-ledger" :: T.Text)] - ] - BSL.writeFile ".eslintrc.json" $ encode $ object - [ "extends" .= - [ "eslint:recommended" :: T.Text - ] - , "env" .= object [ "commonjs" .= True ] -- We generate commonjs modules - , "rules" .= object - [ "no-unused-vars" .= - -- We disable the unused argument warning since that gets - -- triggered for decoders of phantom type arguments. - [ "error" :: Value , object [ "args" .= ("none" :: T.Text) ] ] - ] - ] - callProcessSilent yarn ["install", "--pure-lockfile"] - callProcessSilent yarn ["workspaces", "run", "eslint", "-c", ".." ".eslintrc.json", "--max-warnings", "0", "lib/"] ] where setupYarnEnvironment :: IO () @@ -251,9 +155,6 @@ tests yarn damlc damlcLegacy daml2js davl = testGroup "daml2js tests" buildProject :: [String] -> IO () buildProject args = callProcessSilent damlc (["build"] ++ args) - buildProjectLegacy :: [String] -> IO () - buildProjectLegacy args = callProcessSilent damlcLegacy (["build"] ++ args) - daml2jsProject :: [FilePath] -> FilePath -> IO () daml2jsProject dars outDir = callProcessSilent daml2js $ dars ++ ["-o", outDir] diff --git a/rules_daml/daml.bzl b/rules_daml/daml.bzl index 74ba933c4793..bdd45d23f29b 100644 --- a/rules_daml/daml.bzl +++ b/rules_daml/daml.bzl @@ -231,20 +231,29 @@ $$DAMLC validate-dar $$(canonicalize_rlocation $(rootpath {dar})) **kwargs ) -def _inspect_dar(base): - name = base + "-inspect" - dar = base + ".dar" - pp = base + ".dar.pp" - native.genrule( - name = name, - srcs = [ - dar, - "//compiler/damlc:damlc-compile-only", - ], - outs = [pp], - cmd = "$(location //compiler/damlc:damlc-compile-only) inspect $(location :" + dar + ") > $@", +def _inspect_dar_impl(ctx): + dar = ctx.file.dar + damlc = ctx.executable.damlc + pp = ctx.outputs.pp + ctx.actions.run( + executable = damlc, + inputs = [dar], + outputs = [pp], + arguments = ["inspect", dar.path, "-o", pp.path], ) +_inspect_dar = rule( + implementation = _inspect_dar_impl, + attrs = { + "dar": attr.label( + allow_single_file = True, + mandatory = True, + ), + "damlc": _damlc, + "pp": attr.output(mandatory = True), + }, +) + _default_project_version = "1.0.0" default_damlc_opts = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"] @@ -286,7 +295,10 @@ def daml_compile( **kwargs ) _inspect_dar( - base = name, + name = "{}-inspect".format(name), + dar = "{}.dar".format(name), + pp = "{}.dar.pp".format(name), + damlc = damlc_for_target(target), ) def daml_compile_with_dalf(