Skip to content

Commit

Permalink
More edge-case fixes.
Browse files Browse the repository at this point in the history
- Fix the `xhtml` package by doing a better job filtering out built-in
  packages that aren't in the build plan.
- Fix `Paths_` modules for packages with dashes in their name.  (Unit testing
  deferred to #54.)
  • Loading branch information
judah committed Feb 3, 2018
1 parent 63d26c1 commit b1b8c21
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- run: weeder . --build

# Run pier on some sample packages
- run: $(stack exec which pier) build lens pandoc c2hs unix-time pier -j4
- run: $(stack exec which pier) build lens pandoc c2hs unix-time xhtml pier -j4
- run: $(stack exec which pier) run -j4 hlint --sandbox $PWD/src
- run: $(stack exec which pier) run hlint src

Expand Down
3 changes: 2 additions & 1 deletion src/Pier/Build/Components.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,11 @@ buildExecutable confd exe = do
datas
}
where
pathsMod = fromString $ "Paths_" ++ display (packageName confd)
pathsMod = fromString $ "Paths_" ++ fixDashes (display $ packageName confd)
addIfMissing m ms
| m `elem` ms = ms
| otherwise = m : ms
fixDashes = map $ \c -> if c == '-' then '_' else c


-- TODO: issue if this doesn't preserve ".lhs" vs ".hs", for example?
Expand Down
2 changes: 1 addition & 1 deletion src/Pier/Build/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ askConfig :: Action Config
askConfig = do
yaml <- askPersistent PierYamlQ
p <- askBuildPlan (resolver yaml)
ghc <- askInstalledGhc (ghcVersion p)
ghc <- askInstalledGhc p
-- TODO: don't parse local package defs twice.
-- We do it again later so the full PackageDescription
-- doesn't need to get saved in the cache.
Expand Down
3 changes: 2 additions & 1 deletion src/Pier/Build/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ getPackageSourceDir :: PackageIdentifier -> Action Artifact
getPackageSourceDir pkg = do
tarball <- downloadCabalPackage pkg
runCommand (output outDir)
$ prog "tar" ["-xzf", pathIn tarball, "-C", pathOut (takeDirectory outDir)]
$ message ("Unpacking " ++ display pkg)
<> prog "tar" ["-xzf", pathIn tarball, "-C", pathOut (takeDirectory outDir)]
<> input tarball
where
outDir = "package/raw" </> display pkg
Expand Down
28 changes: 17 additions & 11 deletions src/Pier/Build/Stackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ askBuildPlan :: PlanName -> Action BuildPlan
askBuildPlan = askPersistent . ReadPlan


newtype InstallGhc = InstallGhc Version
data InstallGhc = InstallGhc Version [PackageName]
deriving (Show, Typeable, Eq, Hashable, Binary, NFData, Generic)

-- | TODO: make the below functions that use Version take InstalledGhc directly instead
Expand All @@ -127,8 +127,10 @@ packageConfD = "package.conf.d"
ghcArtifacts :: InstalledGhc -> Set.Set Artifact
ghcArtifacts g = Set.fromList [ghcInstallDir g, globalPackageDb g]

askInstalledGhc :: Version -> Action InstalledGhc
askInstalledGhc = askPersistent . InstallGhc
askInstalledGhc :: BuildPlan -> Action InstalledGhc
askInstalledGhc plan
= askPersistent $ InstallGhc (ghcVersion plan)
$ HM.keys $ corePackageVersions plan

ghcLibRoot :: InstalledGhc -> Artifact
ghcLibRoot g = ghcLibRootA (ghcInstalledVersion g) (ghcInstallDir g)
Expand Down Expand Up @@ -179,7 +181,7 @@ hsc2hsProg ghc args =
template = ghcLibRoot ghc /> "template-hsc.h"

installGhcRules :: Rules ()
installGhcRules = addPersistent $ \(InstallGhc version) -> do
installGhcRules = addPersistent $ \(InstallGhc version corePkgs) -> do
setupYaml <- askDownload Download
{ downloadFilePrefix = "stackage/setup"
, downloadName = "stack-setup-2.yaml"
Expand All @@ -191,7 +193,7 @@ installGhcRules = addPersistent $ \(InstallGhc version) -> do
Left err -> throw err
Right x
| Just download <- HM.lookup version (ghcVersions x)
-> downloadAndInstallGHC version download
-> downloadAndInstallGHC version corePkgs download
| otherwise -> error $ "Couldn't find GHC version" ++ Cabal.display version
where
setupUrl = "https://raw.githubusercontent.com/fpco/stackage-content/master/stack"
Expand Down Expand Up @@ -237,8 +239,9 @@ platformKey = case buildPlatform of
_ -> error $ "Unrecognized platform: " ++ Cabal.display buildPlatform


downloadAndInstallGHC :: Version -> DownloadInfo -> Action InstalledGhc
downloadAndInstallGHC version download = do
downloadAndInstallGHC
:: Version -> [PackageName] -> DownloadInfo -> Action InstalledGhc
downloadAndInstallGHC version corePkgs download = do
-- TODO: reenable this once we've fixed the issue with nondetermistic
-- temp file locations.
-- rerunIfCleaned
Expand All @@ -264,20 +267,23 @@ downloadAndInstallGHC version download = do
<> progTemp (unpackedDir </> "configure")
["--prefix=${TMPDIR}/" ++ pathOut installDir]
<> prog "make" ["install"])
fixed <- makeRelativeGlobalDb
fixed <- makeRelativeGlobalDb corePkgs
InstalledGhc { ghcInstallDir = installed
, ghcInstalledVersion = version
}
runCommand_ $ ghcPkgProg fixed ["check"]
return fixed

makeRelativeGlobalDb :: InstalledGhc -> Action InstalledGhc
makeRelativeGlobalDb ghc = do
makeRelativeGlobalDb :: [PackageName] -> InstalledGhc -> Action InstalledGhc
makeRelativeGlobalDb corePkgs ghc = do
let corePkgsSet = Set.fromList corePkgs
-- List all packages, excluding Cabal which stack doesn't consider a "core"
-- package.
-- TODO: if our package ids included a hash, this wouldn't be as big a problem
-- because two versions of the same package could exist simultaneously.
builtinPackages <- fmap (filter (/= "Cabal") . words) $ runCommandStdout
builtinPackages <- fmap (filter ((`Set.member` corePkgsSet) . mkPackageName)
. words)
. runCommandStdout
$ ghcPkgProg ghc
["list", "--global", "--names-only",
"--simple-output" ]
Expand Down

0 comments on commit b1b8c21

Please sign in to comment.