Skip to content

Commit 20d625e

Browse files
committed
Properly assign component ID/build dir for LibV09 test libraries
When building a LibV09 test library, Cabal previously dumped it into the same directory as the library proper. This means that if there are any module name conflicts, they'd override each other. Bad! The way to fix this is to build test libraries in different directories. We need to teach Cabal that not all libraries are the main library. This patch is a minimal patch to make this work for GHC; doubtless refactoring can make this generalize to all other backends (and make it hard to get wrong.) This follows the reserved namespace as per haskell#3017. Signed-off-by: Edward Z. Yang <[email protected]>
1 parent 3ea7566 commit 20d625e

File tree

16 files changed

+318
-74
lines changed

16 files changed

+318
-74
lines changed

Cabal/Distribution/Simple/Build.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule
3535

3636
import Distribution.Package
3737
( Package(..), PackageName(..), PackageIdentifier(..)
38-
, Dependency(..), thisPackageVersion, packageName
39-
, ComponentId(..), ComponentId(..) )
38+
, Dependency(..), thisPackageVersion )
4039
import Distribution.Simple.Compiler
4140
( Compiler, CompilerFlavor(..), compilerFlavor
4241
, PackageDB(..), PackageDBStack )
4342
import Distribution.PackageDescription
4443
( PackageDescription(..), BuildInfo(..), Library(..), Executable(..)
4544
, TestSuite(..), TestSuiteInterface(..), Benchmark(..)
46-
, BenchmarkInterface(..), allBuildInfo, defaultRenaming )
45+
, BenchmarkInterface(..), allBuildInfo )
4746
import qualified Distribution.InstalledPackageInfo as IPI
4847
import qualified Distribution.ModuleName as ModuleName
4948
import Distribution.ModuleName (ModuleName)
@@ -55,7 +54,7 @@ import Distribution.Simple.BuildTarget
5554
import Distribution.Simple.PreProcess
5655
( preprocessComponent, preprocessExtras, PPSuffixHandler )
5756
import Distribution.Simple.LocalBuildInfo
58-
( LocalBuildInfo(compiler, buildDir, withPackageDB, withPrograms)
57+
( LocalBuildInfo(compiler, buildDir, withPackageDB, withPrograms, flagAssignment)
5958
, Component(..), componentName, getComponent, componentBuildInfo
6059
, ComponentLocalBuildInfo(..), pkgEnabledComponents
6160
, withComponentsInBuildOrder, componentsInBuildOrder
@@ -65,6 +64,7 @@ import Distribution.Simple.Program.Types
6564
import Distribution.Simple.Program.Db
6665
import Distribution.Simple.BuildPaths
6766
( autogenModulesDir, autogenModuleName, cppHeaderName, exeExtension )
67+
import Distribution.Simple.Configure (computeComponentId, computeCompatPackageKey)
6868
import Distribution.Simple.Register
6969
( registerPackage, inplaceInstalledPackageInfo
7070
, doesPackageDBExist, deletePackageDB, createPackageDB )
@@ -249,7 +249,10 @@ buildComponent verbosity numJobs pkg_descr lbi0 suffixes
249249
extras <- preprocessExtras comp lbi
250250
info verbosity $ "Building test suite " ++ testName test ++ "..."
251251
buildLib verbosity numJobs pkg lbi lib libClbi
252-
registerPackage verbosity (compiler lbi) (withPrograms lbi) False
252+
-- NB: need to enable multiple instances here, because on 7.10+
253+
-- the package name is the same as the library, and we still
254+
-- want the registration to go through.
255+
registerPackage verbosity (compiler lbi) (withPrograms lbi) True
253256
(withPackageDB lbi) ipi
254257
let ebi = buildInfo exe
255258
exe' = exe { buildInfo = addExtraCSources ebi extras }
@@ -401,17 +404,22 @@ testSuiteLibV09AsLibAndExe pkg_descr
401404
libExposed = True,
402405
libBuildInfo = bi
403406
}
407+
cid = computeComponentId (package pkg_descr)
408+
(CTestName (testName test))
409+
(map fst (componentPackageDeps clbi))
410+
(flagAssignment lbi)
411+
(pkg_name, compat_key) = computeCompatPackageKey
412+
(compiler lbi) (package pkg_descr)
413+
(CTestName (testName test)) cid
404414
libClbi = LibComponentLocalBuildInfo
405415
{ componentPackageDeps = componentPackageDeps clbi
406416
, componentPackageRenaming = componentPackageRenaming clbi
407-
, componentId = ComponentId $ display (packageId pkg)
408-
, componentCompatPackageKey = ComponentId $ display (packageId pkg)
417+
, componentId = cid
418+
, componentCompatPackageKey = compat_key
409419
, componentExposedModules = [IPI.ExposedModule m Nothing Nothing]
410420
}
411421
pkg = pkg_descr {
412-
package = (package pkg_descr) {
413-
pkgName = PackageName (testName test)
414-
}
422+
package = (package pkg_descr) { pkgName = pkg_name }
415423
, buildDepends = targetBuildDepends $ testBuildInfo test
416424
, executables = []
417425
, testSuites = []
@@ -439,9 +447,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
439447
: (filter (\(_, x) -> let PackageName name = pkgName x
440448
in name == "Cabal" || name == "base")
441449
(componentPackageDeps clbi)),
442-
componentPackageRenaming =
443-
Map.insert (packageName ipi) defaultRenaming
444-
(componentPackageRenaming clbi)
450+
componentPackageRenaming = Map.empty
445451
}
446452
testSuiteLibV09AsLibAndExe _ TestSuite{} _ _ _ _ = error "testSuiteLibV09AsLibAndExe: wrong kind"
447453

0 commit comments

Comments
 (0)