Remove damlc migrate (#4816)

* Remove damlc migrate

``damlc migrate`` hasn’t worked for quite a while and we emitted a
warning for months so given that we don’t have plans to make it work
again in the near future, I think it does more harm than good to keep
it around.

changelog_begin

- [DAML Compiler] After being deprecated for a while the ``damlc
  migrate`` command has now been removed. See
  https://docs.daml.com/upgrade/ for up to date documentation
  on model upgrades.

changelog_end

fixes #3704 (by removing the tests 😇)

* yeah the windows cache is once again broken \o/

* Revert "yeah the windows cache is once again broken \o/"

This reverts commit 38d7877aa4.
This commit is contained in:
mergify[bot] 2020-03-04 20:36:48 +00:00 committed by GitHub
parent f9057bea19
commit cb1395e923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1 additions and 467 deletions

View File

@ -1,33 +0,0 @@
-- Copyright (c) 2020 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
--
module DA.Daml.Compiler.Upgrade
( generateUpgradeModule
) where
-- | Generate non-consuming choices to upgrade all templates defined in the module.
generateUpgradeModule :: [String] -> String -> String -> String -> String
generateUpgradeModule templateNames modName qualA qualB =
unlines $ header ++ concatMap upgradeTemplates templateNames
where
header = header0 ++ header2
-- If we compile with packages from a single sdk version, the instances modules will not be
-- there and hence we can not include header1.
header0 =
[ "daml 1.2"
, "module " <> modName <> " where"
, "import " <> modName <> qualA <> " qualified as A"
, "import " <> modName <> qualB <> " qualified as B"
]
header2 = [
"import DA.Upgrade"
]
upgradeTemplates :: String -> [String]
upgradeTemplates n =
[ "instance Convertible A." <> n <> " B." <> n <> " where"
, " convert A." <> n <> "{..} = B." <> n <> " {..}"
, "instance Convertible B." <> n <> " A." <> n <> " where"
, " convert B." <> n <> "{..} = A." <> n <> " {..}"
]

View File

@ -24,12 +24,10 @@ import DA.Cli.Damlc.IdeState
import DA.Cli.Damlc.Packaging
import DA.Cli.Damlc.Test
import DA.Daml.Compiler.Dar
import DA.Daml.Compiler.ExtractDar (getEntry)
import qualified DA.Daml.Compiler.Repl as Repl
import DA.Daml.Compiler.DocTest
import DA.Daml.Compiler.Scenario
import qualified DA.Daml.LF.ReplClient as ReplClient
import DA.Daml.Compiler.Upgrade
import DA.Daml.Compiler.Validate (validateDar)
import qualified DA.Daml.LF.Ast as LF
import qualified DA.Daml.LF.Proto3.Archive as Archive
@ -57,7 +55,6 @@ import qualified Data.HashSet as HashSet
import Data.List.Extra
import qualified Data.List.Split as Split
import Data.Maybe
import qualified Data.NameMap as NM
import qualified Data.Text.Extended as T
import Development.IDE.Core.API
import Development.IDE.Core.Debouncer
@ -112,7 +109,6 @@ data CommandName =
| License
| Lint
| MergeDars
| Migrate
| Package
| Test
| Visual
@ -314,19 +310,6 @@ cmdValidateDar =
where
cmd = execValidateDar <$> inputDarOpt
cmdMigrate :: Mod CommandFields Command
cmdMigrate =
command "migrate" $
info (helper <*> cmd) $
progDesc "Generate a migration package to upgrade the ledger" <> fullDesc
where
cmd =
execMigrate
<$> projectOpts "daml damlc migrate"
<*> inputDarOpt
<*> inputDarOpt
<*> targetSrcDirOpt
cmdMergeDars :: Mod CommandFields Command
cmdMergeDars =
command "merge-dars" $
@ -760,80 +743,6 @@ execValidateDar inFile =
n <- validateDar inFile -- errors if validation fails
putStrLn $ "DAR is valid; contains " <> show n <> " packages."
execMigrate ::
ProjectOpts
-> FilePath
-> FilePath
-> Maybe FilePath
-> Command
execMigrate projectOpts inFile1_ inFile2_ mbDir =
Command Migrate (Just projectOpts) effect
where
effect = do
-- See https://github.com/digital-asset/daml/issues/3704
hPutStrLn stderr $ unlines
[ "Warning: `damlc migrate` is currently in the process of being reworked"
, "to make it function better across SDK versions and address"
, "a number of known bugs."
]
inFile1 <- makeAbsolute inFile1_
inFile2 <- makeAbsolute inFile2_
withProjectRoot' projectOpts $ \_relativize
-> do
-- get the package name and the lf-package
[(pkgName1, _pkgId1, lfPkg1), (pkgName2, _pkgId2, lfPkg2)] <-
forM [inFile1, inFile2] $ \inFile -> do
bytes <- B.readFile inFile
let dar = ZipArchive.toArchive $ BSL.fromStrict bytes
-- get the main pkg
dalfManifest <- either fail pure $ readDalfManifest dar
mainDalfEntry <- getEntry (mainDalfPath dalfManifest) dar
(mainPkgId, mainLfPkg) <-
decode $ BSL.toStrict $ ZipArchive.fromEntry mainDalfEntry
let pkgName = unitIdString (LF.unitIdFromFile (mainDalfPath dalfManifest) mainPkgId)
pure (pkgName, mainPkgId, mainLfPkg)
-- generate upgrade modules and instances modules
let eqModNames =
(NM.names $ LF.packageModules lfPkg1) `intersect`
(NM.names $ LF.packageModules lfPkg2)
let eqModNamesStr = map (T.unpack . LF.moduleNameString) eqModNames
let buildOptions =
[ "'--package=" <> show ("instances-" <> pkgName1, True, [(m, m ++ "A") | m <- eqModNamesStr]) <> "'"
, "'--package=" <> show ("instances-" <> pkgName2, True, [(m, m ++ "B") | m <- eqModNamesStr]) <> "'"
]
forM_ eqModNames $ \m@(LF.ModuleName modName) -> do
let upgradeModPath =
(joinPath $ fromMaybe "" mbDir : map T.unpack modName) <>
".daml"
templateNames <-
map (T.unpack . T.intercalate "." . LF.unTypeConName) .
NM.names . LF.moduleTemplates <$>
getModule m lfPkg1
let generatedUpgradeMod =
generateUpgradeModule
templateNames
(T.unpack $ LF.moduleNameString m)
"A"
"B"
createDirectoryIfMissing True $ takeDirectory upgradeModPath
writeFile upgradeModPath generatedUpgradeMod
oldDamlYaml <- T.readFileUtf8 "daml.yaml"
let newDamlYaml = T.unlines $
T.lines oldDamlYaml ++
["build-options:"] ++
map (\opt -> T.pack $ "- " <> opt) buildOptions
T.writeFileUtf8 "daml.yaml" newDamlYaml
putStrLn "Generation of migration project complete."
decode dalf =
errorOnLeft
"Cannot decode daml-lf archive"
(Archive.decodeArchive Archive.DecodeAsMain dalf)
getModule modName pkg =
maybe
(fail $ T.unpack $ "Can't find module" <> LF.moduleNameString modName)
pure $
NM.lookup modName $ LF.packageModules pkg
-- | Merge two dars. The idea is that the second dar is a delta. Hence, we take the main in the
-- manifest from the first.
execMergeDars :: FilePath -> FilePath -> Maybe FilePath -> Command
@ -909,7 +818,6 @@ options numProcessors =
<> cmdInspect
<> cmdVisual
<> cmdVisualWeb
<> cmdMigrate
<> cmdMergeDars
<> cmdInit numProcessors
<> cmdCompile numProcessors

View File

@ -36,7 +36,6 @@ data Command
, shutdownStdinClose :: Bool
}
| New { targetFolder :: FilePath, templateNameM :: Maybe String }
| Migrate { targetFolder :: FilePath, pkgPathFrom :: FilePath, pkgPathTo :: FilePath }
| Init { targetFolderM :: Maybe FilePath }
| ListTemplates
| Start
@ -65,7 +64,6 @@ commandParser :: Parser Command
commandParser = subparser $ fold
[ command "studio" (info (damlStudioCmd <**> helper) forwardOptions)
, command "new" (info (newCmd <**> helper) idm)
, command "migrate" (info (migrateCmd <**> helper) idm)
, command "init" (info (initCmd <**> helper) idm)
, command "start" (info (startCmd <**> helper) idm)
, command "deploy" (info (deployCmd <**> helper) deployCmdInfo)
@ -107,11 +105,6 @@ commandParser = subparser $ fold
<*> optional (argument str (metavar "TEMPLATE" <> help ("Name of the template used to create the project (default: " <> defaultProjectTemplate <> ")")))
]
migrateCmd = Migrate
<$> argument str (metavar "TARGET_PATH" <> help "Path where the new project should be located")
<*> argument str (metavar "FROM_PATH" <> help "Path to the dar-package from which to migrate from")
<*> argument str (metavar "TO_PATH" <> help "Path to the dar-package to which to migrate to")
initCmd = Init
<$> optional (argument str (metavar "TARGET_PATH" <> help "Project folder to initialize."))
@ -261,7 +254,6 @@ runCommand = \case
(if shutdownStdinClose then withCloseOnStdin else id) $
runJar jarPath mbLogbackConfig remainingArguments
New {..} -> runNew targetFolder templateNameM [] []
Migrate {..} -> runMigrate targetFolder pkgPathFrom pkgPathTo
Init {..} -> runInit targetFolderM
ListTemplates -> runListTemplates
Start {..} ->

