on master help sign in
WIP ob-preprocessor fixes

Still waiting on a long download

commit1ed3d55224ee642804aefd5833b13aba0357b9b3 authorleon.smith@obsidian.systems <leon.smith@obsidian.systems> dateWed 15 Jan 2020, 13:07 (7 years ago) parent25c2068
1 file changed+8−5
lib/command/src/Obelisk/Command/Preprocessor.hs+8−5
lib/command/src/Obelisk/Command/Preprocessor.hs+8−5
@@ -26,26 +26,29 @@ main = do
2626
2727 args@(origPath:inPath:outPath:packagePaths) <- getArgs
2828
29+ outFile <- hOpen outPath WriteMode
30+ let hPutTextBuilder h = BL.hPutBuilder h . TL.encodeUtf8Builder . TL.toLazyText
31+
2932 putStr "--------------------------------------------------------------------------------\n"
3033 print args
3134 putStr "--------------------------------------------------------------------------------\n"
3235
3336 -- Thus we must select among the packagePaths for the file we are going to parse.
3437
35− let packageDirs = sortOn (negate . length) $ map (splitPath . normalise) packagePaths
38+ let takeDirs = takeWhile hasTrailingPathSeperator
39+ packageDirs = sortOn (negate . length . takeDirs) $ map (splitPath . normalise) packagePaths
3640 origDir = splitPath $ normalise $ origPath
37− matches = [ d | d@(_:_) <- packageDirs, takeWhile hasTrailingPathSeperator d `isPrefixOf` origDir ]
41+ matches = [ d | d <- packageDirs, takeDirs d `isPrefixOf` origDir ]
3842
3943 -- So the first element of matches is going to be the deepest path to a package spec that contains
4044 -- our file as a subdirectory.
4145
42− let hPutTextBuilder outFile = BL.hPutBuilder outFile . TL.encodeUtf8Builder . TL.toLazyText
4346 case matches of
44− [] -> hPutTextBuilder (lineNumberPragma origPath) -- TODO: probably should produce a warning
47+ [] -> hPutTextBuilder outFile (lineNumberPragma origPath) -- TODO: probably should produce a warning
4548 (packagePath:_) -> do
4649 runObelisk (ObeliskT mempty) (parseCabalPackage packagePath) >>= \case
4750 Just packageInfo -> do
48− hPutTextBuilder (generateHeader origPath packageInfo)
51+ hPutTextBuilder outFile (generateHeader origPath packageInfo)
4952
5053 BL.readFile inPath >>= BL.hPut outFile
5154 hClose outFile