<commit_before>
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Main (main) where

import ClientMonad

import Builder.Command
import Builder.Files
import Builder.Handlelike
import Builder.Utils

import Control.Concurrent
import Control.Exception
import Control.Monad.State
import Network.Socket
import OpenSSL
import OpenSSL.Session
import OpenSSL.X509
import Prelude hiding (catch)
import System.Directory
import System.Environment
import System.Exit
import System.FilePath
import System.IO
import System.IO.Error hiding (catch)
#ifdef HAVE_SYSTEM_POSIX_RESOURCE
import System.Posix.Resource
#endif

baseSubDir :: FilePath
baseSubDir = "builder"

getTempBuildDir :: ClientMonad FilePath
getTempBuildDir = do dir <- getBaseDir
                     return (dir </> "tempbuild")

getBuildResultFile :: BuildNum -> ClientMonad FilePath
getBuildResultFile bn = do dir <- getBaseDir
                           return (dir </> "builds" </> show bn </> "result")

main :: IO ()
main = do hSetBuffering stdout LineBuffering
          hSetBuffering stderr LineBuffering
#ifdef HAVE_SYSTEM_POSIX_RESOURCE
          -- We should really have different limits for different
          -- clients, but for now we just use the same value everywhere
          let memLimit = 1000000000 -- 1G
          rls <- getResourceLimit ResourceTotalMemory
          case softLimit rls of
              ResourceLimit l
               | l <= memLimit ->
                  return ()
              _ ->
                  setResourceLimit ResourceTotalMemory
                                   (rls {softLimit = ResourceLimit memLimit})
#endif
          unless rtsSupportsBoundThreads $ die "Not linked with -threaded"
          args <- getArgs
          case args of
              []       -> withSocketsDo $ withOpenSSL $ runClient Normal  mainLoop
              ["-v"]   -> withSocketsDo $ withOpenSSL $ runClient Verbose mainLoop
              ["--do-build"] -> withSocketsDo $ withOpenSSL $ runClient Verbose (doABuild (StartBuild (Other "manual")))
              -- XXX user and pass oughtn't really be given on the
              -- commandline, but hey<commit_msg>When doing a single build, exit after the first build is done<commit_after>
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Main (main) where

import ClientMonad

import Builder.Command
import Builder.Files
import Builder.Handlelike
import Builder.Utils

import Control.Concurrent
import Control.Exception
import Control.Monad.State
import Network.Socket
import OpenSSL
import OpenSSL.Session
import OpenSSL.X509
import Prelude hiding (catch)
import System.Directory
import System.Environment
import System.Exit
import System.FilePath
import System.IO
import System.IO.Error hiding (catch)
#ifdef HAVE_SYSTEM_POSIX_RESOURCE
import System.Posix.Resource
#endif

baseSubDir :: FilePath
baseSubDir = "builder"

getTempBuildDir :: ClientMonad FilePath
getTempBuildDir = do dir <- getBaseDir
                     return (dir </> "tempbuild")

getBuildResultFile :: BuildNum -> ClientMonad FilePath
getBuildResultFile bn = do dir <- getBaseDir
                           return (dir </> "builds" </> show bn </> "result")

main :: IO ()
main = do hSetBuffering stdout LineBuffering
          hSetBuffering stderr LineBuffering
#ifdef HAVE_SYSTEM_POSIX_RESOURCE
          -- We should really have different limits for different
          -- clients, but for now we just use the same value everywhere
          let memLimit = 1000000000 -- 1G
          rls <- getResourceLimit ResourceTotalMemory
          case softLimit rls of
              ResourceLimit l
               | l <= memLimit ->
                  return ()
              _ ->
                  setResourceLimit ResourceTotalMemory
                                   (rls {softLimit = ResourceLimit memLimit})
#endif
          unless rtsSupportsBoundThreads $ die "Not linked with -threaded"
          args <- getArgs
          case args of
              []       -> withSocketsDo $ withOpenSSL $ runClient Normal  mainLoop
              ["-v"]   -> withSocketsDo $ withOpenSSL $ runClient Verbose mainLoop
              ["--do-build"] -> withSocketsDo $ withOpenSSL $ runClient Verbose (doABuild (StartBuild (Other "manual")) >> liftIO exitSuccess)
              -- XXX user and pass oughtn't really be given on the
              -- commandline, but hey
{'fraction_non_alphanumeric': 0.0709366391184573, 'fraction_numerical': 0.006427915518824609, 'mean_word_length': 2.4995983935742974, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5168760', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1119, 'n_words': 376}