1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 21:01:35 +03:00
semantic/languages/ruby/Setup.hs

47 lines
1.7 KiB
Haskell
Raw Normal View History

2017-01-31 01:00:38 +03:00
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.Simple.Setup
import Distribution.Simple.Utils
2017-01-31 20:58:38 +03:00
import Distribution.Simple.LocalBuildInfo
import Data.Maybe
import System.Directory
2017-01-31 22:05:27 +03:00
import Distribution.System
2017-01-31 20:58:38 +03:00
import System.FilePath.Posix
main = defaultMainWithHooks simpleUserHooks {
2017-01-31 21:16:47 +03:00
preConf = makeScannerLib,
confHook = \a f -> confHook simpleUserHooks a f >>= updateExtraLibDirs,
postClean = cleanScannerLib
2017-01-31 20:58:38 +03:00
}
makeScannerLib :: Args -> ConfigFlags -> IO HookedBuildInfo
makeScannerLib _ flags = do
2017-01-31 21:16:47 +03:00
let verbosity = fromFlag $ configVerbosity flags
rawSystemExit verbosity "env" ["mkdir", "-p", "lib"]
let flag = if buildOS == OSX then "-std=c++11" else "-std=c++0x"
2017-01-31 23:16:20 +03:00
rawSystemExit verbosity "env" ["g++", flag, "-lstdc++", "-Ivendor/tree-sitter-ruby/src/", "-fPIC", "vendor/tree-sitter-ruby/src/scanner.cc", "-c", "-o", "lib/scanner.o"]
2017-01-31 21:16:47 +03:00
rawSystemExit verbosity "env" ["ar", "rcvs", "lib/libscanner.a", "lib/scanner.o"]
pure emptyHookedBuildInfo
2017-01-31 20:58:38 +03:00
updateExtraLibDirs :: LocalBuildInfo -> IO LocalBuildInfo
updateExtraLibDirs localBuildInfo = do
2017-01-31 21:16:47 +03:00
let packageDescription = localPkgDescr localBuildInfo
lib = fromJust $ library packageDescription
libBuild = libBuildInfo lib
dir <- getCurrentDirectory
pure localBuildInfo {
localPkgDescr = packageDescription {
library = Just $ lib {
libBuildInfo = libBuild {
extraLibDirs = (dir </> "lib") : extraLibDirs libBuild
2017-01-31 20:58:38 +03:00
}
2017-01-31 21:16:47 +03:00
}
}
}
cleanScannerLib :: Args -> CleanFlags -> PackageDescription -> () -> IO ()
cleanScannerLib _ flags _ _ = do
let verbosity = fromFlag $ cleanVerbosity flags
dir <- getCurrentDirectory
2017-01-31 21:26:58 +03:00
rawSystemExit verbosity "env" ["rm", "-rf", dir </> "lib"]