Skip to content

Commit

Permalink
Properly assign component ID/build dir for LibV09 test libraries
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ezyang committed Jan 2, 2016
1 parent 3ea7566 commit 3462ea6
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 74 deletions.
32 changes: 19 additions & 13 deletions Cabal/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule

import Distribution.Package
( Package(..), PackageName(..), PackageIdentifier(..)
, Dependency(..), thisPackageVersion, packageName
, ComponentId(..), ComponentId(..) )
, Dependency(..), thisPackageVersion )
import Distribution.Simple.Compiler
( Compiler, CompilerFlavor(..), compilerFlavor
, PackageDB(..), PackageDBStack )
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..), Library(..), Executable(..)
, TestSuite(..), TestSuiteInterface(..), Benchmark(..)
, BenchmarkInterface(..), allBuildInfo, defaultRenaming )
, BenchmarkInterface(..), allBuildInfo )
import qualified Distribution.InstalledPackageInfo as IPI
import qualified Distribution.ModuleName as ModuleName
import Distribution.ModuleName (ModuleName)
Expand All @@ -55,7 +54,7 @@ import Distribution.Simple.BuildTarget
import Distribution.Simple.PreProcess
( preprocessComponent, preprocessExtras, PPSuffixHandler )
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(compiler, buildDir, withPackageDB, withPrograms)
( LocalBuildInfo(compiler, buildDir, withPackageDB, withPrograms, flagAssignment)
, Component(..), componentName, getComponent, componentBuildInfo
, ComponentLocalBuildInfo(..), pkgEnabledComponents
, withComponentsInBuildOrder, componentsInBuildOrder
Expand All @@ -65,6 +64,7 @@ import Distribution.Simple.Program.Types
import Distribution.Simple.Program.Db
import Distribution.Simple.BuildPaths
( autogenModulesDir, autogenModuleName, cppHeaderName, exeExtension )
import Distribution.Simple.Configure (computeComponentId, computeCompatPackageKey)
import Distribution.Simple.Register
( registerPackage, inplaceInstalledPackageInfo
, doesPackageDBExist, deletePackageDB, createPackageDB )
Expand Down Expand Up @@ -249,7 +249,10 @@ buildComponent verbosity numJobs pkg_descr lbi0 suffixes
extras <- preprocessExtras comp lbi
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildLib verbosity numJobs pkg lbi lib libClbi
registerPackage verbosity (compiler lbi) (withPrograms lbi) False
-- NB: need to enable multiple instances here, because on 7.10+
-- the package name is the same as the library, and we still
-- want the registration to go through.
registerPackage verbosity (compiler lbi) (withPrograms lbi) True
(withPackageDB lbi) ipi
let ebi = buildInfo exe
exe' = exe { buildInfo = addExtraCSources ebi extras }
Expand Down Expand Up @@ -401,17 +404,22 @@ testSuiteLibV09AsLibAndExe pkg_descr
libExposed = True,
libBuildInfo = bi
}
cid = computeComponentId (package pkg_descr)
(CTestName (testName test))
(map fst (componentPackageDeps clbi))
(flagAssignment lbi)
(pkg_name, compat_key) = computeCompatPackageKey
(compiler lbi) (package pkg_descr)
(CTestName (testName test)) cid
libClbi = LibComponentLocalBuildInfo
{ componentPackageDeps = componentPackageDeps clbi
, componentPackageRenaming = componentPackageRenaming clbi
, componentId = ComponentId $ display (packageId pkg)
, componentCompatPackageKey = ComponentId $ display (packageId pkg)
, componentId = cid
, componentCompatPackageKey = compat_key
, componentExposedModules = [IPI.ExposedModule m Nothing Nothing]
}
pkg = pkg_descr {
package = (package pkg_descr) {
pkgName = PackageName (testName test)
}
package = (package pkg_descr) { pkgName = pkg_name }
, buildDepends = targetBuildDepends $ testBuildInfo test
, executables = []
, testSuites = []
Expand Down Expand Up @@ -439,9 +447,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
: (filter (\(_, x) -> let PackageName name = pkgName x
in name == "Cabal" || name == "base")
(componentPackageDeps clbi)),
componentPackageRenaming =
Map.insert (packageName ipi) defaultRenaming
(componentPackageRenaming clbi)
componentPackageRenaming = Map.empty
}
testSuiteLibV09AsLibAndExe _ TestSuite{} _ _ _ _ = error "testSuiteLibV09AsLibAndExe: wrong kind"

Expand Down
Loading

0 comments on commit 3462ea6

Please sign in to comment.