Skip to content

Commit

Permalink
Fix build process for Stack 1.4 & Cabal 1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubfijalkowski committed Mar 19, 2017
1 parent 00946c9 commit 9a74cb4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.1.5.2] - 2017-03-19
### Fixed
- Build process for dependant libraries works with Cabal 1.24 & Stack 1.4

## [0.1.5.0] - 2015-12-19
### Added
- Bindings to `sass_value_op`, `sass_import_get_imp_path` and
Expand Down Expand Up @@ -59,6 +63,7 @@ All notable changes to this project will be documented in this file.
- Bindings to Libsass C API
- Basic tests

[0.1.5.2]: https://github.com/jakubfijalkowski/hlibsass/compare/v0.1.5.0...v0.1.5.2
[0.1.5.0]: https://github.com/jakubfijalkowski/hlibsass/compare/v0.1.4.0...v0.1.5.0
[0.1.4.0]: https://github.com/jakubfijalkowski/hlibsass/compare/v0.1.3.0...v0.1.4.0
[0.1.3.0]: https://github.com/jakubfijalkowski/hlibsass/compare/v0.1.2.1...v0.1.3.0
Expand Down
82 changes: 42 additions & 40 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,65 @@ import System.Directory (getCurrentDirectory)
main = defaultMainWithHooks hooksFix
where
hooks = simpleUserHooks {
preConf = \a f -> makeLibsass a f >> preConf simpleUserHooks a f
, confHook = \a f -> confHook simpleUserHooks a f >>= updateExtraLibDirs
preConf = makeLibsass
, confHook = (\a f -> confHook simpleUserHooks a f >>= updateExtraLibDirs)
, postConf = disablePostConfHooks
, preBuild = updateLibDirs
, postCopy = copyLibsass
, postClean = cleanLibsass
, preSDist = \a f -> (updateLibsassVersion a f >> preSDist simpleUserHooks a f)
, preSDist = updateLibsassVersion
}
-- Fix for Cabal-1.18 - it does not `copy` on `install`, so we `copy` on
-- `install` manually. ;)
hooksFix = if cabalVersion < Version [1, 20, 0] []
then hooks { postInst = installLibsass }
else hooks

makeLibsass :: Args -> ConfigFlags -> IO ()
makeLibsass _ f =
makeLibsass :: Args -> ConfigFlags -> IO HookedBuildInfo
makeLibsass _ f = do
let verbosity = fromFlag $ configVerbosity f
external = getCabalFlag "externalLibsass" f
target = if getCabalFlag "sharedLibsass" f then "shared" else "static"
in unless external $ rawSystemExit verbosity "env"
unless external $ rawSystemExit verbosity "env"
["BUILD=" ++ target, "make", "--directory=libsass"]
return emptyHookedBuildInfo

disablePostConfHooks :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
disablePostConfHooks args flags pd lbi
| getCabalFlag "externalLibsass" flags = postConf simpleUserHooks args flags pd lbi
| otherwise = return ()

updateLibDirs :: Args -> BuildFlags -> IO HookedBuildInfo
updateLibDirs _ _ = do
dir <- getCurrentDirectory
let libsassDir = dir ++ "/libsass/lib"
bi = emptyBuildInfo { extraLibDirs = [ libsassDir ] }
return (Just bi, [])

updateExtraLibDirs :: LocalBuildInfo -> IO LocalBuildInfo
updateExtraLibDirs lbi
| getCabalFlag "externalLibsass" $ configFlags lbi = return lbi
| otherwise = do
let packageDescription = localPkgDescr lbi
lib = fromJust $ library packageDescription
let pkg_descr = localPkgDescr lbi
lib = fromJust $ library pkg_descr
libBuild = libBuildInfo lib
dir <- getCurrentDirectory
libPref = libdir $ absoluteInstallDirs pkg_descr lbi NoCopyDest
return lbi {
localPkgDescr = packageDescription {
localPkgDescr = pkg_descr {
library = Just $ lib {
libBuildInfo = libBuild {
extraLibDirs = (dir ++ "/libsass/lib") :
extraLibDirs libBuild
extraLibDirs = libPref : extraLibDirs libBuild
}
}
}
}

copyLibsass :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
copyLibsass _ flags pkg_descr lbi =
let libPref = libdir . absoluteInstallDirs pkg_descr lbi
. fromFlag . copyDest
$ flags
verb = fromFlag $ copyVerbosity flags
config = configFlags lbi
external = getCabalFlag "externalLibsass" config
copyLib :: ConfigFlags -> LocalBuildInfo -> FilePath -> IO ()
copyLib fl lbi libPref =
let verb = fromFlag $ configVerbosity fl
external = getCabalFlag "externalLibsass" fl
Platform _ os = hostPlatform lbi
shared = getCabalFlag "sharedLibsass" config
shared = getCabalFlag "sharedLibsass" fl
ext = if shared then "so" else "a"
in unless external $
if os == Windows
Expand All @@ -82,40 +92,32 @@ copyLibsass _ flags pkg_descr lbi =
("libsass/lib/libsass." ++ ext)
(libPref ++ "/libsass." ++ ext)

copyLibsass :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
copyLibsass _ flags pkg_descr lbi =
let libPref = libdir . absoluteInstallDirs pkg_descr lbi
. fromFlag . copyDest
$ flags
config = configFlags lbi
in copyLib config lbi libPref

installLibsass :: Args -> InstallFlags -> PackageDescription -> LocalBuildInfo -> IO ()
installLibsass _ flags pkg_descr lbi =
let libPref = libdir $ absoluteInstallDirs pkg_descr lbi NoCopyDest
verb = fromFlag $ installVerbosity flags
config = configFlags lbi
external = getCabalFlag "externalLibsass" config
Platform _ os = hostPlatform lbi
shared = getCabalFlag "sharedLibsass" config
ext = if shared then "so" else "a"
in unless external $
if os == Windows
then do
installExecutableFile verb
"libsass/lib/libsass.a"
(libPref ++ "/libsass.a")
when shared $ installExecutableFile verb
"libsass/lib/libsass.dll"
(libPref ++ "/libsass.dll")
else
installExecutableFile verb
("libsass/lib/libsass." ++ ext)
(libPref ++ "/libsass." ++ ext)
in copyLib config lbi libPref

cleanLibsass :: Args -> CleanFlags -> PackageDescription -> () -> IO ()
cleanLibsass _ flags _ _ =
rawSystemExit (fromFlag $ cleanVerbosity flags) "env"
["make", "--directory=libsass", "clean"]

updateLibsassVersion :: Args -> SDistFlags -> IO ()
updateLibsassVersion :: Args -> SDistFlags -> IO HookedBuildInfo
updateLibsassVersion _ flags = do
let verbosity = fromFlag $ sDistVerbosity flags
ver <- rawSystemStdout verbosity "env" [ "git", "-C", "libsass", "describe",
"--abbrev=4", "--dirty", "--always", "--tags" ]
writeFile "libsass/VERSION" ver
return emptyHookedBuildInfo

getCabalFlag :: String -> ConfigFlags -> Bool
getCabalFlag name flags = fromMaybe False (lookup (FlagName name') allFlags)
Expand Down
2 changes: 1 addition & 1 deletion hlibsass.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: hlibsass
version: 0.1.5.1
version: 0.1.5.2
license: MIT
license-file: LICENSE
author: Jakub Fijałkowski <[email protected]>
Expand Down

0 comments on commit 9a74cb4

Please sign in to comment.