<commit_before>import Control.Monad (mapM_, when)
import Data.List (foldl', intersperse, intercalate, nub, lookup, isPrefixOf)
import Data.Maybe (fromJust)
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.InstallDirs (InstallDirs(..))
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo, localPkgDescr, installedPkgs, withPrograms, buildDir, absoluteInstallDirs)
import Distribution.Simple.PackageIndex(SearchResult (..), searchByName )
import Distribution.Simple.Program (ConfiguredProgram (..), lookupProgram, runProgram, simpleProgram, locationPath)
import Distribution.Simple.Setup (ConfigFlags, BuildFlags, InstallFlags, CopyDest(..), fromFlag, installVerbosity)
import Distribution.Simple.Utils (installOrdinaryFile)
import Distribution.System (OS (..), Arch (..), buildOS, buildArch)
import Distribution.Verbosity (normal, verbose)
import System.Cmd (system)
import System.Directory (createDirectoryIfMissing, doesFileExist, getCurrentDirectory, getModificationTime)
import System.Environment (getEnv)
import System.Exit (ExitCode (..))
import System.FilePath.Posix ((</>), (<.>), replaceExtension, takeFileName, dropFileName, addExtension)
import System.IO.Unsafe (unsafePerformIO)
import System.Process (readProcess)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

main :: IO ()
main = defaultMainWithHooks simpleUserHooks { confHook = myConfHook, buildHook = myBuildHook, instHook = myInstHook }

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

sourceDirectory  :: FilePath
includeDirectory :: FilePath