View File

@ -4,7 +4,6 @@ module DA.Daml.Helper.Run
( runDamlStudio
, runInit
, runNew
, runMigrate
, runJar
, runDaml2ts
, runListTemplates
@ -642,28 +641,6 @@ runNew targetFolder templateNameM pkgDeps dataDeps = do
"Created a new project in \"" <> targetFolder <>
"\" based on the template \"" <> templateName <> "\"."
-- | Create a project containing code to migrate a running system between two given packages.
runMigrate :: FilePath -> FilePath -> FilePath -> IO ()
runMigrate targetFolder pkgPath1 pkgPath2
= do
pkgPath1Abs <- makeAbsolute pkgPath1
pkgPath2Abs <- makeAbsolute pkgPath2
-- Create a new project
runNew targetFolder (Just "migrate") [] [pkgPath1Abs, pkgPath2Abs]
-- Call damlc to create the upgrade source files.
procConfig <- toAssistantCommand
[ "damlc"
, "migrate"
, "--srcdir"
, "daml"
, "--project-root"
, targetFolder
, pkgPath1
, pkgPath2
]
runProcess_ procConfig
defaultProjectTemplate :: String
defaultProjectTemplate = "skeleton"

View File

@ -256,294 +256,6 @@ packagingTests = testGroup "packaging"
_ -> assertFailure "Expected JSON object in response body"
-- waitForProcess' will block on Windows so we explicitly kill the process.
terminateProcess startPh
-- Note(MK): The hacks around daml-prim which were already not quite right, e.g.,
-- we didnt include daml-prim from all SDK versions, are broken completely
-- now that we split daml-prim into multiple packages. Therefore, we
-- disable this for now.
-- See https://github.com/digital-asset/daml/issues/3704
-- , testCaseSteps "Build migration package" $ \step -> withTempDir $ \tmpDir -> do
-- -- it's important that we have fresh empty directories here!
-- let projectA = tmpDir </> "a-1.0"
-- let projectB = tmpDir </> "a-2.0"
-- let projectUpgrade = tmpDir </> "upgrade"
-- let projectRollback = tmpDir </> "rollback"
-- let aDar = projectA </> "projecta.dar"
-- let bDar = projectB </> "projectb.dar"
-- let upgradeDar = projectUpgrade </> distDir </> "upgrade-0.0.1.dar"
-- let rollbackDar= projectRollback </> distDir </> "rollback-0.0.1.dar"
-- let bWithUpgradesDar = "a-2.0-with-upgrades.dar"
-- step "Creating project a-1.0 ..."
-- createDirectoryIfMissing True (projectA </> "daml")
-- writeFileUTF8 (projectA </> "daml" </> "Main.daml") $ unlines
-- [ "{-# LANGUAGE EmptyCase #-}"
-- , "daml 1.2"
-- , "module Main where"
-- , "data OnlyA"
-- , "data Both"
-- , "template Foo"
-- , " with"
-- , " a : Int"
-- , " p : Party"
-- , " where"
-- , " signatory p"
-- ]
-- writeFileUTF8 (projectA </> "daml.yaml") $ unlines
-- [ "sdk-version: " <> sdkVersion
-- , "name: a"
-- , "version: \"1.0\""
-- , "source: daml"
-- , "exposed-modules: [Main]"
-- , "dependencies:"
-- , " - daml-prim"
-- , " - daml-stdlib"
-- ]
-- -- We use -o to test that we do not depend on the name of the dar
-- withCurrentDirectory projectA $ callCommandQuiet $ "daml build -o " <> aDar
-- assertBool "a-1.0.dar was not created." =<< doesFileExist aDar
-- step "Creating project a-2.0 ..."
-- createDirectoryIfMissing True (projectB </> "daml")
-- writeFileUTF8 (projectB </> "daml" </> "Main.daml") $ unlines
-- [ "daml 1.2"
-- , "module Main where"
-- , "data OnlyB"
-- , "data Both"
-- , "template Foo"
-- , " with"
-- , " a : Int"
-- , " p : Party"
-- , " where"
-- , " signatory p"
-- ]
-- writeFileUTF8 (projectB </> "daml.yaml") $ unlines
-- [ "sdk-version: " <> sdkVersion
-- , "name: a"
-- , "version: \"2.0\""
-- , "source: daml"
-- , "exposed-modules: [Main]"
-- , "dependencies:"
-- , " - daml-prim"
-- , " - daml-stdlib"
-- ]
-- -- We use -o to test that we do not depend on the name of the dar
-- withCurrentDirectory projectB $ callCommandQuiet $ "daml build -o " <> bDar
-- assertBool "a-2.0.dar was not created." =<< doesFileExist bDar
-- step "Creating upgrade/rollback project"
-- -- We use -o to verify that we do not depend on the
-- callCommandQuiet $ unwords ["daml", "migrate", projectUpgrade, aDar, bDar]
-- callCommandQuiet $ unwords ["daml", "migrate", projectRollback, bDar, aDar]
-- step "Build migration project"
-- withCurrentDirectory projectUpgrade $
-- callCommandQuiet "daml build"
-- assertBool "upgrade-0.0.1.dar was not created" =<< doesFileExist upgradeDar
-- step "Build rollback project"
-- withCurrentDirectory projectRollback $
-- callCommandQuiet "daml build"
-- assertBool "rollback-0.0.1.dar was not created" =<< doesFileExist rollbackDar
-- step "Merging upgrade dar"
-- callCommandQuiet $
-- unwords
-- [ "daml damlc merge-dars"
-- , bDar
-- , upgradeDar
-- , "--dar-name"
-- , bWithUpgradesDar
-- ]
-- assertBool "a-0.2-with-upgrades.dar was not created." =<< doesFileExist bWithUpgradesDar
-- , testCaseSteps "Build migration package with generics" $ \step -> withTempDir $ \tmpDir -> do
-- -- it's important that we have fresh empty directories here!
-- let projectA = tmpDir </> "a-1.0"
-- let projectB = tmpDir </> "a-2.0"
-- let projectUpgrade = tmpDir </> "upgrade"
-- let aDar = projectA </> "projecta.dar"
-- let bDar = projectB </> "projectb.dar"
-- let upgradeDar = projectUpgrade </> distDir </> "upgrade-0.0.1.dar"
-- step "Creating project a-1.0 ..."
-- createDirectoryIfMissing True (projectA </> "daml")
-- writeFileUTF8 (projectA </> "daml" </> "Main.daml") $ unlines
-- [ "{-# LANGUAGE EmptyCase #-}"
-- , "daml 1.2"
-- , "module Main where"
-- , "data OnlyA"
-- , "data Both"
-- , "template Foo"
-- , " with"
-- , " a : Int"
-- , " p : Party"
-- , " where"
-- , " signatory p"
-- ]
-- writeFileUTF8 (projectA </> "daml.yaml") $ unlines
-- [ "sdk-version: " <> sdkVersion
-- , "name: a"
-- , "version: \"1.0\""
-- , "source: daml"
-- , "exposed-modules: [Main]"
-- , "dependencies:"
-- , " - daml-prim"
-- , " - daml-stdlib"
-- ]
-- -- We use -o to test that we do not depend on the name of the dar
-- withCurrentDirectory projectA $ callCommandQuiet $ "daml build -o " <> aDar
-- assertBool "a-1.0.dar was not created." =<< doesFileExist aDar
-- step "Creating project a-2.0 ..."
-- createDirectoryIfMissing True (projectB </> "daml")
-- writeFileUTF8 (projectB </> "daml" </> "Main.daml") $ unlines
-- [ "daml 1.2"
-- , "module Main where"
-- , "data OnlyB"
-- , "data Both"
-- , "template Foo"
-- , " with"
-- , " a : Int"
-- , " p : Party"
-- , " new : Optional Text"
-- , " where"
-- , " signatory p"
-- ]
-- writeFileUTF8 (projectB </> "daml.yaml") $ unlines
-- [ "sdk-version: " <> sdkVersion
-- , "name: a"
-- , "version: \"2.0\""
-- , "source: daml"
-- , "exposed-modules: [Main]"
-- , "dependencies:"
-- , " - daml-prim"
-- , " - daml-stdlib"
-- ]
-- -- We use -o to test that we do not depend on the name of the dar
-- withCurrentDirectory projectB $ callCommandQuiet $ "daml build -o " <> bDar
-- assertBool "a-2.0.dar was not created." =<< doesFileExist bDar
-- step "Creating upgrade/rollback project"
-- callCommandQuiet $ unwords ["daml", "migrate", projectUpgrade, aDar, bDar]
-- step "Generate generic instances"
-- writeFileUTF8 (projectUpgrade </> "daml" </> "Main.daml") $ unlines
-- [ "daml 1.2"
-- , "module Main where"
-- , "import MainA qualified as A"
-- , "import MainB qualified as B"
-- , "import MainAGenInstances()"
-- , "import MainBGenInstances()"
-- , "import DA.Upgrade"
-- , "import DA.Generics"
-- , "instance Convertible A.Foo B.Foo"
-- , "instance Convertible B.Foo A.Foo"
-- ]
-- callCommandQuiet $
-- unwords
-- [ "daml"
-- , "damlc"
-- , "generate-generic-src"
-- , "--srcdir"
-- , projectUpgrade </> "daml"
-- , "--qualify"
-- , "A"
-- , aDar
-- ]
-- callCommandQuiet $
-- unwords
-- [ "daml"
-- , "damlc"
-- , "generate-generic-src"
-- , "--srcdir"
-- , projectUpgrade </> "daml"
-- , "--qualify"
-- , "B"
-- , bDar
-- ]
-- step "Build migration project"
-- withCurrentDirectory projectUpgrade $
-- callCommandQuiet "daml build --generated-src"
-- assertBool "upgrade-0.0.1.dar was not created" =<< doesFileExist upgradeDar
-- , testCaseSteps "Build migration package in LF 1.dev with Numerics" $ \step -> withTempDir $ \tmpDir -> do
-- -- it's important that we have fresh empty directories here!
-- let projectA = tmpDir </> "a-1.0"
-- let projectB = tmpDir </> "a-2.0"
-- let projectUpgrade = tmpDir </> "upgrade"
-- let projectRollback = tmpDir </> "rollback"
-- let aDar = projectA </> "projecta.dar"
-- let bDar = projectB </> "projectb.dar"
-- let upgradeDar = projectUpgrade </> distDir </> "upgrade-0.0.1.dar"
-- let rollbackDar= projectRollback </> distDir </> "rollback-0.0.1.dar"
-- let bWithUpgradesDar = "a-2.0-with-upgrades.dar"
-- step "Creating project a-1.0 ..."
-- createDirectoryIfMissing True (projectA </> "daml")
-- writeFileUTF8 (projectA </> "daml" </> "Main.daml") $ unlines
-- [ "daml 1.2"
-- , "module Main where"
-- , "data OnlyA"
-- , "data Both"
-- , "template Foo"
-- , " with"
-- , " a : Numeric 5"
-- , " p : Party"
-- , " where"
-- , " signatory p"
-- ]
-- writeFileUTF8 (projectA </> "daml.yaml") $ unlines
-- [ "sdk-version: " <> sdkVersion
-- , "name: a"
-- , "version: \"1.0\""
-- , "source: daml"
-- , "exposed-modules: [Main]"
-- , "dependencies:"
-- , " - daml-prim"
-- , " - daml-stdlib"
-- ]
-- -- We use -o to test that we do not depend on the name of the dar
-- withCurrentDirectory projectA $ callCommandQuiet $ "daml build --target 1.dev -o " <> aDar
-- assertBool "a-1.0.dar was not created." =<< doesFileExist aDar
-- step "Creating project a-2.0 ..."
-- createDirectoryIfMissing True (projectB </> "daml")
-- writeFileUTF8 (projectB </> "daml" </> "Main.daml") $ unlines
-- [ "daml 1.2"
-- , "module Main where"
-- , "data OnlyB"
-- , "data Both"
-- , "template Foo"
-- , " with"
-- , " a : Numeric 5"
-- , " p : Party"
-- , " where"
-- , " signatory p"
-- ]
-- writeFileUTF8 (projectB </> "daml.yaml") $ unlines
-- [ "sdk-version: " <> sdkVersion
-- , "name: a"
-- , "version: \"2.0\""
-- , "source: daml"
-- , "exposed-modules: [Main]"
-- , "dependencies:"
-- , " - daml-prim"
-- , " - daml-stdlib"
-- ]
-- -- We use -o to test that we do not depend on the name of the dar
-- withCurrentDirectory projectB $ callCommandQuiet $ "daml build --target 1.dev -o " <> bDar
-- assertBool "a-2.0.dar was not created." =<< doesFileExist bDar
-- step "Creating upgrade/rollback project"
-- -- We use -o to verify that we do not depend on the
-- callCommandQuiet $ unwords ["daml", "migrate", projectUpgrade, aDar, bDar]
-- callCommandQuiet $ unwords ["daml", "migrate", projectRollback, bDar, aDar]
-- step "Build migration project"
-- withCurrentDirectory projectUpgrade $
-- callCommandQuiet "daml build --target 1.dev"
-- assertBool "upgrade-0.0.1.dar was not created" =<< doesFileExist upgradeDar
-- step "Build rollback project"
-- withCurrentDirectory projectRollback $
-- callCommandQuiet "daml build --target 1.dev"
-- assertBool "rollback-0.0.1.dar was not created" =<< doesFileExist rollbackDar
-- step "Merging upgrade dar"
-- callCommandQuiet $
-- unwords
-- [ "daml damlc merge-dars"
-- , bDar
-- , upgradeDar
-- , "--dar-name"
-- , bWithUpgradesDar
-- ]
-- assertBool "a-0.2-with-upgrades.dar was not created." =<< doesFileExist bWithUpgradesDar
]
quickstartTests :: FilePath -> FilePath -> TestTree

