Skip to content

Commit

Permalink
Include package name in manifest file (digital-asset#3805)
Browse files Browse the repository at this point in the history
Currently, we generate the `depends` field in the ghc-pkg config file
based on the file name of the DARs in the `dependencies` field in
`daml.yaml`. This falls apart when you use the -o option to `daml
build` since `ghc-pkg` will complain about missing packages.

This PR adds the name to the manifest so that we can generate the
`depends` field based on that but I’ll leave that change for a
separate PR.
  • Loading branch information
cocreature authored Dec 10, 2019
1 parent dcc7dc9 commit 4413ecc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/daml-lf-reader/src/DA/Daml/LF/Reader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.UTF8 as BSUTF8
import Data.Char
import Data.Either.Extra
import Data.List.Extra
import Data.Maybe
import qualified Data.Text as T
Expand Down Expand Up @@ -91,6 +92,7 @@ data DalfManifest = DalfManifest
, dalfPaths :: [FilePath]
-- ^ Includes the mainDalf.
, sdkVersion :: String
, packageName :: Maybe String
} deriving (Show)

-- | The dalfs stored in the DAR.
Expand All @@ -106,7 +108,8 @@ readDalfManifest dar = do
mainDalf <- getAttr "Main-Dalf" attrs
dalfPaths <- splitOn ", " <$> getAttr "Dalfs" attrs
sdkVersion <- getAttr "Sdk-Version" attrs
pure $ DalfManifest mainDalf dalfPaths sdkVersion
let mbName = eitherToMaybe (getAttr "Name" attrs)
pure $ DalfManifest mainDalf dalfPaths sdkVersion mbName
where
getAttr :: ByteString -> [(ByteString, ByteString)] -> Either String String
getAttr attrName attrs =
Expand Down
1 change: 1 addition & 0 deletions compiler/damlc/daml-compiler/src/DA/Daml/Compiler/Dar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ createArchive PackageConfigFields {..} pkgId dalf dalfDependencies srcRoot fileD
map (breakAt72Bytes . BSLUTF8.fromString)
[ "Manifest-Version: 1.0"
, "Created-By: damlc"
, "Name: " <> pkgNameVersion pName pVersion
, "Sdk-Version: " <> unPackageSdkVersion pSdkVersion
, "Main-Dalf: " <> toPosixFilePath location
, "Dalfs: " <> intercalate ", " (map toPosixFilePath dalfs)
Expand Down
1 change: 1 addition & 0 deletions compiler/damlc/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ da_haskell_test(
visibility = ["//visibility:public"],
deps = [
"//:sdk-version-hs-lib",
"//compiler/daml-lf-reader",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
],
Expand Down
16 changes: 16 additions & 0 deletions compiler/damlc/tests/src/DA/Test/Packaging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qualified "zip-archive" Codec.Archive.Zip as Zip
import Control.Monad.Extra
import Control.Exception.Safe
import DA.Bazel.Runfiles
import DA.Daml.LF.Reader (readDalfManifest, packageName)
import Data.Conduit.Tar.Extra (dropDirectory1)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Lazy.Char8 as BSL.Char8
Expand Down Expand Up @@ -356,6 +357,21 @@ tests damlc = testGroup "Packaging"
]
buildProjectError projDir "" "name collision between module A.B and variant A:B"

, testCase "Manifest name" $ withTempDir $ \projDir -> do
createDirectoryIfMissing True (projDir </> "src")
writeFileUTF8 (projDir </> "daml.yaml") $ unlines
[ "sdk-version: " <> sdkVersion
, "name: foobar"
, "version: 0.0.1"
, "source: src"
, "dependencies: [daml-prim, daml-stdlib]"
]
withCurrentDirectory projDir $ callProcessSilent damlc ["build", "-o", "baz.dar"]
Right manifest <- readDalfManifest . Zip.toArchive <$> BSL.readFile (projDir </> "baz.dar")
-- Verify that the name in the manifest is independent of the DAR name.
packageName manifest @?= Just "foobar-0.0.1"


, dataDependencyTests damlc
]
where
Expand Down
2 changes: 2 additions & 0 deletions compiler/damlc/tests/src/DarReaderTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ unitTests = testGroup "testing dar reader for longer manifest lines"
[ ("Dalfs", "stdlib.dalf, prim.dalf")
, ("Main-Dalf", "testing.dalf")
, ("Sdk-Version", "0.13.30")
, ("Name", "foobar-2.0")
])
(parseManifestFile $ BS.unlines
[ "Dalfs: stdlib.da"
, " lf, prim.dalf"
, "Main-Dalf: testing.dalf"
, "Sdk-Version: 0.13.30"
, "Name: foobar-2.0"
])
, testCase "multiline manifest file test" $
assertEqual "all content in the same line"
Expand Down

0 comments on commit 4413ecc

Please sign in to comment.