Skip to content

Commit

Permalink
Merge pull request #3176 from 23Skidoo/framework-dirs
Browse files Browse the repository at this point in the history
Add field for setting framework search path (fixes #182).
  • Loading branch information
23Skidoo committed Feb 20, 2016
2 parents 7781178 + b9571ab commit eb21f98
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 68 deletions.
111 changes: 57 additions & 54 deletions Cabal/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ data BuildInfo = BuildInfo {
ldOptions :: [String], -- ^ options for linker
pkgconfigDepends :: [Dependency], -- ^ pkg-config packages that are used
frameworks :: [String], -- ^support frameworks for Mac OS X
extraFrameworkDirs:: [String], -- ^ extra locations to find frameworks.
cSources :: [FilePath],
jsSources :: [FilePath],
hsSourceDirs :: [FilePath], -- ^ where to look for the Haskell module hierarchy
Expand Down Expand Up @@ -844,66 +845,68 @@ instance Binary BuildInfo

instance Monoid BuildInfo where
mempty = BuildInfo {
buildable = True,
buildTools = [],
cppOptions = [],
ccOptions = [],
ldOptions = [],
pkgconfigDepends = [],
frameworks = [],
cSources = [],
jsSources = [],
hsSourceDirs = [],
otherModules = [],
defaultLanguage = Nothing,
otherLanguages = [],
defaultExtensions = [],
otherExtensions = [],
oldExtensions = [],
extraLibs = [],
extraGHCiLibs = [],
extraLibDirs = [],
includeDirs = [],
includes = [],
installIncludes = [],
options = [],
profOptions = [],
sharedOptions = [],
customFieldsBI = [],
targetBuildDepends = [],
buildable = True,
buildTools = [],
cppOptions = [],
ccOptions = [],
ldOptions = [],
pkgconfigDepends = [],
frameworks = [],
extraFrameworkDirs = [],
cSources = [],
jsSources = [],
hsSourceDirs = [],
otherModules = [],
defaultLanguage = Nothing,
otherLanguages = [],
defaultExtensions = [],
otherExtensions = [],
oldExtensions = [],
extraLibs = [],
extraGHCiLibs = [],
extraLibDirs = [],
includeDirs = [],
includes = [],
installIncludes = [],
options = [],
profOptions = [],
sharedOptions = [],
customFieldsBI = [],
targetBuildDepends = [],
targetBuildRenaming = Map.empty
}
mappend = (Semi.<>)

instance Semigroup BuildInfo where
a <> b = BuildInfo {
buildable = buildable a && buildable b,
buildTools = combine buildTools,
cppOptions = combine cppOptions,
ccOptions = combine ccOptions,
ldOptions = combine ldOptions,
pkgconfigDepends = combine pkgconfigDepends,
frameworks = combineNub frameworks,
cSources = combineNub cSources,
jsSources = combineNub jsSources,
hsSourceDirs = combineNub hsSourceDirs,
otherModules = combineNub otherModules,
defaultLanguage = combineMby defaultLanguage,
otherLanguages = combineNub otherLanguages,
defaultExtensions = combineNub defaultExtensions,
otherExtensions = combineNub otherExtensions,
oldExtensions = combineNub oldExtensions,
extraLibs = combine extraLibs,
extraGHCiLibs = combine extraGHCiLibs,
extraLibDirs = combineNub extraLibDirs,
includeDirs = combineNub includeDirs,
includes = combineNub includes,
installIncludes = combineNub installIncludes,
options = combine options,
profOptions = combine profOptions,
sharedOptions = combine sharedOptions,
customFieldsBI = combine customFieldsBI,
targetBuildDepends = combineNub targetBuildDepends,
buildable = buildable a && buildable b,
buildTools = combine buildTools,
cppOptions = combine cppOptions,
ccOptions = combine ccOptions,
ldOptions = combine ldOptions,
pkgconfigDepends = combine pkgconfigDepends,
frameworks = combineNub frameworks,
extraFrameworkDirs = combineNub extraFrameworkDirs,
cSources = combineNub cSources,
jsSources = combineNub jsSources,
hsSourceDirs = combineNub hsSourceDirs,
otherModules = combineNub otherModules,
defaultLanguage = combineMby defaultLanguage,
otherLanguages = combineNub otherLanguages,
defaultExtensions = combineNub defaultExtensions,
otherExtensions = combineNub otherExtensions,
oldExtensions = combineNub oldExtensions,
extraLibs = combine extraLibs,
extraGHCiLibs = combine extraGHCiLibs,
extraLibDirs = combineNub extraLibDirs,
includeDirs = combineNub includeDirs,
includes = combineNub includes,
installIncludes = combineNub installIncludes,
options = combine options,
profOptions = combine profOptions,
sharedOptions = combine sharedOptions,
customFieldsBI = combine customFieldsBI,
targetBuildDepends = combineNub targetBuildDepends,
targetBuildRenaming = combineMap targetBuildRenaming
}
where
Expand Down
19 changes: 18 additions & 1 deletion Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ data PackageCheck =
| PackageDistSuspicious { explanation :: String }

-- | Like PackageDistSuspicious but will only display warnings
-- rather than causing abnormal exit.
-- rather than causing abnormal exit when you run 'cabal check'.
| PackageDistSuspiciousWarn { explanation :: String }

-- | An issue that is OK in the author's environment but is almost
Expand Down Expand Up @@ -669,6 +669,14 @@ checkGhcOptions pkg =

, checkAlternatives "ghc-options" "extra-lib-dirs"
[ (flag, dir) | flag@('-':'L':dir) <- all_ghc_options ]

, checkAlternatives "ghc-options" "frameworks"
[ (flag, fmwk) | (flag@"-framework", fmwk) <-
zip all_ghc_options (safeTail all_ghc_options) ]

, checkAlternatives "ghc-options" "extra-framework-dirs"
[ (flag, dir) | (flag@"-framework-path", dir) <-
zip all_ghc_options (safeTail all_ghc_options) ]
]

where
Expand Down Expand Up @@ -912,6 +920,13 @@ checkCabalVersion pkg =
++ ". To use this new syntax, the package needs to specify at least"
++ "'cabal-version: >= 1.21'."

-- check use of 'extra-framework-dirs' field
, checkVersion [1,23] (any (not . null) (buildInfoField extraFrameworkDirs)) $
-- Just a warning, because this won't break on old Cabal versions.
PackageDistSuspiciousWarn $
"To use the 'extra-framework-dirs' field the package needs to specify"
++ " at least 'cabal-version: >= 1.23'."

-- check use of default-extensions field
-- don't need to do the equivalent check for other-extensions
, checkVersion [1,10] (any (not . null) (buildInfoField defaultExtensions)) $
Expand Down Expand Up @@ -1568,6 +1583,8 @@ checkLocalPathsExist ops pkg = do
| bi <- allBuildInfo pkg
, (dir, kind) <-
[ (dir, "extra-lib-dirs") | dir <- extraLibDirs bi ]
++ [ (dir, "extra-framework-dirs")
| dir <- extraFrameworkDirs bi ]
++ [ (dir, "include-dirs") | dir <- includeDirs bi ]
++ [ (dir, "hs-source-dirs") | dir <- hsSourceDirs bi ]
, isRelative dir ]
Expand Down
3 changes: 3 additions & 0 deletions Cabal/Distribution/PackageDescription/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ binfoFieldDescrs =
, listField "frameworks"
showToken parseTokenQ
frameworks (\val binfo -> binfo{frameworks=val})
, listField "extra-framework-dirs"
showToken parseFilePathQ
extraFrameworkDirs (\val binfo -> binfo{extraFrameworkDirs=val})
, listFieldWithSep vcat "c-sources"
showFilePath parseFilePathQ
cSources (\paths binfo -> binfo{cSources=paths})
Expand Down
1 change: 1 addition & 0 deletions Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ configureFinalizedPackage verbosity cfg
where
addExtraIncludeLibDirs pkg_descr =
let extraBi = mempty { extraLibDirs = configExtraLibDirs cfg
, extraFrameworkDirs = configExtraFrameworkDirs cfg
, PD.includeDirs = configExtraIncludeDirs cfg}
modifyLib l = l{ libBuildInfo = libBuildInfo l
`mappend` extraBi }
Expand Down
24 changes: 16 additions & 8 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,13 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptHPCDir = hpcdir Hpc.Dyn
}
linkerOpts = mempty {
ghcOptLinkOptions = toNubListR $ PD.ldOptions libBi,
ghcOptLinkLibs = toNubListR $ extraLibs libBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs libBi,
ghcOptLinkFrameworks = toNubListR $ PD.frameworks libBi,
ghcOptLinkOptions = toNubListR $ PD.ldOptions libBi,
ghcOptLinkLibs = toNubListR $ extraLibs libBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs libBi,
ghcOptLinkFrameworks = toNubListR $
PD.frameworks libBi,
ghcOptLinkFrameworkDirs = toNubListR $
PD.extraFrameworkDirs libBi,
ghcOptInputFiles = toNubListR
[libTargetDir </> x | x <- cObjs]
}
Expand Down Expand Up @@ -724,6 +727,8 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptLinkLibs = toNubListR $ extraLibs libBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs libBi,
ghcOptLinkFrameworks = toNubListR $ PD.frameworks libBi,
ghcOptLinkFrameworkDirs =
toNubListR $ PD.extraFrameworkDirs libBi,
ghcOptRPaths = rpaths
}