sourceDirectory  = "cpp"
includeDirectory = "include"

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- Comment out type signature because of a Cabal API change from 1.6 to 1.7
myConfHook (pkg0, pbi) flags = do

    lbi <- confHook simpleUserHooks (pkg0, pbi) flags
    let lpd       = localPkgDescr lbi
    let lib       = fromJust (library lpd)
    let libbi     = libBuildInfo lib
    let custom_bi = customFieldsBI libbi

    wx <- fmap parseWxConfig readWxConfig

    let libbi' = libbi
          { extraLibDirs = extraLibDirs libbi ++ extraLibDirs wx
          , extraLibs    = extraLibs    libbi ++ reverse (extraLibs    wx)
          , ldOptions    = ldOptions    libbi ++ ldOptions    wx
          , frameworks   = frameworks   libbi ++ frameworks   wx
          , includeDirs  = includeDirs  libbi ++ includeDirs  wx
          , ccOptions    = ccOptions    libbi ++ ccOptions    wx ++ ["-DwxcREFUSE_MEDIACTRL"]
          }

    let lib' = lib { libBuildInfo = libbi' }
    let lpd' = lpd { library = Just lib' }

    return $ lbi { localPkgDescr = lpd' }

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- Make sure the right version of wx widgets is installed and return the 
readWxConfig :: IO String
readWxConfig = do
    -- Try to force version and see if we have it
    let wxRequiredVersion = "2.9"

    -- The Windows port of wx-config doesn't let you specify a version, nor query the full version,
    -- accordingly we just check what version is installed (which is returned with --release)
    wxVersion <- case buildOS of
      Windows -> readProcess "wx-config" ["--release"] ""
      _       -> readProcess "wx-config" ["--version=" ++ wxRequiredVersion, "--version-full"] ""

    if wxRequiredVersion `isPrefixOf` wxVersion 
      then putStrLn ("Configuring wxc to build against wx " ++ wxVersion)
      else error ("This version of wxcore requires wx " ++ wxRequiredVersion ++ " to be available")

    -- The Windows port of wx-config doesn't let you specify a version (yet)
    output <- case buildOS of
      -- TODO: Nasty Windows hack: wx-config-win barfs if --cppflags comes after --libs :-(
      Windows -> readProcess "wx-config" ["--cppflags", "--libs", "all"] ""
      _       -> readProcess "wx-config" ["--version=" ++ wxRequiredVersion, "--libs", "all", "--cppflags"] ""
    return output

parseWxConfig :: String -> BuildInfo
parseWxConfig s =
    helper emptyBuildInfo (words s)
  where
    helper b ("-framework":w:ws) = helper (b { frameworks = w : frameworks b }) ws
    helper b (w:ws)              = helper (f b w) ws
    helper b []                  = b
    f b w =
        case w of
          ('-':'L':v) -> b { extraLibDirs = v : extraLibDirs b }
          ('-':'l':v) -> b { extraLibs    = v : extraLibs b }
          ('-':'I':v) -> b { includeDirs  = v : includeDirs b }
          ('-':'D':_) -> b { ccOptions    = w : ccOptions b }
          _           -> b

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- | Extend the standard build hook to build a shared library for wxc - this will statically link<commit_msg>Fix minor typos in error message when required wxWidgets version is not available. Issue reported by <NAME> (<EMAIL>)<commit_after>import Control.Monad (mapM_, when)
import Data.List (foldl', intersperse, intercalate, nub, lookup, isPrefixOf)
import Data.Maybe (fromJust)
import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.InstallDirs (InstallDirs(..))
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo, localPkgDescr, installedPkgs, withPrograms, buildDir, absoluteInstallDirs)
import Distribution.Simple.PackageIndex(SearchResult (..), searchByName )
import Distribution.Simple.Program (ConfiguredProgram (..), lookupProgram, runProgram, simpleProgram, locationPath)
import Distribution.Simple.Setup (ConfigFlags, BuildFlags, InstallFlags, CopyDest(..), fromFlag, installVerbosity)
import Distribution.Simple.Utils (installOrdinaryFile)
import Distribution.System (OS (..), Arch (..), buildOS, buildArch)
import Distribution.Verbosity (normal, verbose)
import System.Cmd (system)
import System.Directory (createDirectoryIfMissing, doesFileExist, getCurrentDirectory, getModificationTime)
import System.Environment (getEnv)
import System.Exit (ExitCode (..))
import System.FilePath.Posix ((</>), (<.>), replaceExtension, takeFileName, dropFileName, addExtension)
import System.IO.Unsafe (unsafePerformIO)
import System.Process (readProcess)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

main :: IO ()
main = defaultMainWithHooks simpleUserHooks { confHook = myConfHook, buildHook = myBuildHook, instHook = myInstHook }

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

sourceDirectory  :: FilePath
includeDirectory :: FilePath

sourceDirectory  = "cpp"
includeDirectory = "include"

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- Comment out type signature because of a Cabal API change from 1.6 to 1.7
myConfHook (pkg0, pbi) flags = do

    lbi <- confHook simpleUserHooks (pkg0, pbi) flags
    let lpd       = localPkgDescr lbi
    let lib       = fromJust (library lpd)
    let libbi     = libBuildInfo lib
    let custom_bi = customFieldsBI libbi

    wx <- fmap parseWxConfig readWxConfig

    let libbi' = libbi
          { extraLibDirs = extraLibDirs libbi ++ extraLibDirs wx
          , extraLibs    = extraLibs    libbi ++ reverse (extraLibs    wx)
          , ldOptions    = ldOptions    libbi ++ ldOptions    wx
          , frameworks   = frameworks   libbi ++ frameworks   wx
          , includeDirs  = includeDirs  libbi ++ includeDirs  wx
          , ccOptions    = ccOptions    libbi ++ ccOptions    wx ++ ["-DwxcREFUSE_MEDIACTRL"]
          }

    let lib' = lib { libBuildInfo = libbi' }
    let lpd' = lpd { library = Just lib' }

    return $ lbi { localPkgDescr = lpd' }

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- Make sure the right version of wx widgets is installed and return the 
readWxConfig :: IO String
readWxConfig = do
    -- Try to force version and see if we have it
    let wxRequiredVersion = "2.9"

    -- The Windows port of wx-config doesn't let you specify a version, nor query the full version,
    -- accordingly we just check what version is installed (which is returned with --release)
    wxVersion <- case buildOS of
      Windows -> readProcess "wx-config" ["--release"] ""
      _       -> readProcess "wx-config" ["--version=" ++ wxRequiredVersion, "--version-full"] ""

    if wxRequiredVersion `isPrefixOf` wxVersion 
      then putStrLn ("Configuring wxc to build against wxWidgets " ++ wxVersion)
      else error ("This version of wxc requires wxWidgets " ++ wxRequiredVersion ++ " to be available")

    -- The Windows port of wx-config doesn't let you specify a version (yet)
    output <- case buildOS of
      -- TODO: Nasty Windows hack: wx-config-win barfs if --cppflags comes after --libs :-(
      Windows -> readProcess "wx-config" ["--cppflags", "--libs", "all"] ""
      _       -> readProcess "wx-config" ["--version=" ++ wxRequiredVersion, "--libs", "all", "--cppflags"] ""
    return output

parseWxConfig :: String -> BuildInfo
parseWxConfig s =
    helper emptyBuildInfo (words s)
  where
    helper b ("-framework":w:ws) = helper (b { frameworks = w : frameworks b }) ws
    helper b (w:ws)              = helper (f b w) ws
    helper b []                  = b
    f b w =
        case w of
          ('-':'L':v) -> b { extraLibDirs = v : extraLibDirs b }
          ('-':'l':v) -> b { extraLibs    = v : extraLibs b }
          ('-':'I':v) -> b { includeDirs  = v : includeDirs b }
          ('-':'D':_) -> b { ccOptions    = w : ccOptions b }
          _           -> b

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- | Extend the standard build hook to build a shared library for wxc - this will statically link
{'fraction_non_alphanumeric': 0.14381762790209054, 'fraction_numerical': 0.0016808488286584725, 'mean_word_length': 2.458045768252815, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6761427', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2762, 'n_words': 858}