dev: cleanup
This commit is contained in:
parent
48620c8e8c
commit
c0971c1c09
@ -318,12 +318,12 @@ includedirectivep iopts = do
|
|||||||
return prefixedglob
|
return prefixedglob
|
||||||
) <|> errorNoArg
|
) <|> errorNoArg
|
||||||
|
|
||||||
let (mprefix,glb) = splitReaderPrefix prefixedglob
|
let (mprefix,path) = splitReaderPrefix prefixedglob
|
||||||
parentf <- sourcePosFilePath pos
|
parentf <- sourcePosFilePath pos
|
||||||
when (null $ dbg6 (parentf <> " include: glob pattern") glb) errorNoArg
|
when (null $ dbg6 (parentf <> " include: path ") path) errorNoArg
|
||||||
|
|
||||||
-- Find the file or glob-matched files (just the ones from this include directive), with some IO error checking.
|
-- Find the file or glob-matched files (just the ones from this include directive), with some IO error checking.
|
||||||
paths <- findMatchedFiles eoff parentf glb
|
paths <- findMatchedFiles eoff parentf path
|
||||||
-- Also report whether a glob pattern was used, and not just a literal file path.
|
-- Also report whether a glob pattern was used, and not just a literal file path.
|
||||||
-- (paths, isglob) <- findMatchedFiles off pos glb
|
-- (paths, isglob) <- findMatchedFiles off pos glb
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ includedirectivep iopts = do
|
|||||||
-- but ** will implicitly search non-top-level dot directories (see #2498, Glob#49).
|
-- but ** will implicitly search non-top-level dot directories (see #2498, Glob#49).
|
||||||
|
|
||||||
findMatchedFiles :: (MonadIO m) => Int -> FilePath -> FilePath -> JournalParser m [FilePath]
|
findMatchedFiles :: (MonadIO m) => Int -> FilePath -> FilePath -> JournalParser m [FilePath]
|
||||||
findMatchedFiles off parentf globpattern = do
|
findMatchedFiles off parentf path = do
|
||||||
|
|
||||||
-- Some notes about the Glob library that we use (related: https://github.com/Deewiant/glob/issues/49):
|
-- Some notes about the Glob library that we use (related: https://github.com/Deewiant/glob/issues/49):
|
||||||
-- It does not expand tilde.
|
-- It does not expand tilde.
|
||||||
@ -374,39 +374,39 @@ includedirectivep iopts = do
|
|||||||
-- A **/ component matches any number of directory parts.
|
-- A **/ component matches any number of directory parts.
|
||||||
-- A **/ does not implicitly search top-level dot directories or implicitly match do files,
|
-- A **/ does not implicitly search top-level dot directories or implicitly match do files,
|
||||||
-- but it does search non-top-level dot directories. Eg ** will find the c file in a/.b/c.
|
-- but it does search non-top-level dot directories. Eg ** will find the c file in a/.b/c.
|
||||||
|
-- It tends to get attributes of all files in a directory.
|
||||||
|
|
||||||
-- expand a tilde at the start of the glob pattern, or throw an error
|
-- expand a tilde at the start of the glob pattern, or throw an error
|
||||||
expandedglob <- lift $ expandHomePath globpattern & handleIOError off "failed to expand ~"
|
expandedpath <- lift $ expandHomePath path & handleIOError off "failed to expand ~"
|
||||||
|
|
||||||
-- get the directory of the including file
|
-- get the directory of the including file
|
||||||
-- need to canonicalise a symlink parentf so takeDirectory works correctly [#2503]
|
-- need to canonicalise a symlink parentf so takeDirectory works correctly [#2503]
|
||||||
cwd <- fmap takeDirectory <$> liftIO $ canonicalizePath parentf
|
cwd <- fmap takeDirectory <$> liftIO $ canonicalizePath parentf
|
||||||
|
|
||||||
-- Don't allow 3 or more stars.
|
-- Don't allow 3 or more stars.
|
||||||
when ("***" `isInfixOf` expandedglob) $
|
when ("***" `isInfixOf` expandedpath) $
|
||||||
customFailure $ parseErrorAt off $ "Invalid glob pattern: too many stars, use * or **"
|
customFailure $ parseErrorAt off $ "Invalid glob pattern: too many stars, use * or **"
|
||||||
|
|
||||||
-- Make ** also match file name parts like zsh's GLOB_STAR_SHORT.
|
-- Make ** also match file name parts like zsh's GLOB_STAR_SHORT.
|
||||||
let
|
let
|
||||||
finalglob =
|
finalpath =
|
||||||
-- ** without a slash is equivalent to **/*
|
-- ** without a slash is equivalent to **/*
|
||||||
case regexReplace (toRegex' $ T.pack "\\*\\*([^/\\])") "**/*\\1" expandedglob of
|
case regexReplace (toRegex' $ T.pack "\\*\\*([^/\\])") "**/*\\1" expandedpath of
|
||||||
Right s -> s
|
Right s -> s
|
||||||
Left _ -> expandedglob -- ignore any error, there should be none
|
Left _ -> expandedpath -- ignore any error, there should be none
|
||||||
|
|
||||||
-- Compile as a Pattern. Can throw an error.
|
-- Compile as a Pattern. Can throw an error.
|
||||||
pat <- case tryCompileWith compDefault{errorRecovery=False} finalglob of
|
pat <- case tryCompileWith compDefault{errorRecovery=False} finalpath of
|
||||||
Left e -> customFailure $ parseErrorAt off $ "Invalid glob pattern: " ++ e
|
Left e -> customFailure $ parseErrorAt off $ "Invalid glob pattern: " ++ e
|
||||||
Right x -> pure x
|
Right x -> pure x
|
||||||
|
|
||||||
-- Find all matched paths. These might include directories or the current file.
|
-- Find all paths matched by the glob pattern.
|
||||||
-- Glob seems to get attributes of all files in a directory, which disturbs build systems
|
-- If it is a literal (non-glob) path, don't use the Glob lib, because it gets attributes
|
||||||
-- which detect dependencies based on filesystem operations (eg tup).
|
-- of all files in the directory, which confuses build systems like tup.
|
||||||
-- So avoid using it if not needed.
|
paths <-
|
||||||
paths <- liftIO $
|
|
||||||
if isLiteral pat
|
if isLiteral pat
|
||||||
then return $ if isAbsolute finalglob then [finalglob] else [cwd </> finalglob]
|
then return $ if isAbsolute finalpath then [finalpath] else [cwd </> finalpath]
|
||||||
else globDir1 pat cwd
|
else liftIO $ globDir1 pat cwd
|
||||||
|
|
||||||
-- Exclude any directories or symlinks to directories, and canonicalise, and sort.
|
-- Exclude any directories or symlinks to directories, and canonicalise, and sort.
|
||||||
files <- liftIO $
|
files <- liftIO $
|
||||||
@ -429,7 +429,7 @@ includedirectivep iopts = do
|
|||||||
| otherwise -> return f
|
| otherwise -> return f
|
||||||
|
|
||||||
-- Throw an error if no files were matched.
|
-- Throw an error if no files were matched.
|
||||||
when (null files2) $ customFailure $ parseErrorAt off $ "No files were matched by: " ++ globpattern
|
when (null files2) $ customFailure $ parseErrorAt off $ "No files were matched by: " ++ path
|
||||||
|
|
||||||
-- If the current file got included, ignore it (last, to avoid triggering the error above).
|
-- If the current file got included, ignore it (last, to avoid triggering the error above).
|
||||||
let
|
let
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user