Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Infer target platform from ghc --info #1214

Merged
merged 3 commits into from

7 participants

@lukexi

Add a new operating system: iOS

Base install paths on target platform

Thread platform through Cabal

Infer target platform from ghc --info

@23Skidoo
Collaborator

I don't think that this is what Johan meant :-)

You have one large commit that contains all your changes instead of a series of relatively small and self-contained patches where each one can be reviewed separately.

Also, you don't have to close the pull request if you just want to edit history with rebase: you can just do push -f to the relevant branch and the pull request will be automatically updated.

@tibbe
Owner

What @23Skidoo said. It looks like this could e.g. be 4 commits, based on the four sentences in the commit message. Thanks for your patience!

@lukexi

Sorry about that : ) — here it is again split into 4 logical commits.

b3594cb, 8eaf9a1 and fab3dd7 should work in isolation and b1c6200 depends on 8eaf9a1.

@tibbe
Owner

Could someone clarify what the current buildPlatform variable means? Is it the platform GHC was built on (as described in http://hackage.haskell.org/trac/ghc/wiki/CrossCompilation)?

@dcoutts
Collaborator

I think putting the Platform into the Compiler type is not right, it should go into the LocalBuildInfo directly. It's not just the compiler that varies between platforms, it's the whole toolchain.

Fixing this should not be hard. In the configCompiler, just return (Compiler, Maybe Platform, ProgramConfiguration), ie return the platform as a separate result. (Of course all other compilers other than GHC will return Nothing.) Then if it's not Nothing, put it into the LocalBuildInfo, or default to the build platform. This also leaves open the option later to take the target platform as a command line arg, rather than inferring based on the ghc.

Longer term, I expect we'll need more info for the target, a whole target profile with info about the whole toolchain, default c flags etc etc. And the appropriate place for that is in the LocalBuildInfo, so that's the other reson we should make sure we start by putting the Platform id in the right place.

@lukexi

Hi Duncan, that all sounds great. I'll make the changes later today. Thanks for reviewing!

@lukexi

Here are those changes — let me know if that looks good and I'll tidy up the history.

@dcoutts
Collaborator

That looks good, thanks. Can I make one nitpick?

So we have the "build" platform and the "host" platform. (I had to go look it up to make sure I've got the right terminology!) (Note also, that there's no such thing as the "target" platform in our context, that only makes sense for compilers.)

In Distribution.System we have the right name buildPlatform :: Platform. So to keep things clear, we should also use the terminology "host" in the code. So we ought really to call it hostPlatform :: Platform, ie the field in LocalBuildInfo should be hostPlatform rather than just platform.

Sorry about asking you to go do more renaming, but it's probably best to establish that naming convention from the start rather than people gettting confused later about build vs host.

We should then (I don't mean you have to do this in this patch!) audit our other uses of buildPlatform and see which ought to be changed to hostPlatform. I suspect there's several, in particular in the cabal config flags, if you use "if arch(blah)", that probably ought to refer to the host not the build platform (and we may decide we need both). Anyway, that's for later.

@lukexi

No problem! It's tricky to keep straight so I'm all for extra clarity : ). I'll do that now.

@lukexi

^ Tidied up.

Cabal/Distribution/Simple/GHC.hs
((5 lines not shown))
conf4 = configureToolchain ghcProg ghcInfo conf3 -- configure gcc and ld
- return (comp, conf4)
+ return (comp, compPlatform, conf4)
+
+targetPlatform :: [(String, String)] -> Platform
+targetPlatform ghcInfo = fromMaybe buildPlatform maybePlatform
@tibbe Owner
tibbe added a note

You already do this defaulting in Configure. Couldn't you just return Nothing here on failure instead of duplicating the defaulting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tibbe
Owner

This looks great. Just added one minor comment and then we're good to merge.

lukexi added some commits
@lukexi lukexi Return Maybe Platform as part of compiler configure, and place it in …
…LocalBuildInfo as hostPlatform.

GHC infers the platform form ghc --info using new 'platformFromTriple' function. Other compilers return Nothing, which triggers fallback to old behavior of using buildPlatform. hostPlatform is then threaded through to initialPathTemplateEnv.
7a0941c
@lukexi lukexi Adds $arch-$os-$compiler to libsubdir, datasubdir and docdir by defau…
…lt as suggested in haskell/cabal#1214
fa44826
@lukexi

Nice catch, thanks!

@tibbe tibbe merged commit fa44826 into haskell:master
@tibbe
Owner

All merged. Thanks for the patches!

@23Skidoo 23Skidoo commented on the diff
cabal-install/Distribution/Client/Install.hs
((5 lines not shown))
-> PackageDescription
-> IO a -> IO a
-withWin32SelfUpgrade _ _ _ _ action | buildOS /= Windows = action
-withWin32SelfUpgrade verbosity configFlags compid pkg action = do
+withWin32SelfUpgrade _ _ _ _ _ action | buildOS /= Windows = action
@23Skidoo Collaborator
23Skidoo added a note

Shouldn't you replace the buildOS /= Windows check with platformOS platform /= Windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@nh2

Could we change this such that public API like configCompiler still returns the old tuple?

This change breaks almost all packages that use a custom Setup.hs, and the only way for them to support multiple cabal versions would be CPP.

Maybe we could add another function that returns the triple, and deprecate the old one.

@cartazio

you can't use CPP that branches on lib versions in setup.hs, so you'd have to use template haskell with hand written ASTs

@cartazio

breaking changes to the cabal apis need to probably go through a release or so of just being deprecated before being removed, else its really really hard for maintainers to support multiple cabal versions. (though gnarly setup.hs files are breakage prone by their very nature)

@dagit

@cartazio and the additional limitation that you can't specify what version of Cabal a Setup.hs file depends (otherwise, that might provide an escape hatch for some API changes).

@cartazio

@dagit there is a hacky work around, but its basically doing poor man's CPP

used it to patch the bos/llvm lib to work with cabal 1.17

{-
this is the workaround for conditional compilation if template haskell was more
    permissive, but isn't

 --- what i'd like to write, but can't because template haskell rejecting
 the branch that has the wrong api version
 extractCLBI x=
     $(if cabalVersion >= Version [1,17,0] []
         then [|  getComponentLocalBuildInfo 'x CLibName  |]
         else  [|
                    let   LocalBuildInfo  { libraryConfig = Just clbi } = 'x
                        in clbi |]
    )


-}

--- horrible hack to support cabal versions both above and below 1.17
extractCLBI x=
    $(if cabalVersion >= Version [1,17,0] []
        then  appE (appE  ( varE $ mkName "getComponentLocalBuildInfo") ( varE 'x) ) (conE ( mkName "CLibName"))

        else  letE
                [valD  (recP
                            (mkName "LocalBuildInfo" )
                            [fieldPat (mkName "libraryConfig")
                             (conP (mkName "Just")    [varP $ mkName "clbi"] ) ] )
                    (normalB $ varE 'x)   []    ]
                 (varE $ mkName "clbi")  )

[edit: fixed quoting]

@nh2

@cartazio

you can't use CPP that branches on lib versions in setup.hs

If I understand it right, you agree with me that this API change is problematic?

@cartazio

i'm saying that its currently a pain in the ass (albeit doable hackily) to work around these api changes, but it really sucks, and will only get fixed by proactive maintainers.

the real problem is theres no way to have setup.hs have CPP than usages the cabal library version

@23Skidoo
Collaborator

@cartazio

i can't quote this block properly, but you get the idea

Use ``` (three backticks) instead of '''.

@cartazio

@23Skidoo thanks, Fixed

@23Skidoo 23Skidoo referenced this pull request from a commit in 23Skidoo/cabal
@23Skidoo 23Skidoo Backwards compatibility patch for cross-compilation changes.
Changes back the types of 'configCompiler' and 'configCompilerEx', but marks
them as deprecated. Adds new functions 'configCompilerEx' and
'configCompilerAuxEx'.

The remaining functions that changed type after the cross-compilation changes
shouldn't matter from the backwards compatibility standpoint:

    * InstallDirs.{absoluteInstallDirs, prefixRelativeInstallDirs,
      initialPathTemplateEnv} - the versions in D.S.LocalBuildInfo retain their
      old types and are usually used instead. In any case, removing the Platform
      parameter from here is problematic because the default install dirs now
      include $arch and $os vars.

    * D.S.Configure.configure - shouldn't be used by the setup scripts.

See #1214 for the original (backwards-incompatible) patches.
b57b115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2013
  1. @lukexi

    Add iOS as an OS.

    lukexi authored
Commits on Mar 1, 2013
  1. @lukexi

    Return Maybe Platform as part of compiler configure, and place it in …

    lukexi authored
    …LocalBuildInfo as hostPlatform.
    
    GHC infers the platform form ghc --info using new 'platformFromTriple' function. Other compilers return Nothing, which triggers fallback to old behavior of using buildPlatform. hostPlatform is then threaded through to initialPathTemplateEnv.
  2. @lukexi
This page is out of date. Refresh to see the latest.
View
3  Cabal/Distribution/Simple/Bench.hs
@@ -152,5 +152,6 @@ benchOption pkg_descr lbi bm template =
fromPathTemplate $ substPathTemplate env template
where
env = initialPathTemplateEnv
- (PD.package pkg_descr) (compilerId $ LBI.compiler lbi) ++
+ (PD.package pkg_descr) (compilerId $ LBI.compiler lbi)
+ (LBI.hostPlatform lbi) ++
[(BenchmarkNameVar, toPathTemplate $ PD.benchmarkName bm)]
View
38 Cabal/Distribution/Simple/Configure.hs
@@ -115,7 +115,7 @@ import Distribution.Simple.Utils
, withFileContents, writeFileAtomic
, withTempFile )
import Distribution.System
- ( OS(..), buildOS, Arch(..), buildArch, buildPlatform )
+ ( OS(..), buildOS, Arch(..), Platform(..), buildPlatform )
import Distribution.Version
( Version(..), anyVersion, orLaterVersion, withinRange, isAnyVersion )
import Distribution.Verbosity
@@ -137,7 +137,7 @@ import Control.Monad
import Data.List
( nub, partition, isPrefixOf, inits )
import Data.Maybe
- ( isNothing, catMaybes )
+ ( isNothing, catMaybes, fromMaybe )
import Data.Monoid
( Monoid(..) )
import System.Directory
@@ -287,7 +287,7 @@ configure (pkg_descr0, pbi) cfg
(configPackageDBs cfg)
-- detect compiler
- (comp, programsConfig') <- configCompiler
+ (comp, compPlatform, programsConfig') <- configCompiler
(flagToMaybe $ configHcFlavor cfg)
(flagToMaybe $ configHcPath cfg) (flagToMaybe $ configHcPkg cfg)
programsConfig (lessVerbose verbosity)
@@ -340,7 +340,7 @@ configure (pkg_descr0, pbi) cfg
case finalizePackageDescription
(configConfigurationsFlags cfg)
dependencySatisfiable
- Distribution.System.buildPlatform
+ compPlatform
(compilerId comp)
(configConstraints cfg)
pkg_descr0''
@@ -492,6 +492,7 @@ configure (pkg_descr0, pbi) cfg
-- did they would go here.
installDirTemplates = installDirs,
compiler = comp,
+ hostPlatform = compPlatform,
buildDir = buildDir',
scratchDir = fromFlagOrDefault
(distPref </> "scratch")
@@ -792,7 +793,7 @@ ccLdOptionsBuildInfo cflags ldflags =
-- -----------------------------------------------------------------------------
-- Determining the compiler details
-configCompilerAux :: ConfigFlags -> IO (Compiler, ProgramConfiguration)
+configCompilerAux :: ConfigFlags -> IO (Compiler, Platform, ProgramConfiguration)
configCompilerAux cfg = configCompiler (flagToMaybe $ configHcFlavor cfg)
(flagToMaybe $ configHcPath cfg)
(flagToMaybe $ configHcPkg cfg)
@@ -805,18 +806,19 @@ configCompilerAux cfg = configCompiler (flagToMaybe $ configHcFlavor cfg)
configCompiler :: Maybe CompilerFlavor -> Maybe FilePath -> Maybe FilePath
-> ProgramConfiguration -> Verbosity
- -> IO (Compiler, ProgramConfiguration)
+ -> IO (Compiler, Platform, ProgramConfiguration)
configCompiler Nothing _ _ _ _ = die "Unknown compiler"
configCompiler (Just hcFlavor) hcPath hcPkg conf verbosity = do
- case hcFlavor of
- GHC -> GHC.configure verbosity hcPath hcPkg conf
- JHC -> JHC.configure verbosity hcPath hcPkg conf
- LHC -> do (_,ghcConf) <- GHC.configure verbosity Nothing hcPkg conf
- LHC.configure verbosity hcPath Nothing ghcConf
- Hugs -> Hugs.configure verbosity hcPath hcPkg conf
- NHC -> NHC.configure verbosity hcPath hcPkg conf
- UHC -> UHC.configure verbosity hcPath hcPkg conf
- _ -> die "Unknown compiler"
+ (comp, maybePlatform, programsConfig) <- case hcFlavor of
+ GHC -> GHC.configure verbosity hcPath hcPkg conf
+ JHC -> JHC.configure verbosity hcPath hcPkg conf
+ LHC -> do (_, _, ghcConf) <- GHC.configure verbosity Nothing hcPkg conf
+ LHC.configure verbosity hcPath Nothing ghcConf
+ Hugs -> Hugs.configure verbosity hcPath hcPkg conf
+ NHC -> NHC.configure verbosity hcPath hcPkg conf
+ UHC -> UHC.configure verbosity hcPath hcPkg conf
+ _ -> die "Unknown compiler"
+ return (comp, fromMaybe buildPlatform maybePlatform, programsConfig)
-- -----------------------------------------------------------------------------
@@ -1030,7 +1032,7 @@ checkForeignDeps pkg lbi verbosity = do
hcDefines comp =
case compilerFlavor comp of
GHC ->
- let ghcOS = case buildOS of
+ let ghcOS = case hostOS of
Linux -> ["linux"]
Windows -> ["mingw32"]
OSX -> ["darwin"]
@@ -1042,8 +1044,9 @@ checkForeignDeps pkg lbi verbosity = do
HPUX -> ["hpux"]
IRIX -> ["irix"]
HaLVM -> []
+ IOS -> ["ios"]
OtherOS _ -> []
- ghcArch = case buildArch of
+ ghcArch = case hostArch of
I386 -> ["i386"]
X86_64 -> ["x86_64"]
PPC -> ["powerpc"]
@@ -1068,6 +1071,7 @@ checkForeignDeps pkg lbi verbosity = do
Hugs -> ["-D__HUGS__"]
_ -> []
where
+ Platform hostArch hostOS = hostPlatform lbi
version = compilerVersion comp
-- TODO: move this into the compiler abstraction
-- FIXME: this forces GHC's crazy 4.8.2 -> 408 convention on all
View
9 Cabal/Distribution/Simple/GHC.hs
@@ -138,6 +138,7 @@ import System.FilePath ( (</>), (<.>), takeExtension,
import System.IO (hClose, hPutStrLn)
import System.Environment (getEnv)
import Distribution.Compat.Exception (catchExit, catchIO)
+import Distribution.System (Platform, buildPlatform, platformFromTriple)
getGhcInfo :: Verbosity -> ConfiguredProgram -> IO [(String, String)]
getGhcInfo verbosity ghcProg =
@@ -158,7 +159,7 @@ getGhcInfo verbosity ghcProg =
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
- -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
+ -> ProgramConfiguration -> IO (Compiler, Maybe Platform, ProgramConfiguration)
configure verbosity hcPath hcPkgPath conf0 = do
(ghcProg, ghcVersion, conf1) <-
@@ -196,8 +197,12 @@ configure verbosity hcPath hcPkgPath conf0 = do
compilerLanguages = languages,
compilerExtensions = extensions
}
+ compPlatform = targetPlatform ghcInfo
conf4 = configureToolchain ghcProg ghcInfo conf3 -- configure gcc and ld
- return (comp, conf4)
+ return (comp, compPlatform, conf4)
+
+targetPlatform :: [(String, String)] -> Maybe Platform
+targetPlatform ghcInfo = platformFromTriple =<< lookup "Target platform" ghcInfo
-- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find
-- the corresponding tool; e.g. if the tool is ghc-pkg, we try looking
View
1  Cabal/Distribution/Simple/Haddock.hs
@@ -530,6 +530,7 @@ haddockPackageFlags lbi clbi htmlTemplate = do
haddockTemplateEnv :: LocalBuildInfo -> PackageIdentifier -> PathTemplateEnv
haddockTemplateEnv lbi pkg_id = (PrefixVar, prefix (installDirTemplates lbi))
: initialPathTemplateEnv pkg_id (compilerId (compiler lbi))
+ (hostPlatform lbi)
-- --------------------------------------------------------------------------
-- hscolour support
View
6 Cabal/Distribution/Simple/Hugs.hs
@@ -118,6 +118,7 @@ import System.Directory
import System.Exit
( ExitCode(ExitSuccess) )
import Distribution.Compat.Exception
+import Distribution.System ( Platform )
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
@@ -125,7 +126,7 @@ import qualified Data.ByteString.Lazy.Char8 as BS.Char8
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
- -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
+ -> ProgramConfiguration -> IO (Compiler, Maybe Platform, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(_ffihugsProg, conf') <- requireProgram verbosity ffihugsProgram
@@ -139,7 +140,8 @@ configure verbosity hcPath _hcPkgPath conf = do
compilerLanguages = hugsLanguages,
compilerExtensions = hugsLanguageExtensions
}
- return (comp, conf'')
+ compPlatform = Nothing
+ return (comp, compPlatform, conf'')
where
hugsProgram' = hugsProgram { programFindVersion = getVersion }
View
27 Cabal/Distribution/Simple/InstallDirs.hs
@@ -80,7 +80,7 @@ import System.FilePath (dropDrive)
import Distribution.Package
( PackageIdentifier, packageName, packageVersion )
import Distribution.System
- ( OS(..), buildOS, Platform(..), buildPlatform )
+ ( OS(..), buildOS, Platform(..) )
import Distribution.Compiler
( CompilerId, CompilerFlavor(..) )
import Distribution.Text
@@ -236,7 +236,7 @@ defaultInstallDirs comp userInstall _hasLibs = do
JHC -> "$compiler"
LHC -> "$compiler"
UHC -> "$pkgid"
- _other -> "$pkgid" </> "$compiler",
+ _other -> "$arch-$os-$compiler" </> "$pkgid",
dynlibdir = "$libdir",
libexecdir = case buildOS of
Windows -> "$prefix" </> "$pkgid"
@@ -246,8 +246,8 @@ defaultInstallDirs comp userInstall _hasLibs = do
datadir = case buildOS of
Windows -> "$prefix"
_other -> "$prefix" </> "share",
- datasubdir = "$pkgid",
- docdir = "$datadir" </> "doc" </> "$pkgid",
+ datasubdir = "$arch-$os-$compiler" </> "$pkgid",
+ docdir = "$datadir" </> "doc" </> "$arch-$os-$compiler" </> "$pkgid",
mandir = "$datadir" </> "man",
htmldir = "$docdir" </> "html",
haddockdir = "$htmldir"
@@ -306,10 +306,10 @@ substituteInstallDirTemplates env dirs = dirs'
-- | Convert from abstract install directories to actual absolute ones by
-- substituting for all the variables in the abstract paths, to get real
-- absolute path.
-absoluteInstallDirs :: PackageIdentifier -> CompilerId -> CopyDest
+absoluteInstallDirs :: PackageIdentifier -> CompilerId -> CopyDest -> Platform
-> InstallDirs PathTemplate
-> InstallDirs FilePath
-absoluteInstallDirs pkgId compilerId copydest dirs =
+absoluteInstallDirs pkgId compilerId copydest platform dirs =
(case copydest of
CopyTo destdir -> fmap ((destdir </>) . dropDrive)
_ -> id)
@@ -317,7 +317,7 @@ absoluteInstallDirs pkgId compilerId copydest dirs =
. fmap fromPathTemplate
$ substituteInstallDirTemplates env dirs
where
- env = initialPathTemplateEnv pkgId compilerId
+ env = initialPathTemplateEnv pkgId compilerId platform
-- |The location prefix for the /copy/ command.
@@ -332,10 +332,10 @@ data CopyDest
-- prevents us from making a relocatable package (also known as a \"prefix
-- independent\" package).
--
-prefixRelativeInstallDirs :: PackageIdentifier -> CompilerId
+prefixRelativeInstallDirs :: PackageIdentifier -> CompilerId -> Platform
-> InstallDirTemplates
-> InstallDirs (Maybe FilePath)
-prefixRelativeInstallDirs pkgId compilerId dirs =
+prefixRelativeInstallDirs pkgId compilerId platform dirs =
fmap relative
. appendSubdirs combinePathTemplate
$ -- substitute the path template into each other, except that we map
@@ -345,7 +345,7 @@ prefixRelativeInstallDirs pkgId compilerId dirs =
prefix = PathTemplate [Variable PrefixVar]
}
where
- env = initialPathTemplateEnv pkgId compilerId
+ env = initialPathTemplateEnv pkgId compilerId platform
-- If it starts with $prefix then it's relative and produce the relative
-- path by stripping off $prefix/ or $prefix
@@ -417,12 +417,11 @@ substPathTemplate environment (PathTemplate template) =
Nothing -> [component]
-- | The initial environment has all the static stuff but no paths
-initialPathTemplateEnv :: PackageIdentifier -> CompilerId -> PathTemplateEnv
-initialPathTemplateEnv pkgId compilerId =
+initialPathTemplateEnv :: PackageIdentifier -> CompilerId -> Platform -> PathTemplateEnv
+initialPathTemplateEnv pkgId compilerId platform =
packageTemplateEnv pkgId
++ compilerTemplateEnv compilerId
- ++ platformTemplateEnv buildPlatform -- platform should be param if we want
- -- to do cross-platform configuation
+ ++ platformTemplateEnv platform
packageTemplateEnv :: PackageIdentifier -> PathTemplateEnv
packageTemplateEnv pkgId =
View
6 Cabal/Distribution/Simple/JHC.hs
@@ -84,6 +84,7 @@ import Distribution.Text
( Text(parse), display )
import Distribution.Compat.ReadP
( readP_to_S, string, skipSpaces )
+import Distribution.System ( Platform )
import Data.List ( nub )
import Data.Char ( isSpace )
@@ -96,7 +97,7 @@ import qualified Data.ByteString.Lazy.Char8 as BS.Char8
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
- -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
+ -> ProgramConfiguration -> IO (Compiler, Maybe Platform, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(jhcProg, _, conf') <- requireProgramVersion verbosity
@@ -109,7 +110,8 @@ configure verbosity hcPath _hcPkgPath conf = do
compilerLanguages = jhcLanguages,
compilerExtensions = jhcLanguageExtensions
}
- return (comp, conf')
+ compPlatform = Nothing
+ return (comp, compPlatform, conf')
jhcLanguages :: [(Language, Flag)]
jhcLanguages = [(Haskell98, "")]
View
6 Cabal/Distribution/Simple/LHC.hs
@@ -123,12 +123,13 @@ import System.FilePath ( (</>), (<.>), takeExtension,
takeDirectory, replaceExtension )
import System.IO (hClose, hPutStrLn)
import Distribution.Compat.Exception (catchExit, catchIO)
+import Distribution.System ( Platform )
-- -----------------------------------------------------------------------------
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
- -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
+ -> ProgramConfiguration -> IO (Compiler, Maybe Platform, ProgramConfiguration)
configure verbosity hcPath hcPkgPath conf = do
(lhcProg, lhcVersion, conf') <-
@@ -155,7 +156,8 @@ configure verbosity hcPath hcPkgPath conf = do
compilerExtensions = extensions
}
conf''' = configureToolchain lhcProg conf'' -- configure gcc and ld
- return (comp, conf''')
+ compPlatform = Nothing
+ return (comp, compPlatform, conf''')
-- | Adjust the way we find and configure gcc and ld
--
View
8 Cabal/Distribution/Simple/LocalBuildInfo.hs
@@ -102,7 +102,8 @@ import Distribution.Simple.Setup
( ConfigFlags )
import Distribution.Text
( display )
-
+import Distribution.System
+ ( Platform )
import Data.List (nub, find)
import Data.Graph
import Data.Tree (flatten)
@@ -124,6 +125,8 @@ data LocalBuildInfo = LocalBuildInfo {
--TODO: inplaceDirTemplates :: InstallDirs FilePath
compiler :: Compiler,
-- ^ The compiler we're building with
+ hostPlatform :: Platform,
+ -- ^ The platform we're building for
buildDir :: FilePath,
-- ^ Where to build the package.
--TODO: eliminate hugs's scratchDir, use builddir
@@ -400,6 +403,7 @@ absoluteInstallDirs pkg lbi copydest =
(packageId pkg)
(compilerId (compiler lbi))
copydest
+ (hostPlatform lbi)
(installDirTemplates lbi)
-- |See 'InstallDirs.prefixRelativeInstallDirs'
@@ -409,6 +413,7 @@ prefixRelativeInstallDirs pkg_descr lbi =
InstallDirs.prefixRelativeInstallDirs
(packageId pkg_descr)
(compilerId (compiler lbi))
+ (hostPlatform lbi)
(installDirTemplates lbi)
substPathTemplate :: PackageId -> LocalBuildInfo
@@ -418,3 +423,4 @@ substPathTemplate pkgid lbi = fromPathTemplate
where env = initialPathTemplateEnv
pkgid
(compilerId (compiler lbi))
+ (hostPlatform lbi)
View
6 Cabal/Distribution/Simple/NHC.hs
@@ -104,12 +104,13 @@ import Data.Maybe ( catMaybes )
import Data.Monoid ( Monoid(..) )
import Control.Monad ( when, unless )
import Distribution.Compat.Exception
+import Distribution.System ( Platform )
-- -----------------------------------------------------------------------------
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
- -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
+ -> ProgramConfiguration -> IO (Compiler, Maybe Platform, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(_nhcProg, nhcVersion, conf') <-
@@ -134,7 +135,8 @@ configure verbosity hcPath _hcPkgPath conf = do
compilerLanguages = nhcLanguages,
compilerExtensions = nhcLanguageExtensions
}
- return (comp, conf'''')
+ compPlatform = Nothing
+ return (comp, compPlatform, conf'''')
nhcLanguages :: [(Language, Flag)]
nhcLanguages = [(Haskell98, "-98")]
View
5 Cabal/Distribution/Simple/Test.hs
@@ -430,6 +430,7 @@ testSuiteLogPath template pkg_descr lbi testLog =
where
env = initialPathTemplateEnv
(PD.package pkg_descr) (compilerId $ LBI.compiler lbi)
+ (LBI.hostPlatform lbi)
++ [ (TestSuiteNameVar, toPathTemplate $ testSuiteName testLog)
, (TestSuiteResultVar, result)
]
@@ -446,7 +447,8 @@ testOption pkg_descr lbi suite template =
fromPathTemplate $ substPathTemplate env template
where
env = initialPathTemplateEnv
- (PD.package pkg_descr) (compilerId $ LBI.compiler lbi) ++
+ (PD.package pkg_descr) (compilerId $ LBI.compiler lbi)
+ (LBI.hostPlatform lbi) ++
[(TestSuiteNameVar, toPathTemplate $ PD.testName suite)]
packageLogPath :: PathTemplate
@@ -458,6 +460,7 @@ packageLogPath template pkg_descr lbi =
where
env = initialPathTemplateEnv
(PD.package pkg_descr) (compilerId $ LBI.compiler lbi)
+ (LBI.hostPlatform lbi)
-- | The filename of the source file for the stub executable associated with a
-- library 'TestSuite'.
View
12 Cabal/Distribution/Simple/UHC.hs
@@ -69,12 +69,13 @@ import Distribution.Version
import Language.Haskell.Extension
import System.Directory
import System.FilePath
+import Distribution.System ( Platform )
-- -----------------------------------------------------------------------------
-- Configuring
configure :: Verbosity -> Maybe FilePath -> Maybe FilePath
- -> ProgramConfiguration -> IO (Compiler, ProgramConfiguration)
+ -> ProgramConfiguration -> IO (Compiler, Maybe Platform, ProgramConfiguration)
configure verbosity hcPath _hcPkgPath conf = do
(_uhcProg, uhcVersion, conf') <-
@@ -83,11 +84,12 @@ configure verbosity hcPath _hcPkgPath conf = do
(userMaybeSpecifyPath "uhc" hcPath conf)
let comp = Compiler {
- compilerId = CompilerId UHC uhcVersion,
- compilerLanguages = uhcLanguages,
- compilerExtensions = uhcLanguageExtensions
+ compilerId = CompilerId UHC uhcVersion,
+ compilerLanguages = uhcLanguages,
+ compilerExtensions = uhcLanguageExtensions
}
- return (comp, conf')
+ compPlatform = Nothing
+ return (comp, compPlatform, conf')
uhcLanguages :: [(Language, C.Flag)]
uhcLanguages = [(Haskell98, "")]
View
22 Cabal/Distribution/System.hs
@@ -25,12 +25,13 @@ module Distribution.System (
-- * Platform is a pair of arch and OS
Platform(..),
buildPlatform,
+ platformFromTriple
) where
import qualified System.Info (os, arch)
import qualified Data.Char as Char (toLower, isAlphaNum)
-import Data.Maybe (fromMaybe)
+import Data.Maybe (fromMaybe, listToMaybe)
import Distribution.Text (Text(..), display)
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
@@ -59,10 +60,11 @@ data ClassificationStrictness = Permissive | Compat | Strict
-- * Operating System
-- ------------------------------------------------------------
-data OS = Linux | Windows | OSX -- teir 1 desktop OSs
+data OS = Linux | Windows | OSX -- tier 1 desktop OSs
| FreeBSD | OpenBSD | NetBSD -- other free unix OSs
| Solaris | AIX | HPUX | IRIX -- ageing Unix OSs
| HaLVM -- bare metal / VMs / hypervisors
+ | IOS -- iOS
| OtherOS String
deriving (Eq, Ord, Show, Read)
@@ -75,12 +77,14 @@ knownOSs :: [OS]
knownOSs = [Linux, Windows, OSX
,FreeBSD, OpenBSD, NetBSD
,Solaris, AIX, HPUX, IRIX
- ,HaLVM]
+ ,HaLVM
+ ,IOS]
osAliases :: ClassificationStrictness -> OS -> [String]
osAliases Permissive Windows = ["mingw32", "cygwin32"]
osAliases Compat Windows = ["mingw32", "win32"]
osAliases _ OSX = ["darwin"]
+osAliases _ IOS = ["ios"]
osAliases Permissive FreeBSD = ["kfreebsdgnu"]
osAliases Permissive Solaris = ["solaris2"]
osAliases _ _ = []
@@ -174,3 +178,15 @@ ident = Parse.munch1 (\c -> Char.isAlphaNum c || c == '_' || c == '-')
lowercase :: String -> String
lowercase = map Char.toLower
+
+platformFromTriple :: String -> Maybe Platform
+platformFromTriple triple = fmap fst (listToMaybe $ Parse.readP_to_S parseTriple triple)
+ where parseWord = Parse.munch1 (\c -> Char.isAlphaNum c || c == '_')
+ parseTriple = do
+ arch <- fmap (classifyArch Strict) parseWord
+ _ <- Parse.char '-'
+ _ <- parseWord -- Skip vendor
+ _ <- Parse.char '-'
+ os <- fmap (classifyOS Compat) ident -- OS may have hyphens, like 'nto-qnx'
+ return $ Platform arch os
+
View
5 cabal-install/Distribution/Client/BuildReports/Storage.hs
@@ -74,8 +74,8 @@ storeAnonymous reports = sequence_
[ (report, repo, remoteRepo)
| (report, repo@Repo { repoKind = Left remoteRepo }) <- rs ]
-storeLocal :: [PathTemplate] -> [(BuildReport, Repo)] -> IO ()
-storeLocal templates reports = sequence_
+storeLocal :: [PathTemplate] -> [(BuildReport, Repo)] -> Platform -> IO ()
+storeLocal templates reports platform = sequence_
[ do createDirectoryIfMissing True (takeDirectory file)
appendFile file output
--TODO: make this concurrency safe, either lock the report file or make
@@ -94,6 +94,7 @@ storeLocal templates reports = sequence_
where env = initialPathTemplateEnv
(BuildReport.package report)
(BuildReport.compiler report)
+ platform
groupByFileName = map (\grp@((filename,_):_) -> (filename, map snd grp))
. groupBy (equating fst)
View
12 cabal-install/Distribution/Client/Configure.hs
@@ -47,7 +47,7 @@ import Distribution.Version
import Distribution.Simple.Utils as Utils
( notice, info, debug, die )
import Distribution.System
- ( Platform, buildPlatform )
+ ( Platform )
import Distribution.Verbosity as Verbosity
( Verbosity )
@@ -58,18 +58,19 @@ configure :: Verbosity
-> PackageDBStack
-> [Repo]
-> Compiler
+ -> Platform
-> ProgramConfiguration
-> ConfigFlags
-> ConfigExFlags
-> [String]
-> IO ()
-configure verbosity packageDBs repos comp conf
+configure verbosity packageDBs repos comp platform conf
configFlags configExFlags extraArgs = do
installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
sourcePkgDb <- getSourcePackages verbosity repos
- progress <- planLocalPackage verbosity comp configFlags configExFlags
+ progress <- planLocalPackage verbosity comp platform configFlags configExFlags
installedPkgIndex sourcePkgDb
notice verbosity "Resolving dependencies..."
@@ -125,11 +126,12 @@ configure verbosity packageDBs repos comp conf
-- and all its dependencies.
--
planLocalPackage :: Verbosity -> Compiler
+ -> Platform
-> ConfigFlags -> ConfigExFlags
-> PackageIndex
-> SourcePackageDb
-> IO (Progress String String InstallPlan)
-planLocalPackage verbosity comp configFlags configExFlags installedPkgIndex
+planLocalPackage verbosity comp platform configFlags configExFlags installedPkgIndex
(SourcePackageDb _ packagePrefs) = do
pkg <- readPackageDescription verbosity =<< defaultPackageDesc verbosity
solver <- chooseSolver verbosity (fromFlag $ configSolver configExFlags) (compilerId comp)
@@ -177,7 +179,7 @@ planLocalPackage verbosity comp configFlags configExFlags installedPkgIndex
(SourcePackageDb mempty packagePrefs)
[SpecificSourcePackage localPkg]
- return (resolveDependencies buildPlatform (compilerId comp) solver resolverParams)
+ return (resolveDependencies platform (compilerId comp) solver resolverParams)
-- | Call an installer for an 'SourcePackage' but override the configure
View
20 cabal-install/Distribution/Client/Install.hs
@@ -604,7 +604,7 @@ postInstallActions verbosity
| UserTargetNamed dep <- targets ]
let buildReports = BuildReports.fromInstallPlan installPlan
- BuildReports.storeLocal (installSummaryFile installFlags) buildReports
+ BuildReports.storeLocal (installSummaryFile installFlags) buildReports (InstallPlan.planPlatform installPlan)
when (reportingLevel >= AnonymousReports) $
BuildReports.storeAnonymous buildReports
when (reportingLevel == DetailedReports) $
@@ -807,7 +807,7 @@ performInstallations verbosity
installUnpackedPackage verbosity buildLimit installLock numJobs
(setupScriptOptions installedPkgIndex cacheLock)
miscOptions configFlags' installFlags haddockFlags
- compid pkg pkgoverride mpath useLogFile
+ compid platform pkg pkgoverride mpath useLogFile
where
platform = InstallPlan.planPlatform installPlan
@@ -888,7 +888,7 @@ performInstallations verbosity
substLogFileName template pkg = fromPathTemplate
. substPathTemplate env
$ template
- where env = initialPathTemplateEnv (packageId pkg) (compilerId comp)
+ where env = initialPathTemplateEnv (packageId pkg) (compilerId comp) platform
miscOptions = InstallMisc {
rootCmd = if fromFlag (configUserInstall configFlags)
@@ -1072,6 +1072,7 @@ installUnpackedPackage
-> InstallFlags
-> HaddockFlags
-> CompilerId
+ -> Platform
-> PackageDescription
-> PackageDescriptionOverride
-> Maybe FilePath -- ^ Directory to change to before starting the installation.
@@ -1080,7 +1081,7 @@ installUnpackedPackage
installUnpackedPackage verbosity buildLimit installLock numJobs
scriptOptions miscOptions
configFlags installConfigFlags haddockFlags
- compid pkg pkgoverride workingDir useLogFile = do
+ compid platform pkg pkgoverride workingDir useLogFile = do
-- Override the .cabal file if necessary
case pkgoverride of
@@ -1123,7 +1124,7 @@ installUnpackedPackage verbosity buildLimit installLock numJobs
-- Install phase
onFailure InstallFailed $ criticalSection installLock $
- withWin32SelfUpgrade verbosity configFlags compid pkg $ do
+ withWin32SelfUpgrade verbosity configFlags compid platform pkg $ do
case rootCmd miscOptions of
(Just cmd) -> reexec cmd
Nothing -> setup Cabal.installCommand installFlags
@@ -1203,10 +1204,11 @@ onFailure result action =
withWin32SelfUpgrade :: Verbosity
-> ConfigFlags
-> CompilerId
+ -> Platform
-> PackageDescription
-> IO a -> IO a
-withWin32SelfUpgrade _ _ _ _ action | buildOS /= Windows = action
-withWin32SelfUpgrade verbosity configFlags compid pkg action = do
+withWin32SelfUpgrade _ _ _ _ _ action | buildOS /= Windows = action
@23Skidoo Collaborator
23Skidoo added a note

Shouldn't you replace the buildOS /= Windows check with platformOS platform /= Windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+withWin32SelfUpgrade verbosity configFlags compid platform pkg action = do
defaultDirs <- InstallDirs.defaultInstallDirs
compFlavor
@@ -1234,7 +1236,7 @@ withWin32SelfUpgrade verbosity configFlags compid pkg action = do
templateDirs = InstallDirs.combineInstallDirs fromFlagOrDefault
defaultDirs (configInstallDirs configFlags)
absoluteDirs = InstallDirs.absoluteInstallDirs
- pkgid compid InstallDirs.NoCopyDest templateDirs
+ pkgid compid InstallDirs.NoCopyDest platform templateDirs
substTemplate = InstallDirs.fromPathTemplate
. InstallDirs.substPathTemplate env
- where env = InstallDirs.initialPathTemplateEnv pkgid compid
+ where env = InstallDirs.initialPathTemplateEnv pkgid compid platform
View
4 cabal-install/Distribution/Client/InstallSymlink.hs
@@ -147,12 +147,12 @@ symlinkBinaries configFlags installFlags plan =
defaultDirs (configInstallDirs configFlags)
absoluteDirs = InstallDirs.absoluteInstallDirs
(packageId pkg) compilerId InstallDirs.NoCopyDest
- templateDirs
+ platform templateDirs
canonicalizePath (InstallDirs.bindir absoluteDirs)
substTemplate pkgid = InstallDirs.fromPathTemplate
. InstallDirs.substPathTemplate env
- where env = InstallDirs.initialPathTemplateEnv pkgid compilerId
+ where env = InstallDirs.initialPathTemplateEnv pkgid compilerId platform
fromFlagTemplate = fromFlagOrDefault (InstallDirs.toPathTemplate "")
prefixTemplate = fromFlagTemplate (configProgPrefix configFlags)
View
11 cabal-install/Distribution/Client/Sandbox.hs
@@ -59,6 +59,7 @@ import Distribution.Simple.Utils ( die, debug, notice, info
, createDirectoryIfMissingVerbose )
import Distribution.Verbosity ( Verbosity, lessVerbose )
import Distribution.Compat.Env ( lookupEnv, setEnv )
+import Distribution.System ( Platform )
import qualified Distribution.Client.Index as Index
import qualified Distribution.Simple.Register as Register
import Control.Exception ( bracket_ )
@@ -155,7 +156,7 @@ sandboxInit verbosity sandboxFlags globalFlags = do
-- Determine which compiler to use (using the value from ~/.cabal/config).
userConfig <- loadConfig verbosity (globalConfigFile globalFlags) NoFlag
- (comp, conf) <- configCompilerAux (savedConfigureFlags userConfig)
+ (comp, _, conf) <- configCompilerAux (savedConfigureFlags userConfig)
-- Create the package environment file.
pkgEnvDir <- getCurrentDirectory
@@ -208,7 +209,7 @@ sandboxConfigure verbosity
configFlags' = savedConfigureFlags config `mappend` configFlags
configExFlags' = savedConfigureExFlags config `mappend` configExFlags
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux configFlags'
+ (comp, platform, conf) <- configCompilerAux configFlags'
-- If the user has set the -w option, we may need to create the package DB for
-- this compiler.
@@ -218,7 +219,7 @@ sandboxConfigure verbosity
withSandboxBinDirOnSearchPath sandboxDir $
configure verbosity
(configPackageDB' configFlags'') (globalRepos globalFlags')
- comp conf configFlags'' configExFlags' extraArgs
+ comp platform conf configFlags'' configExFlags' extraArgs
-- | Entry point for the 'cabal sandbox-build' command.
sandboxBuild :: Verbosity -> SandboxFlags -> BuildFlags -> [String] -> IO ()
@@ -281,7 +282,7 @@ sandboxInstall verbosity _sandboxFlags configFlags configExFlags
installFlags' = defaultInstallFlags `mappend`
savedInstallFlags config `mappend` installFlags
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux' configFlags'
+ (comp, _, conf) <- configCompilerAux' configFlags'
-- If the user has set the -w option, we may need to create the package DB for
-- this compiler.
@@ -323,7 +324,7 @@ configPackageDB' cfg =
interpretPackageDbFlags {- userInstall = -} False (configPackageDBs cfg)
configCompilerAux' :: ConfigFlags
- -> IO (Compiler, ProgramConfiguration)
+ -> IO (Compiler, Platform, ProgramConfiguration)
configCompilerAux' configFlags =
configCompilerAux configFlags
--FIXME: make configCompilerAux use a sensible verbosity
View
5 cabal-install/Distribution/Client/SetupWrapper.hs
@@ -261,8 +261,9 @@ externalSetupMethod verbosity options pkg bt mkargs = do
configureCompiler options' = do
(comp, conf) <- case useCompiler options' of
Just comp -> return (comp, useProgramConfig options')
- Nothing -> configCompiler (Just GHC) Nothing Nothing
- (useProgramConfig options') verbosity
+ Nothing -> do (comp, _, conf) <- configCompiler (Just GHC) Nothing Nothing
+ (useProgramConfig options') verbosity
+ return (comp, conf)
return (comp, conf, options' { useCompiler = Just comp,
useProgramConfig = conf })
View
17 cabal-install/src/Main.hs
@@ -89,6 +89,7 @@ import Distribution.Simple.Configure
( checkPersistBuildConfigOutdated, configCompilerAux
, interpretPackageDbFlags, maybeGetPersistBuildConfig )
import qualified Distribution.Simple.LocalBuildInfo as LBI
+import Distribution.System ( Platform )
import Distribution.Simple.Utils
( cabalVersion, die, notice, topHandler )
import Distribution.Text
@@ -225,10 +226,10 @@ configureAction (configFlags, configExFlags) extraArgs globalFlags = do
let configFlags' = savedConfigureFlags config `mappend` configFlags
configExFlags' = savedConfigureExFlags config `mappend` configExFlags
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux configFlags'
+ (comp, platform, conf) <- configCompilerAux configFlags'
configure verbosity
(configPackageDB' configFlags') (globalRepos globalFlags')
- comp conf configFlags' configExFlags' extraArgs
+ comp platform conf configFlags' configExFlags' extraArgs
buildAction :: BuildFlags -> [String] -> GlobalFlags -> IO ()
buildAction buildFlags extraArgs globalFlags = do
@@ -395,7 +396,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags)
installFlags' = defaultInstallFlags `mappend`
savedInstallFlags config `mappend` installFlags
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux' configFlags'
+ (comp, _, conf) <- configCompilerAux' configFlags'
install verbosity
(configPackageDB' configFlags') (globalRepos globalFlags')
comp conf globalFlags' configFlags' configExFlags' installFlags' haddockFlags
@@ -441,7 +442,7 @@ listAction listFlags extraArgs globalFlags = do
config <- loadConfig verbosity (globalConfigFile globalFlags) mempty
let configFlags = savedConfigureFlags config
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux' configFlags
+ (comp, _, conf) <- configCompilerAux' configFlags
list verbosity
(configPackageDB' configFlags)
(globalRepos globalFlags')
@@ -457,7 +458,7 @@ infoAction infoFlags extraArgs globalFlags = do
config <- loadConfig verbosity (globalConfigFile globalFlags) mempty
let configFlags = savedConfigureFlags config
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux configFlags
+ (comp, _, conf) <- configCompilerAux configFlags
info verbosity
(configPackageDB' configFlags)
(globalRepos globalFlags')
@@ -498,7 +499,7 @@ fetchAction fetchFlags extraArgs globalFlags = do
config <- loadConfig verbosity (globalConfigFile globalFlags) mempty
let configFlags = savedConfigureFlags config
globalFlags' = savedGlobalFlags config `mappend` globalFlags
- (comp, conf) <- configCompilerAux' configFlags
+ (comp, _, conf) <- configCompilerAux' configFlags
fetch verbosity
(configPackageDB' configFlags) (globalRepos globalFlags')
comp conf globalFlags' fetchFlags
@@ -600,7 +601,7 @@ initAction initFlags _extraArgs globalFlags = do
let verbosity = fromFlag (initVerbosity initFlags)
config <- loadConfig verbosity (globalConfigFile globalFlags) mempty
let configFlags = savedConfigureFlags config
- (comp, conf) <- configCompilerAux' configFlags
+ (comp, _, conf) <- configCompilerAux' configFlags
initCabal verbosity
(configPackageDB' configFlags)
comp
@@ -689,7 +690,7 @@ configPackageDB' cfg =
userInstall = fromFlagOrDefault True (configUserInstall cfg)
configCompilerAux' :: ConfigFlags
- -> IO (Compiler, ProgramConfiguration)
+ -> IO (Compiler, Platform, ProgramConfiguration)
configCompilerAux' configFlags =
configCompilerAux configFlags
--FIXME: make configCompilerAux use a sensible verbosity
Something went wrong with that request. Please try again.