Skip to content

Commit

Permalink
Fix module-prefix changes being ignored (#20288)
Browse files Browse the repository at this point in the history
* Add module prefixes to package-db reinitialisation check

* Extend module-prefixes test to include this behaviour
  • Loading branch information
samuel-williams-da authored Nov 12, 2024
1 parent 92d0d43 commit c4a4a38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sdk/compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import SdkVersion.Class (SdkVersioned, damlStdlib)
createProjectPackageDb :: SdkVersioned => NormalizedFilePath -> Options -> MS.Map UnitId GHC.ModuleName -> IO ()
createProjectPackageDb projectRoot (disableScenarioService -> opts) modulePrefixes
= do
(needsReinitalization, depsFingerprint) <- dbNeedsReinitialization projectRoot depsDir
(needsReinitalization, depsFingerprint) <- dbNeedsReinitialization projectRoot depsDir modulePrefixes
loggerH <- getLogger opts "package-db"
when needsReinitalization $ do
Logger.logDebug loggerH "package db is not up2date, reinitializing"
Expand Down Expand Up @@ -221,8 +221,8 @@ createProjectPackageDb projectRoot (disableScenarioService -> opts) modulePrefix
-- | Compute the hash over all dependencies and compare it to the one stored in the metadata file in
-- the package db to decide whether to run reinitialization or not.
dbNeedsReinitialization ::
NormalizedFilePath -> FilePath -> IO (Bool, Fingerprint)
dbNeedsReinitialization projectRoot depsDir = do
NormalizedFilePath -> FilePath -> MS.Map UnitId GHC.ModuleName -> IO (Bool, Fingerprint)
dbNeedsReinitialization projectRoot depsDir modulePrefixes = do
allDeps <- listFilesRecursive depsDir
fileFingerprints <- mapM getFileHash allDeps
let depsFingerprint = fingerprintFingerprints fileFingerprints
Expand All @@ -231,7 +231,11 @@ dbNeedsReinitialization projectRoot depsDir = do
pure $
case errOrmetaData of
Left _err -> (True, depsFingerprint)
Right metaData -> (fingerprintDependencies metaData /= depsFingerprint, depsFingerprint)
Right metaData ->
let fingerprintChanged = fingerprintDependencies metaData /= depsFingerprint
-- Use `fst` to throw away the contained module list, as the daml.yaml doesn't contain this information
modulePrefixesChanged = (fst <$> moduleRenamings metaData) /= modulePrefixes
in (fingerprintChanged || modulePrefixesChanged, depsFingerprint)

disableScenarioService :: Options -> Options
disableScenarioService opts = opts
Expand Down
15 changes: 15 additions & 0 deletions sdk/compiler/damlc/tests/src/DA/Test/Packaging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,21 @@ tests Tools{damlc} = testGroup "Packaging" $
, "main = dep1 + dep2"
]
callProcessSilent damlc ["build", "--project-root", dir </> "main", "-o", "main.dar"]
step "Changing module prefixes"
writeFileUTF8 (dir </> "main" </> "daml.yaml") $ unlines
[ "sdk-version: " <> sdkVersion
, "name: main"
, "version: 0.0.1"
, "source: ."
, "dependencies: [daml-prim, daml-stdlib]"
, "data-dependencies:"
, " - " <> show (dir </> "dep1" </> "dep1.dar")
, " - " <> show (dir </> "dep2" </> "dep2.dar")
, "module-prefixes:"
, " dep-1.0.0: Dep3"
, " dep-2.0.0: Dep4"
]
buildProjectError (dir </> "main") "" "Could not find module"
, testCaseSteps "relative output filepath" $ \step -> withTempDir $ \dir -> do
step "Create project"
writeFileUTF8 (dir </> "daml.yaml") $ unlines
Expand Down

0 comments on commit c4a4a38

Please sign in to comment.