Fix missing name error when using multi-build with sdk-version daml.yaml (#17986)

* Fix `missing name` error when using multi-build with sdk-version daml.yaml

* Update with better warning
This commit is contained in:
Samuel Williams 2023-12-06 12:28:32 +00:00 committed by GitHub
parent 56018b5d6e
commit 9cc0a654d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -27,12 +27,14 @@ import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.State.Lazy
import qualified Data.Aeson as A
import qualified Data.Aeson.Key as A
import qualified Data.Aeson.KeyMap as A
import qualified Data.Aeson.Encoding as A
import Data.List.Extra (nubOrd)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Data.Yaml as Y
import qualified Module as Ghc
import System.Directory (canonicalizePath, doesFileExist, withCurrentDirectory)
import System.FilePath (takeDirectory, (</>))
@ -149,6 +151,13 @@ overrideSdkVersion pkgConfig = do
withPackageConfig :: ProjectPath -> (PackageConfigFields -> IO a) -> IO a
withPackageConfig projectPath f = do
project <- readProjectConfig projectPath
-- If the config only has the sdk-version, it is "valid" but not usable for package config. It should be handled explicitly
case unwrapProjectConfig project of
A.Object (A.keys -> [A.toString -> "sdk-version"]) ->
throwIO $ ConfigFileInvalid "project" $ Y.InvalidYaml $ Just $ Y.YamlException $
projectConfigName ++ " contains only sdk-version, cannot be used for package config."
_ -> pure ()
pkgConfig <- either throwIO pure (parseProjectConfig project)
pkgConfig' <- overrideSdkVersion pkgConfig
f pkgConfig'

View File

@ -172,7 +172,7 @@ import qualified Data.ByteString.UTF8 as BSUTF8
import Data.Either (fromRight, partitionEithers)
import Data.FileEmbed (embedFile)
import qualified Data.HashSet as HashSet
import Data.List (isPrefixOf)
import Data.List (isPrefixOf, isInfixOf)
import Data.List.Extra (elemIndices, nubOrd, nubSort, nubSortOn)
import qualified Data.List.Split as Split
import qualified Data.Map.Strict as Map
@ -985,13 +985,13 @@ execBuild projectOpts opts mbOutFile incrementalBuild initPkgDb enableMultiPacka
-- We have no package context, but we have found a multi package at the current directory
(False, Nothing, Just _) -> do
hPutStrLn stderr $ "No daml.yaml found, but a multi-package.yaml was found instead.\n"
hPutStrLn stderr $ "No valid daml.yaml found, but a multi-package.yaml was found instead.\n"
<> "If you intended to build everything within this multi-package.yaml, use the --all flag"
exitFailure
-- We have nothing, we're lost
(False, Nothing, Nothing) -> do
hPutStrLn stderr "No daml.yaml or multi-package.yaml could be found."
hPutStrLn stderr "No valid daml.yaml or multi-package.yaml could be found."
exitFailure
else
case mPkgConfig of
@ -1021,6 +1021,9 @@ withMaybeConfig withConfig handler = do
handle (\case
ConfigFileInvalid _ (Y.InvalidYaml (Just (Y.YamlException exc))) | "Yaml file not found: " `isPrefixOf` exc ->
pure Nothing
ConfigFileInvalid _ (Y.InvalidYaml (Just (Y.YamlException exc))) | "contains only sdk-version" `isInfixOf` exc -> do
putStrLn "Found daml.yaml with only sdk-version, ignoring this file."
pure Nothing
e -> throwIO e
) (withConfig $ pure . Just)
handler mConfig