Expand Down Expand Up @@ -846,10 +851,13 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
ghcOptHPCDir = hpcdir Hpc.Dyn
}
linkerOpts = mempty {
ghcOptLinkOptions = toNubListR $ PD.ldOptions exeBi,
ghcOptLinkLibs = toNubListR $ extraLibs exeBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs exeBi,
ghcOptLinkFrameworks = toNubListR $ PD.frameworks exeBi,
ghcOptLinkOptions = toNubListR $ PD.ldOptions exeBi,
ghcOptLinkLibs = toNubListR $ extraLibs exeBi,
ghcOptLinkLibPath = toNubListR $ extraLibDirs exeBi,
ghcOptLinkFrameworks = toNubListR $
PD.frameworks exeBi,
ghcOptLinkFrameworkDirs = toNubListR $
PD.extraFrameworkDirs exeBi,
ghcOptInputFiles = toNubListR
[exeDir </> x | x <- cObjs]
}
Expand Down
7 changes: 7 additions & 0 deletions Cabal/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ data GhcOptions = GhcOptions {
-- | OSX only: frameworks to link in; the @ghc -framework@ flag.
ghcOptLinkFrameworks :: NubListR String,

-- | OSX only: Search path for frameworks to link in; the
-- @ghc -framework-path@ flag.
ghcOptLinkFrameworkDirs :: NubListR String,

-- | Don't do the link step, useful in make mode; the @ghc -no-link@ flag.
ghcOptNoLink :: Flag Bool,

Expand Down Expand Up @@ -363,6 +367,7 @@ renderGhcOptions comp opts
, ["-l" ++ lib | lib <- flags ghcOptLinkLibs ]
, ["-L" ++ dir | dir <- flags ghcOptLinkLibPath ]
, concat [ ["-framework", fmwk] | fmwk <- flags ghcOptLinkFrameworks ]
, concat [ ["-framework-path", path] | path <- flags ghcOptLinkFrameworkDirs ]
, [ "-no-hs-main" | flagBool ghcOptLinkNoHsMain ]
, [ "-dynload deploy" | not (null (flags ghcOptRPaths)) ]
, concat [ [ "-optl-Wl,-rpath," ++ dir]
Expand Down Expand Up @@ -500,6 +505,7 @@ instance Monoid GhcOptions where
ghcOptLinkLibPath = mempty,
ghcOptLinkOptions = mempty,
ghcOptLinkFrameworks = mempty,
ghcOptLinkFrameworkDirs = mempty,
ghcOptNoLink = mempty,
ghcOptLinkNoHsMain = mempty,
ghcOptCcOptions = mempty,
Expand Down Expand Up @@ -556,6 +562,7 @@ instance Semigroup GhcOptions where
ghcOptLinkLibPath = combine ghcOptLinkLibPath,
ghcOptLinkOptions = combine ghcOptLinkOptions,
ghcOptLinkFrameworks = combine ghcOptLinkFrameworks,
ghcOptLinkFrameworkDirs = combine ghcOptLinkFrameworkDirs,
ghcOptNoLink = combine ghcOptNoLink,
ghcOptLinkNoHsMain = combine ghcOptLinkNoHsMain,
ghcOptCcOptions = combine ghcOptCcOptions,
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
-- We don't want cc-options to be propagated
-- to C compilations in other packages.
IPI.ldOptions = ldOptions bi,
IPI.frameworkDirs = [],
IPI.frameworks = frameworks bi,
IPI.frameworkDirs = extraFrameworkDirs bi,
IPI.haddockInterfaces = [haddockdir installDirs </> haddockName pkg],
IPI.haddockHTMLs = [htmldir installDirs],
IPI.pkgRoot = Nothing
Expand Down
10 changes: 10 additions & 0 deletions Cabal/Distribution/Simple/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ data ConfigFlags = ConfigFlags {
-- paths
configScratchDir :: Flag FilePath,
configExtraLibDirs :: [FilePath], -- ^ path to search for extra libraries
configExtraFrameworkDirs :: [FilePath], -- ^ path to search for extra
-- frameworks (OS X only)
configExtraIncludeDirs :: [FilePath], -- ^ path to search for header files
configIPID :: Flag String, -- ^ explicit IPID to be used

Expand Down Expand Up @@ -624,6 +626,12 @@ configureOptions showOrParseArgs =
configExtraLibDirs (\v flags -> flags {configExtraLibDirs = v})
(reqArg' "PATH" (\x -> [x]) id)

,option "" ["extra-framework-dirs"]
"A list of directories to search for external frameworks (OS X only)"
configExtraFrameworkDirs
(\v flags -> flags {configExtraFrameworkDirs = v})
(reqArg' "PATH" (\x -> [x]) id)

,option "" ["extra-prog-path"]
"A list of directories to search for required programs (in addition to the normal search locations)"
configProgramPathExtra (\v flags -> flags {configProgramPathExtra = v})
Expand Down Expand Up @@ -818,6 +826,7 @@ instance Monoid ConfigFlags where
configStripExes = mempty,
configStripLibs = mempty,
configExtraLibDirs = mempty,
configExtraFrameworkDirs = mempty,
configConstraints = mempty,
configDependencies = mempty,
configExtraIncludeDirs = mempty,
Expand Down Expand Up @@ -867,6 +876,7 @@ instance Semigroup ConfigFlags where
configStripExes = combine configStripExes,
configStripLibs = combine configStripLibs,
configExtraLibDirs = combine configExtraLibDirs,
configExtraFrameworkDirs = combine configExtraFrameworkDirs,
configConstraints = combine configConstraints,
configDependencies = combine configDependencies,
configExtraIncludeDirs = combine configExtraIncludeDirs,
Expand Down
6 changes: 6 additions & 0 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ module Distribution.Simple.Utils (
listUnionRight,
ordNub,
ordNubRight,
safeTail,
wrapText,
wrapLine,
) where
Expand Down Expand Up @@ -1473,6 +1474,11 @@ listUnionRight a b = ordNubRight (filter (`Set.notMember` bSet) a) ++ b
where
bSet = Set.fromList b

-- | A total variant of 'tail'.
safeTail :: [a] -> [a]
safeTail [] = []
safeTail (_:xs) = xs

equating :: Eq a => (b -> a) -> b -> b -> Bool
equating p x y = p x == p y

Expand Down
4 changes: 4 additions & 0 deletions Cabal/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-*-change-log-*-

1.23.x.x (current development version)
* Support GHC 8.
* Deal with extra C sources from preprocessors (#238).
* Include cabal_macros.h when running c2hs (#2600).
* Don't recompile C sources unless needed (#2601).
Expand All @@ -21,6 +22,9 @@
* Improved the './Setup configure' solver (#3082, #3076).
* The '--allow-newer' option can be now used with './Setup
configure' (#3163).
* Added a way to specify extra locations to find OS X frameworks
in ('extra-framework-dirs'). Can be used both in .cabal files and
as an argument to './Setup configure' (#3158).

1.22.0.0 Johan Tibell <johan.tibell@gmail.com> January 2015
* Support GHC 7.10.
Expand Down
12 changes: 8 additions & 4 deletions Cabal/doc/developing-packages.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1255,12 +1255,12 @@ pass to `cabal bench`.

### Build information ###

The following fields may be optionally present in a library or
executable section, and give information for the building of the
The following fields may be optionally present in a library, executable, test
suite or benchmark section, and give information for the building of the
corresponding library or executable. See also the sections on
[system-dependent parameters](#system-dependent-parameters) and
[configurations](#configurations) for a way to supply system-dependent
values for these fields.
[configurations](#configurations) for a way to supply system-dependent values
for these fields.

`build-depends:` _package list_
: A list of packages needed to build this one. Each package can be
Expand Down Expand Up @@ -1467,6 +1467,10 @@ values for these fields.
developer documentation for more details on frameworks. This entry
is ignored on all other platforms.

`extra-frameworks-dirs:` _directory list_
: On Darwin/MacOS X, a list of directories to search for frameworks.
This entry is ignored on all other platforms.

### Configurations ###

Library and executable sections may include conditional
Expand Down
Loading

0 comments on commit eb21f98

Please sign in to comment.