<commit_before>{-# LANGUAGE MultiParamTypeClasses, GeneralizedNewtypeDeriving, DeriveDataTypeable #-}

-- | These are the additional rule types required by Makefile
module Development.Make.Rules(
    need_, want_,
    defaultRuleFile_,
    (??>)
    ) where

import Control.Monad
import Control.Monad.IO.Class
import System.Directory

import Development.Shake.Core
import Development.Shake.Types
import Development.Shake.Classes
import Development.Shake.FilePath
import Development.Shake.FileTime

infix 1 ??>

---------------------------------------------------------------------
-- FILE_ RULES
-- These are like file rules, but a rule may not bother creating the result
-- Which matches the (insane) semantics of make
-- If a file is not produced, it will rebuild forever

newtype File_Q = File_Q BS
    deriving (Typeable,Eq,Hashable,Binary,NFData)

instance Show File_Q where show (File_Q x) = unpack x

newtype File_A = File_A (Maybe FileTime)
    deriving (Typeable,Eq,Hashable,Binary,Show,NFData)

instance Rule File_Q File_A where
    storedValue (File_Q x) = fmap (fmap (File_A . Just)) $ getModTimeMaybe $ unpack_ x


defaultRuleFile_ :: Rules ()
defaultRuleFile_ = defaultRule $ \(File_Q x) -> Just $
    liftIO $ fmap (File_A . Just) $ getModTimeError "Error, file does not exist and no rule available:" $ unpack_ x


need_ :: [FilePath] -> Action ()
need_ xs = (apply $ map (File_Q . pack) xs :: Action [File_A]) >> return ()

want_ :: [FilePath] -> Rules ()
want_ = action . need_


(??>) :: (FilePath -> Bool) -> (FilePath -> Action ()) -> Rules ()
(??>) test act = rule $ \(File_Q x_) -> let x = unpack x_ in
    if not $ test x then Nothing else Just $ do
        liftIO $ createDirectoryIfMissing True $ takeDirectory x
        act x
        liftIO $ fmap File_A $ getModTimeMaybe $ unpack_ x_
<commit_msg>Makefile, delete a redundant import<commit_after>{-# LANGUAGE MultiParamTypeClasses, GeneralizedNewtypeDeriving, DeriveDataTypeable #-}

-- | These are the additional rule types required by Makefile
module Development.Make.Rules(
    need_, want_,
    defaultRuleFile_,
    (??>)
    ) where

import Control.Monad.IO.Class
import System.Directory

import Development.Shake.Core
import Development.Shake.Types
import Development.Shake.Classes
import Development.Shake.FilePath
import Development.Shake.FileTime

infix 1 ??>

---------------------------------------------------------------------
-- FILE_ RULES
-- These are like file rules, but a rule may not bother creating the result
-- Which matches the (insane) semantics of make
-- If a file is not produced, it will rebuild forever

newtype File_Q = File_Q BS
    deriving (Typeable,Eq,Hashable,Binary,NFData)

instance Show File_Q where show (File_Q x) = unpack x

newtype File_A = File_A (Maybe FileTime)
    deriving (Typeable,Eq,Hashable,Binary,Show,NFData)

instance Rule File_Q File_A where
    storedValue (File_Q x) = fmap (fmap (File_A . Just)) $ getModTimeMaybe $ unpack_ x


defaultRuleFile_ :: Rules ()
defaultRuleFile_ = defaultRule $ \(File_Q x) -> Just $
    liftIO $ fmap (File_A . Just) $ getModTimeError "Error, file does not exist and no rule available:" $ unpack_ x


need_ :: [FilePath] -> Action ()
need_ xs = (apply $ map (File_Q . pack) xs :: Action [File_A]) >> return ()

want_ :: [FilePath] -> Rules ()
want_ = action . need_


(??>) :: (FilePath -> Bool) -> (FilePath -> Action ()) -> Rules ()
(??>) test act = rule $ \(File_Q x_) -> let x = unpack x_ in
    if not $ test x then Nothing else Just $ do
        liftIO $ createDirectoryIfMissing True $ takeDirectory x
        act x
        liftIO $ fmap File_A $ getModTimeMaybe $ unpack_ x_

{'fraction_non_alphanumeric': 0.13866812825431626, 'fraction_numerical': 0.0005480953685941354, 'mean_word_length': 3.1666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3593193', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1086, 'n_words': 376}