Commit 81330d03 authored by Luite Stegeman's avatar Luite Stegeman
Browse files

Add the js-sources and various ghcjs-options fields to PackageDescription

This patch adds the js-sources field, for JavaScript source code
that should be included in compiled programs, similar to c-sources
for other targets.

It also adds ghcjs-options, ghcjs-shared-options and ghcjs-prof-options
and makes the underlying code for options easier to extend.
parent c933a4cc
......@@ -85,6 +85,8 @@ module Distribution.PackageDescription (
allExtensions,
usedExtensions,
hcOptions,
hcProfOptions,
hcSharedOptions,
-- ** Supplementary build information
HookedBuildInfo,
......@@ -765,6 +767,7 @@ data BuildInfo = BuildInfo {
pkgconfigDepends :: [Dependency], -- ^ pkg-config packages that are used
frameworks :: [String], -- ^support frameworks for Mac OS X
cSources :: [FilePath],
jsSources :: [FilePath],
hsSourceDirs :: [FilePath], -- ^ where to look for the Haskell module hierarchy
otherModules :: [ModuleName], -- ^ non-exposed or non-main modules
......@@ -781,8 +784,8 @@ data BuildInfo = BuildInfo {
includes :: [FilePath], -- ^ The .h files to be found in includeDirs
installIncludes :: [FilePath], -- ^ .h files to install with the package
options :: [(CompilerFlavor,[String])],
ghcProfOptions :: [String],
ghcSharedOptions :: [String],
profOptions :: [(CompilerFlavor,[String])],
sharedOptions :: [(CompilerFlavor,[String])],
customFieldsBI :: [(String,String)], -- ^Custom fields starting
-- with x-, stored in a
-- simple assoc-list.
......@@ -803,6 +806,7 @@ instance Monoid BuildInfo where
pkgconfigDepends = [],
frameworks = [],
cSources = [],
jsSources = [],
hsSourceDirs = [],
otherModules = [],
defaultLanguage = Nothing,
......@@ -817,8 +821,8 @@ instance Monoid BuildInfo where
includes = [],
installIncludes = [],
options = [],
ghcProfOptions = [],
ghcSharedOptions = [],
profOptions = [],
sharedOptions = [],
customFieldsBI = [],
targetBuildDepends = [],
targetBuildRenaming = Map.empty
......@@ -832,6 +836,7 @@ instance Monoid BuildInfo where
pkgconfigDepends = combine pkgconfigDepends,
frameworks = combineNub frameworks,
cSources = combineNub cSources,
jsSources = combineNub jsSources,
hsSourceDirs = combineNub hsSourceDirs,
otherModules = combineNub otherModules,
defaultLanguage = combineMby defaultLanguage,
......@@ -846,8 +851,8 @@ instance Monoid BuildInfo where
includes = combineNub includes,
installIncludes = combineNub installIncludes,
options = combine options,
ghcProfOptions = combine ghcProfOptions,
ghcSharedOptions = combine ghcSharedOptions,
profOptions = combine profOptions,
sharedOptions = combine sharedOptions,
customFieldsBI = combine customFieldsBI,
targetBuildDepends = combineNub targetBuildDepends,
targetBuildRenaming = combineMap targetBuildRenaming
......@@ -907,9 +912,19 @@ emptyHookedBuildInfo = (Nothing, [])
-- |Select options for a particular Haskell compiler.
hcOptions :: CompilerFlavor -> BuildInfo -> [String]
hcOptions hc bi = [ opt | (hc',opts) <- options bi
, hc' == hc
, opt <- opts ]
hcOptions = lookupHcOptions options
hcProfOptions :: CompilerFlavor -> BuildInfo -> [String]
hcProfOptions = lookupHcOptions profOptions
hcSharedOptions :: CompilerFlavor -> BuildInfo -> [String]
hcSharedOptions = lookupHcOptions sharedOptions
lookupHcOptions :: (BuildInfo -> [(CompilerFlavor,[String])])
-> CompilerFlavor -> BuildInfo -> [String]
lookupHcOptions f hc bi = [ opt | (hc',opts) <- f bi
, hc' == hc
, opt <- opts ]
-- ------------------------------------------------------------
-- * Source repos
......
......@@ -724,7 +724,7 @@ checkGhcOptions pkg =
has_Werror = any (\opts -> "-Werror" `elem` opts) ghc_options
(ghc_options, ghc_prof_options) =
unzip . map (\bi -> (hcOptions GHC bi, ghcProfOptions bi))
unzip . map (\bi -> (hcOptions GHC bi, hcProfOptions GHC bi))
$ (allBuildInfo pkg)
all_ghc_options = concat ghc_options
all_ghc_prof_options = concat ghc_prof_options
......@@ -878,6 +878,7 @@ checkPaths pkg =
++ [ (path, "data-dir") | path <- [dataDir pkg]]
++ concat
[ [ (path, "c-sources") | path <- cSources bi ]
++ [ (path, "js-sources") | path <- jsSources bi ]
++ [ (path, "install-includes") | path <- installIncludes bi ]
++ [ (path, "hs-source-dirs") | path <- hsSourceDirs bi ]
| bi <- allBuildInfo pkg ]
......
......@@ -418,7 +418,9 @@ binfoFieldDescrs =
, listFieldWithSep vcat "c-sources"
showFilePath parseFilePathQ
cSources (\paths binfo -> binfo{cSources=paths})
, listFieldWithSep vcat "js-sources"
showFilePath parseFilePathQ
jsSources (\paths binfo -> binfo{jsSources=paths})
, simpleField "default-language"
(maybe empty disp) (option Nothing (fmap Just parseLanguageQ))
defaultLanguage (\lang binfo -> binfo{defaultLanguage=lang})
......@@ -459,14 +461,18 @@ binfoFieldDescrs =
, listFieldWithSep vcat "other-modules"
disp parseModuleNameQ
otherModules (\val binfo -> binfo{otherModules=val})
, listField "ghc-prof-options"
text parseTokenQ
ghcProfOptions (\val binfo -> binfo{ghcProfOptions=val})
, listField "ghc-shared-options"
text parseTokenQ
ghcSharedOptions (\val binfo -> binfo{ghcSharedOptions=val})
, optsField "ghc-prof-options" GHC
profOptions (\val binfo -> binfo{profOptions=val})
, optsField "ghcjs-prof-options" GHCJS
profOptions (\val binfo -> binfo{profOptions=val})
, optsField "ghc-shared-options" GHC
sharedOptions (\val binfo -> binfo{sharedOptions=val})
, optsField "ghcjs-shared-options" GHCJS
sharedOptions (\val binfo -> binfo{sharedOptions=val})
, optsField "ghc-options" GHC
options (\path binfo -> binfo{options=path})
, optsField "ghcjs-options" GHCJS
options (\path binfo -> binfo{options=path})
, optsField "jhc-options" JHC
options (\path binfo -> binfo{options=path})
......
......@@ -268,7 +268,7 @@ ppFields fields x =
vcat [ ppField name (getter x) | FieldDescr name getter _ <- fields ]
ppField :: String -> Doc -> Doc
ppField name fielddoc
ppField name fielddoc
| isEmpty fielddoc = empty
| name `elem` nestedFields = text name <> colon $+$ nest indentWith fielddoc
| otherwise = text name <> colon <+> fielddoc
......@@ -281,6 +281,7 @@ ppField name fielddoc
, "extra-tmp-files"
, "exposed-modules"
, "c-sources"
, "js-sources"
, "extra-libraries"
, "includes"
, "install-includes"
......
......@@ -426,7 +426,8 @@ data ComponentInfo = ComponentInfo {
cinfoSrcDirs :: [FilePath],
cinfoModules :: [ModuleName],
cinfoHsFiles :: [FilePath], -- other hs files (like main.hs)
cinfoCFiles :: [FilePath]
cinfoCFiles :: [FilePath],
cinfoJsFiles :: [FilePath]
}
type ComponentStringName = String
......@@ -439,7 +440,8 @@ pkgComponentInfo pkg =
cinfoSrcDirs = hsSourceDirs bi,
cinfoModules = componentModules c,
cinfoHsFiles = componentHsFiles c,
cinfoCFiles = cSources bi
cinfoCFiles = cSources bi,
cinfoJsFiles = jsSources bi
}
| c <- pkgComponents pkg
, let bi = componentBuildInfo c ]
......@@ -658,12 +660,14 @@ matchComponentFile c str fexists =
, matchOtherFileRooted dirs hsFiles str ])
(msum [ matchModuleFileUnrooted ms str
, matchOtherFileUnrooted hsFiles str
, matchOtherFileUnrooted cFiles str ]))
, matchOtherFileUnrooted cFiles str
, matchOtherFileUnrooted jsFiles str ]))
where
dirs = cinfoSrcDirs c
ms = cinfoModules c
hsFiles = cinfoHsFiles c
cFiles = cinfoCFiles c
jsFiles = cinfoJsFiles c
-- utils
......
......@@ -51,7 +51,8 @@ import qualified Distribution.Simple.GHC.IPI641 as IPI641
import qualified Distribution.Simple.GHC.IPI642 as IPI642
import Distribution.PackageDescription as PD
( PackageDescription(..), BuildInfo(..), Executable(..)
, Library(..), libModules, exeModules, hcOptions
, Library(..), libModules, exeModules
, hcOptions, hcProfOptions, hcSharedOptions
, usedExtensions, allExtensions, ModuleRenaming, lookupRenaming )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo )
......@@ -740,7 +741,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptProfilingMode = toFlag True,
ghcOptHiSuffix = toFlag "p_hi",
ghcOptObjSuffix = toFlag "p_o",
ghcOptExtra = toNubListR $ ghcProfOptions libBi
ghcOptExtra = toNubListR $ hcProfOptions GHC libBi
}
sharedOpts = vanillaOpts `mappend` mempty {
......@@ -748,7 +749,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
ghcOptFPic = toFlag True,
ghcOptHiSuffix = toFlag "dyn_hi",
ghcOptObjSuffix = toFlag "dyn_o",
ghcOptExtra = toNubListR $ ghcSharedOptions libBi
ghcOptExtra = toNubListR $ hcSharedOptions GHC libBi
}
linkerOpts = mempty {
ghcOptLinkOptions = toNubListR $ PD.ldOptions libBi,
......@@ -781,7 +782,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
useDynToo = dynamicTooSupported &&
(forceVanillaLib || withVanillaLib lbi) &&
(forceSharedLib || withSharedLib lbi) &&
null (ghcSharedOptions libBi)
null (hcSharedOptions GHC libBi)
if useDynToo
then runGhcProg vanillaSharedOpts
else if isGhcDynamic then do shared; vanilla
......@@ -998,13 +999,14 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
ghcOptProfilingMode = toFlag True,
ghcOptHiSuffix = toFlag "p_hi",
ghcOptObjSuffix = toFlag "p_o",
ghcOptExtra = toNubListR $ ghcProfOptions exeBi
ghcOptExtra = toNubListR $ hcProfOptions GHC exeBi
}
dynOpts = baseOpts `mappend` mempty {
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
ghcOptHiSuffix = toFlag "dyn_hi",
ghcOptObjSuffix = toFlag "dyn_o",
ghcOptExtra = toNubListR $ ghcSharedOptions exeBi
ghcOptExtra = toNubListR $
hcSharedOptions GHC exeBi
}
dynTooOpts = staticOpts `mappend` mempty {
ghcOptDynLinkMode = toFlag GhcStaticAndDynamic,
......@@ -1050,7 +1052,8 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
doingTH = EnableExtension TemplateHaskell `elem` allExtensions exeBi
-- Should we use -dynamic-too instead of compiling twice?
useDynToo = dynamicTooSupported && isGhcDynamic
&& doingTH && withStaticExe && null (ghcSharedOptions exeBi)
&& doingTH && withStaticExe
&& null (hcSharedOptions GHC exeBi)
compileTHOpts | isGhcDynamic = dynOpts
| otherwise = staticOpts
compileForTH
......@@ -1173,13 +1176,13 @@ libAbiHash verbosity _pkg_descr lbi lib clbi = do
ghcOptFPic = toFlag True,
ghcOptHiSuffix = toFlag "dyn_hi",
ghcOptObjSuffix = toFlag "dyn_o",
ghcOptExtra = toNubListR $ ghcSharedOptions libBi
ghcOptExtra = toNubListR $ hcSharedOptions GHC libBi
}
profArgs = vanillaArgs `mappend` mempty {
ghcOptProfilingMode = toFlag True,
ghcOptHiSuffix = toFlag "p_hi",
ghcOptObjSuffix = toFlag "p_o",
ghcOptExtra = toNubListR $ ghcProfOptions libBi
ghcOptExtra = toNubListR $ hcProfOptions GHC libBi
}
ghcArgs = if withVanillaLib lbi then vanillaArgs
else if withSharedLib lbi then sharedArgs
......
......@@ -28,11 +28,12 @@ import Distribution.Package
import qualified Distribution.ModuleName as ModuleName
import Distribution.PackageDescription as PD
( PackageDescription(..), BuildInfo(..), usedExtensions
, hcSharedOptions
, Library(..), hasLibs, Executable(..)
, TestSuite(..), TestSuiteInterface(..)
, Benchmark(..), BenchmarkInterface(..) )
import Distribution.Simple.Compiler
( Compiler(..), compilerVersion )
( Compiler(..), CompilerFlavor(..), compilerVersion )
import Distribution.Simple.GHC ( componentGhcOptions, ghcLibDir )
import Distribution.Simple.Program.GHC
( GhcOptions(..), GhcDynLinkMode(..), renderGhcOptions )
......@@ -301,7 +302,7 @@ fromLibrary verbosity tmp lbi lib clbi htmlTemplate haddockVersion = do
ghcOptFPic = toFlag True,
ghcOptHiSuffix = toFlag "dyn_hi",
ghcOptObjSuffix = toFlag "dyn_o",
ghcOptExtra = toNubListR $ ghcSharedOptions bi
ghcOptExtra = toNubListR $ hcSharedOptions GHC bi
}
opts <- if withVanillaLib lbi
then return vanillaOpts
......@@ -341,7 +342,7 @@ fromExecutable verbosity tmp lbi exe clbi htmlTemplate haddockVersion = do
ghcOptFPic = toFlag True,
ghcOptHiSuffix = toFlag "dyn_hi",
ghcOptObjSuffix = toFlag "dyn_o",
ghcOptExtra = toNubListR $ ghcSharedOptions bi
ghcOptExtra = toNubListR $ hcSharedOptions GHC bi
}
opts <- if withVanillaLib lbi
then return vanillaOpts
......
......@@ -41,7 +41,8 @@ module Distribution.Simple.LHC (
import Distribution.PackageDescription as PD
( PackageDescription(..), BuildInfo(..), Executable(..)
, Library(..), libModules, hcOptions, usedExtensions, allExtensions )
, Library(..), libModules, hcOptions, usedExtensions, allExtensions
, hcSharedOptions, hcProfOptions )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo
, parseInstalledPackageInfo )
......@@ -344,13 +345,13 @@ buildLib verbosity pkg_descr lbi lib clbi = do
"-hisuf", "p_hi",
"-osuf", "p_o"
]
++ ghcProfOptions libBi
++ hcProfOptions GHC libBi
ghcArgsShared = ghcArgs
++ ["-dynamic",
"-hisuf", "dyn_hi",
"-osuf", "dyn_o", "-fPIC"
]
++ ghcSharedOptions libBi
++ hcSharedOptions GHC libBi
unless (null (libModules lib)) $
do ifVanillaLib forceVanillaLib (runGhcProg $ lhcWrap ghcArgs)
ifProfLib (runGhcProg $ lhcWrap ghcArgsProf)
......@@ -529,7 +530,7 @@ buildExe verbosity _pkg_descr lbi
then ["-prof",
"-hisuf", "p_hi",
"-osuf", "p_o"
] ++ ghcProfOptions exeBi
] ++ hcProfOptions GHC exeBi
else []
-- For building exe's for profiling that use TH we actually
......
......@@ -443,7 +443,7 @@ allSourcesBuildInfo bi pps modules = do
in findFileWithExtension fileExts (hsSourceDirs bi) file
| module_ <- modules ++ otherModules bi ]
return $ sources ++ catMaybes bootFiles ++ cSources bi
return $ sources ++ catMaybes bootFiles ++ cSources bi ++ jsSources bi
where
suffixes = ppSuffixes pps ++ ["hs", "lhs"]
......
......@@ -1398,6 +1398,10 @@ values for these fields.
`c-sources:` _filename list_
: A list of C source files to be compiled and linked with the Haskell files.
`js-sources:` _filename list_
: A list of JavaScript source files to be linked with the Haskell files
(only for JavaScript targets).
`extra-libraries:` _token list_
: A list of extra libraries to link with.
......
......@@ -1013,8 +1013,8 @@ this section will be available.
The files placed in this distribution are the package description file,
the setup script, the sources of the modules named in the package
description file, and files named in the `license-file`, `main-is`,
`c-sources`, `data-files`, `extra-source-files` and `extra-doc-files`
fields.
`c-sources`, `js-sources`, `data-files`, `extra-source-files` and
`extra-doc-files` fields.
This command takes the following option:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment