From c4a4a3819388fb22dff876df9022aa82ce735fa4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 12 Nov 2024 15:28:50 +0000 Subject: [PATCH] Fix module-prefix changes being ignored (#20288) * Add module prefixes to package-db reinitialisation check * Extend module-prefixes test to include this behaviour --- sdk/compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs | 12 ++++++++---- sdk/compiler/damlc/tests/src/DA/Test/Packaging.hs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/sdk/compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs b/sdk/compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs index 0674c80cfcbf..ea68d724d0ab 100644 --- a/sdk/compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs +++ b/sdk/compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs @@ -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" @@ -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 @@ -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 diff --git a/sdk/compiler/damlc/tests/src/DA/Test/Packaging.hs b/sdk/compiler/damlc/tests/src/DA/Test/Packaging.hs index 168e79837f61..706379d921a4 100644 --- a/sdk/compiler/damlc/tests/src/DA/Test/Packaging.hs +++ b/sdk/compiler/damlc/tests/src/DA/Test/Packaging.hs @@ -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