Add --install-with-custom-version, rename --allow-install-non-release (#17931)

* Add --install-with-custom-version, rename --allow-install-non-release

* Test install tarball via custom version in compatibility tests

run-full-compat: true
This commit is contained in:
dylant-da 2023-12-04 10:31:28 +00:00 committed by GitHub
parent d054187b5e
commit 4d8e4995df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 23 deletions

View File

@ -191,6 +191,7 @@ command_post_failure_behaviours = {
"install_and_build_from_tarball": [
"allow_nonrelease",
"update_cache",
"install_via_custom_version",
"do_nothing",
],
}

View File

@ -95,18 +95,35 @@ update_cache () {
}
allow_nonrelease () {
if echo_eval $daml_exe install --install-assistant yes --allow-install-non-release yes $absolute_github_mirror_directory/$tarball_path >daml_install_output 2>&1 || grep -q "The input line is too long" daml_install_output; then
if echo_eval $daml_exe install --install-assistant yes --install-with-internal-version yes $absolute_github_mirror_directory/$tarball_path >daml_install_output 2>&1 || grep -q "The input line is too long" daml_install_output; then
cat daml_install_output
echo_eval init_daml_package $tarball_sdk_version
if echo_eval $daml_exe build; then
echo_eval check_daml_version_indicates_correct $tarball_sdk_version
echo_eval check_dar_has_correct_metadata_version $tarball_sdk_version
else
error_echo "ERROR! \`daml build\` failed for version installed from path $tarball_path"
error_echo "ERROR! \`daml build\` failed for version installed from path $tarball_path with --install-with-internal-version"
fi
else
cat daml_install_output
error_echo "ERROR: Tried to install version from tarball '$tarball_path' with --allow-install-non-release, but \`daml install\` failed."
error_echo "ERROR: Tried to install version from tarball '$tarball_path' with --install-with-internal-version, but \`daml install\` failed."
fi
}
install_via_custom_version () {
custom_version=2.99.0
if echo_eval $daml_exe install --install-assistant yes --install-with-custom-version $custom_version $absolute_github_mirror_directory/$tarball_path >daml_install_output 2>&1 || grep -q "The input line is too long" daml_install_output; then
cat daml_install_output
echo_eval init_daml_package $custom_version
if echo_eval $daml_exe build; then
echo_eval check_daml_version_indicates_correct $custom_version
echo_eval check_dar_has_correct_metadata_version $custom_version
else
error_echo "ERROR! \`daml build\` failed for version installed from path $tarball_path with --install-with-custom-version $custom_version"
fi
else
cat daml_install_output
error_echo "ERROR: Tried to install version from tarball '$tarball_path' with --install-with-custom-version $custom_version, but \`daml install\` failed."
fi
}
@ -140,6 +157,9 @@ do_post_failed_tarball_install_behaviour () {
update_cache)
update_cache "$@"
;;
install_via_custom_version)
install_via_custom_version "$@"
;;
do_nothing)
;;
*)

View File

