Skip to content

Commit

Permalink
language: parse sdk version from manifest (digital-asset#3262)
Browse files Browse the repository at this point in the history
This is in preparation for the support of cross sdk imports, where we
need to know whether imports have different sdk versions or not.
  • Loading branch information
Robin Krom authored Oct 28, 2019
1 parent 380c2cc commit d4f8db0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 11 additions & 5 deletions compiler/daml-lf-reader/src/DA/Daml/LF/Reader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ data DalfManifest = DalfManifest
{ mainDalfPath :: FilePath
, dalfPaths :: [FilePath]
-- ^ Includes the mainDalf.
, sdkVersion :: String
} deriving (Show)

-- | The dalfs stored in the DAR.
Expand All @@ -96,11 +97,16 @@ data Dalfs = Dalfs
readDalfManifest :: Archive -> Either String DalfManifest
readDalfManifest dar = do
attrs <- readManifest dar
mainDalf <- maybe (Left "No Main-Dalf attribute in manifest") pure $ lookup "Main-Dalf" attrs
let mainDalfPath = BSUTF8.toString mainDalf
dalfsValue <- maybe (Left "No Dalfs attribute in manifest") pure $ lookup "Dalfs" attrs
let dalfPaths = splitOn ", " $ BSUTF8.toString dalfsValue
pure $ DalfManifest mainDalfPath dalfPaths
mainDalf <- getAttr "Main-Dalf" attrs
dalfPaths <- splitOn ", " <$> getAttr "Dalfs" attrs
sdkVersion <- getAttr "Sdk-Version" attrs
pure $ DalfManifest mainDalf dalfPaths sdkVersion
where
getAttr :: ByteString -> [(ByteString, ByteString)] -> Either String String
getAttr attrName attrs =
maybe (missingAttr attrName) (Right . BSUTF8.toString) $
lookup attrName attrs
missingAttr attrName = Left $ "No " <> BSUTF8.toString attrName <> " attribute in manifest."

readDalfs :: Archive -> Either String Dalfs
readDalfs dar = do
Expand Down
14 changes: 12 additions & 2 deletions compiler/damlc/tests/src/DarReaderTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ unitTests = testGroup "testing dar reader for longer manifest lines"
[
testCase "multiline manifest file test" $
assertEqual "content over multiple lines"
(Right [("Dalfs", "stdlib.dalf, prim.dalf"), ("Main-Dalf", "testing.dalf")])
(Right
[ ("Dalfs", "stdlib.dalf, prim.dalf")
, ("Main-Dalf", "testing.dalf")
, ("Sdk-Version", "0.13.30")
])
(parseManifestFile $ BS.unlines
[ "Dalfs: stdlib.da"
, " lf, prim.dalf"
, "Main-Dalf: testing.dalf"
, "Sdk-Version: 0.13.30"
])
, testCase "multiline manifest file test" $
assertEqual "all content in the same line"
(Right [("Dalfs", "stdlib.dalf"), ("Main-Dalf", "solution.dalf")])
(Right
[ ("Dalfs", "stdlib.dalf")
, ("Main-Dalf", "solution.dalf")
, ("Sdk-Version", "0.13.29")
])
(parseManifestFile $ BS.unlines
[ "Dalfs: stdlib.dalf"
, "Main-Dalf: solution.dalf"
, "Sdk-Version: 0.13.29"
])
]

0 comments on commit d4f8db0

Please sign in to comment.