View File

@ -10,10 +10,6 @@ commands:
desc: "Create a new DAML project"
args: ["new"]
completion: true
- name: migrate
path: daml-helper/daml-helper
args: ["migrate"]
completion: true
- name: init
path: daml-helper/daml-helper
desc: "Configure a folder as a DAML project"

View File

@ -7,7 +7,6 @@ genrule(
"default-gitignore",
"default-dlint-yaml",
"skeleton/**",
"migrate/**",
"quickstart-java/**",
"quickstart-scala/**",
]) + [
@ -23,7 +22,7 @@ genrule(
OUT=templates-tarball
# templates in templates dir
for d in skeleton migrate quickstart-scala quickstart-java; do
for d in skeleton quickstart-scala quickstart-java; do
mkdir -p $$OUT/$$d
cp -rL $$SRC/$$d/* $$OUT/$$d/
cp $$SRC/default-gitignore $$OUT/$$d/.gitignore

View File

@ -1,12 +0,0 @@
sdk-version: __VERSION__
name: __PROJECT_NAME__
source: daml
parties:
- Alice
- Bob
version: 0.0.1
dependencies:
- daml-prim
- daml-stdlib
data-dependencies:
__DATA_DEPENDENCIES__

View File

@ -1,5 +0,0 @@
users
{
Alice { party = "Alice" },
Bob { party = "Bob" }
}