<commit_before>-- Returns exitcode 0 if the given package is buildable or is a boot package,
-- and 1 otherwise.

module Main (main) where

import Control.Monad
import System.Directory
import System.Environment
import System.Exit
import System.IO

main :: IO ()
main = do args <- getArgs
          case args of
              [packagesFile, package] ->
                  doit packagesFile package
              _ ->
                  error "Syntax: ifBuildable <packages-file> <package>"

doit :: FilePath -> String -> IO ()
doit packagesFile package
 = do setCurrentDirectory package
      unbuildable <- doesFileExist "unbuildable"
      if not unbuildable
         then exitWith ExitSuccess
         else do mustBeBuildables <- getMustBeBuildables packagesFile
                 if package `elem` mustBeBuildables
                     then exitWith ExitSuccess
                     else do hPutStrLn stderr "Warning: Package is unbuildable"
                             exitWith (ExitFailure 1)

getMustBeBuildables :: FilePath -> IO [String]
getMustBeBuildables packagesFile
 = do xs <- readFile packagesFile
      let nonCommentLines = filter (("#" /=) . take 1) $ lines xs
          requiredLines = filter ((2 == ) . length) $ map words nonCommentLines
          requiredLibraries = [ x | 'l':'i':'b':'r':'a':'r':'i':'e':'s':'/':x
                                    <- map head requiredLines ]
      return $ filter ("editline" /=) requiredLibraries<commit_msg>Fix ifBuildable Required libraries now have 3 fields in the packages file, not 2<commit_after>-- Returns exitcode 0 if the given package is buildable or is a boot package,
-- and 1 otherwise.

module Main (main) where

import Control.Monad
import System.Directory
import System.Environment
import System.Exit
import System.IO

main :: IO ()
main = do args <- getArgs
          case args of
              [packagesFile, package] ->
                  doit packagesFile package
              _ ->
                  error "Syntax: ifBuildable <packages-file> <package>"

doit :: FilePath -> String -> IO ()
doit packagesFile package
 = do setCurrentDirectory package
      unbuildable <- doesFileExist "unbuildable"
      if not unbuildable
         then exitWith ExitSuccess
         else do mustBeBuildables <- getMustBeBuildables packagesFile
                 if package `elem` mustBeBuildables
                     then exitWith ExitSuccess
                     else do hPutStrLn stderr "Warning: Package is unbuildable"
                             exitWith (ExitFailure 1)

getMustBeBuildables :: FilePath -> IO [String]
getMustBeBuildables packagesFile
 = do xs <- readFile packagesFile
      let nonCommentLines = filter (("#" /=) . take 1) $ lines xs
          requiredLines = filter ((3 == ) . length) $ map words nonCommentLines
          requiredLibraries = [ x | 'l':'i':'b':'r':'a':'r':'i':'e':'s':'/':x
                                    <- map head requiredLines ]
      return $ filter ("editline" /=) requiredLibraries
{'fraction_non_alphanumeric': 0.08969656552184062, 'fraction_numerical': 0.0040013337779259755, 'mean_word_length': 2.2467532467532467, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '4858728', 'n_tokens_mistral': 807, 'n_tokens_neox': 752, 'n_words': 266}