@ -153,7 +153,8 @@ autoInstall env@Env{..} = do
, iSetPath = SetPath Auto
, iBashCompletions = BashCompletions Auto
, iZshCompletions = ZshCompletions Auto
, iAllowInstallNonRelease = AllowInstallNonRelease False
, iInstallWithInternalVersion = InstallWithInternalVersion False
, iInstallWithCustomVersion = InstallWithCustomVersion Nothing
}
installEnv = InstallEnv
{ options = options

View File

@ -49,8 +49,8 @@ withSdkResource f =
if isWindows
then callProcessSilent
(extractDir </> "daml" </> damlInstallerName)
["install", "--install-assistant=yes", "--set-path=no", "--allow-install-non-release=yes", extractDir]
else callProcessSilent (extractDir </> "install.sh") ["--allow-install-non-release=yes"]
["install", "--install-assistant=yes", "--set-path=no", "--install-with-internal-version=yes", extractDir]
else callProcessSilent (extractDir </> "install.sh") ["--install-with-internal-version=yes"]
-- We restrict the permissions of the DAML_HOME directory to make sure everything
-- still works when the directory is read-only.
allFiles <- listFilesRecursive targetDir

View File

@ -120,7 +120,8 @@ installParser = InstallOptions
<*> fmap SetPath (flagYesNoAuto' "set-path" "Adjust PATH automatically" idm)
<*> fmap BashCompletions (flagYesNoAuto' "bash-completions" "Install bash completions for Daml assistant. Default is yes for linux and mac, no for windows." idm)
<*> fmap ZshCompletions (flagYesNoAuto' "zsh-completions" "Install Zsh completions for Daml assistant. Default is yes for linux and mac, no for windows." idm)
<*> fmap AllowInstallNonRelease (flagYesNoAuto "allow-install-non-release" False "Allow installing from a tarball that has no associated release by using the tarball's SDK version as its release version." internal)
<*> fmap InstallWithInternalVersion (flagYesNoAuto "install-with-internal-version" False "Allow installing from a tarball that has no associated release by using the tarball's SDK version as its release version." internal)
<*> fmap InstallWithCustomVersion (optionOnce (Just <$> str) (long "install-with-custom-version" <> value Nothing))
where
iflag p name opts desc = fmap p (switch (long name <> help desc <> opts))

View File

@ -144,17 +144,22 @@ installExtracted env@InstallEnv{..} sourcePath =
<> " but got version " <> sdkVersionToText sourceSdkVersion)
pure targetVersion
Nothing -> do
if unAllowInstallNonRelease (iAllowInstallNonRelease options)
if unInstallWithInternalVersion (iInstallWithInternalVersion options)
then -- NOTE: Using the SDK version as the release version is
-- only enabled by --allow-install-non-release, which is a
-- only enabled by --install-with-internal-version, which is a
-- flag only for devs
pure (OldReleaseVersion (unwrapSdkVersion sourceSdkVersion))
else
let errMsg =
"Failed to retrieve release version for sdk version " <> V.toText (unwrapSdkVersion sourceSdkVersion)
<> " from sdk path " <> T.pack (unwrapSdkPath sourcePath)
in
requiredE errMsg =<< resolveSdkVersionToRelease useCache sourceSdkVersion
else case unInstallWithCustomVersion (iInstallWithCustomVersion options) of
Just rawCustomVersion -> do
let errMsg = "Version '" <> T.pack rawCustomVersion <> "' from --install-with-custom-version flag could not be parsed as a version"
unresolvedVersion <- requiredE errMsg (parseUnresolvedVersion (T.pack rawCustomVersion))
pure $ mkReleaseVersion unresolvedVersion sourceSdkVersion
Nothing -> do
sourceVersionOrErr <- resolveSdkVersionToRelease useCache sourceSdkVersion
let errMsg =
"Failed to retrieve release version for sdk version " <> V.toText (unwrapSdkVersion sourceSdkVersion)
<> " from sdk path " <> T.pack (unwrapSdkPath sourcePath)
requiredE errMsg sourceVersionOrErr
-- Set file mode of files to install.
requiredIO "Failed to set file modes for extracted SDK files." $
@ -413,6 +418,9 @@ withInstallLock InstallEnv{..} action = do
-- until the other process is finished.
pathInstall :: InstallEnvWithoutVersion -> FilePath -> IO ()
pathInstall env@InstallEnv{..} sourcePath = withInstallLock env $ do
when (bothInstallWithVersion options) $ do
hPutStrLn stderr "ERROR: both --install-with-internal-version and --install-with-custom-version flags were supplied"
exitFailure
isDirectory <- doesDirectoryExist sourcePath
if isDirectory
then do
@ -512,6 +520,18 @@ install options damlPath useCache projectPathM assistantVersion = do
output = putStrLn -- Output install messages to stdout.
artifactoryApiKeyM = DAVersion.queryArtifactoryApiKey =<< eitherToMaybe damlConfigE
env = InstallEnv {..}
warnAboutAnyInstallFlags command = do
when (unInstallWithInternalVersion (iInstallWithInternalVersion options)) $
hPutStrLn stderr $ unlines
[ "WARNING: You have supplied --install-with-internal-version=yes, but `" <> command <> "` does not take that option."
]
case unInstallWithCustomVersion (iInstallWithCustomVersion options) of
Just customVersion ->
hPutStrLn stderr $ unlines
[ "WARNING: You have supplied --install-with-custom-version=" <> customVersion <> ", but `" <> command <> "` does not take that option."
]
Nothing -> pure ()
case iTargetM options of
Nothing -> do
hPutStrLn stderr $ unlines
@ -528,12 +548,15 @@ install options damlPath useCache projectPathM assistantVersion = do
Just RawInstallTarget_Project -> do
projectPath <- required "'daml install project' must be run from within a project."
projectPathM
warnAboutAnyInstallFlags "daml install project"
projectInstall env projectPath
Just RawInstallTarget_Latest ->
Just RawInstallTarget_Latest -> do
warnAboutAnyInstallFlags "daml install latest"
latestInstall env
Just (RawInstallTarget arg) | Right version <- parseVersion (pack arg) -> do
warnAboutAnyInstallFlags "daml install <version>"
releaseVersion <- DAVersion.resolveReleaseVersion useCache version
versionInstall env { targetVersionM = releaseVersion }

View File

@ -14,6 +14,7 @@ import DA.Daml.Project.Types
import Data.Text (Text, pack, unpack)
import Options.Applicative.Extended (YesNoAuto (..))
import Data.Functor.Identity
import Data.Maybe (isJust)
data EnvF f = Env
{ envDamlPath :: DamlPath
@ -74,10 +75,13 @@ data InstallOptions = InstallOptions
, iSetPath :: SetPath -- ^ set the user's PATH (on Windows)
, iBashCompletions :: BashCompletions -- ^ install bash completions for the daml assistant
, iZshCompletions :: ZshCompletions -- ^ install Zsh completions for the daml assistant
, iAllowInstallNonRelease :: AllowInstallNonRelease -- ^ install Zsh completions for the daml assistant
, iInstallWithInternalVersion :: InstallWithInternalVersion -- ^ install using the internal version of the tarball
, iInstallWithCustomVersion :: InstallWithCustomVersion -- ^ install using the custom version
} deriving (Eq, Show)
newtype AllowInstallNonRelease = AllowInstallNonRelease { unAllowInstallNonRelease :: Bool } deriving (Eq, Show)
newtype InstallWithInternalVersion = InstallWithInternalVersion { unInstallWithInternalVersion :: Bool } deriving (Eq, Show)
newtype InstallWithCustomVersion = InstallWithCustomVersion { unInstallWithCustomVersion :: Maybe String } deriving (Eq, Show)
newtype RawInstallTarget = RawInstallTarget String deriving (Eq, Show)
newtype ForceInstall = ForceInstall { unForceInstall :: Bool } deriving (Eq, Show)
newtype QuietInstall = QuietInstall { unQuietInstall :: Bool } deriving (Eq, Show)
@ -86,3 +90,8 @@ newtype SetPath = SetPath {unwrapSetPath :: YesNoAuto} deriving (Eq, Show)
newtype InstallAssistant = InstallAssistant { unwrapInstallAssistant :: YesNoAuto } deriving (Eq, Show)
newtype BashCompletions = BashCompletions { unwrapBashCompletions :: YesNoAuto } deriving (Eq, Show)
newtype ZshCompletions = ZshCompletions { unwrapZshCompletions :: YesNoAuto } deriving (Eq, Show)
bothInstallWithVersion :: InstallOptions -> Bool
bothInstallWithVersion InstallOptions{..} =
unInstallWithInternalVersion iInstallWithInternalVersion &&
isJust (unInstallWithCustomVersion iInstallWithCustomVersion)

View File

@ -412,7 +412,8 @@ testInstall = Tasty.testGroup "DA.Daml.Assistant.Install"
, iSetPath = SetPath No
, iBashCompletions = BashCompletions No
, iZshCompletions = ZshCompletions No
, iAllowInstallNonRelease = AllowInstallNonRelease False
, iInstallWithInternalVersion = InstallWithInternalVersion False
, iInstallWithCustomVersion = InstallWithCustomVersion Nothing
}
setCurrentDirectory base
@ -449,7 +450,8 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
, iSetPath = SetPath No
, iBashCompletions = BashCompletions No
, iZshCompletions = ZshCompletions No
, iAllowInstallNonRelease = AllowInstallNonRelease False
, iInstallWithInternalVersion = InstallWithInternalVersion False
, iInstallWithCustomVersion = InstallWithCustomVersion Nothing
}
setCurrentDirectory base
@ -481,7 +483,8 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
, iSetPath = SetPath No
, iBashCompletions = BashCompletions No
, iZshCompletions = ZshCompletions No
, iAllowInstallNonRelease = AllowInstallNonRelease False
, iInstallWithInternalVersion = InstallWithInternalVersion False
, iInstallWithCustomVersion = InstallWithCustomVersion Nothing
}
setCurrentDirectory base
@ -513,7 +516,8 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
, iSetPath = SetPath No
, iBashCompletions = BashCompletions No
, iZshCompletions = ZshCompletions No
, iAllowInstallNonRelease = AllowInstallNonRelease False
, iInstallWithInternalVersion = InstallWithInternalVersion False
, iInstallWithCustomVersion = InstallWithCustomVersion Nothing
}
setCurrentDirectory base
@ -545,7 +549,8 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
, iSetPath = SetPath No
, iBashCompletions = BashCompletions No
, iZshCompletions = ZshCompletions No
, iAllowInstallNonRelease = AllowInstallNonRelease False
, iInstallWithInternalVersion = InstallWithInternalVersion False
, iInstallWithCustomVersion = InstallWithCustomVersion Nothing
}
setCurrentDirectory base