autonix-deps 0.1.0.1 → 0.2.0.0
raw patch · 5 files changed
+25/−57 lines, 5 files
Files
- autonix-deps.cabal +1/−1
- src/Autonix/Analyze.hs +2/−4
- src/Autonix/Args.hs +2/−6
- src/Autonix/Deps.hs +7/−41
- src/Autonix/Generate.hs +13/−5
autonix-deps.cabal view
@@ -1,5 +1,5 @@ name: autonix-deps-version: 0.1.0.1+version: 0.2.0.0 synopsis: Library for Nix expression dependency generation license: BSD3 license-file: LICENSE
src/Autonix/Analyze.hs view
@@ -25,11 +25,9 @@ analyzePackages :: (MonadIO m, MonadState Deps m) => (ByteString -> FilePath -> m a)- -> FilePath -> Maybe FilePath -> m ()-analyzePackages perPackage manifestPath renamesPath = do+ -> FilePath -> m ()+analyzePackages perPackage manifestPath = do manifest <- readManifest manifestPath- renames <- readRenames renamesPath- names %= flip M.union renames forM_ manifest $ \(pkg, _) -> at pkg .= Just mempty let (pkgs, _) = unzip manifest mapM_ (uncurry perPackage) manifest
src/Autonix/Args.hs view
@@ -5,12 +5,8 @@ import Control.Monad.IO.Class import Options.Applicative -withArgs :: MonadIO m => (FilePath -> Maybe FilePath -> m a) -> m a+withArgs :: MonadIO m => (FilePath -> m a) -> m a withArgs child = join $ liftIO $ execParser $ info (helper <*> parser) fullDesc where- parser = child- <$> strArgument (metavar "MANIFEST")- <*> option- (Just <$> str)- (long "renames" <> metavar "FILENAME" <> value Nothing)+ parser = child <$> strArgument (metavar "MANIFEST")
src/Autonix/Deps.hs view
@@ -13,11 +13,8 @@ import Control.Lens import Control.Monad.State-import qualified Data.ByteString.Char8 as B-import qualified Data.Char as Char import qualified Data.Map as M import Data.Monoid-import qualified Data.Set as S import Prelude hiding (foldr) import Autonix.PkgDeps@@ -33,50 +30,19 @@ mempty = Deps { _names = M.empty, _deps = M.empty } mappend a b = flip execState a $ do- let b' = execState (iforMOf_ (names.>itraversed) a rename) b- iforMOf_ (names.>itraversed) b' rename- names %= M.union (b'^.names)- deps %= M.unionWith mappend (b'^.deps)--lookupNewName :: Deps -> ByteString -> ByteString-lookupNewName r (B.map Char.toLower -> idx) =- M.findWithDefault idx idx (r^.names)--renamePkgDeps :: ByteString -> ByteString -> PkgDeps -> PkgDeps-renamePkgDeps old new =- execState $ do- buildInputs %= S.map go- nativeBuildInputs %= S.map go- propagatedBuildInputs %= S.map go- propagatedNativeBuildInputs %= S.map go- propagatedUserEnvPkgs %= S.map go- where- go pkg | pkg == old = new- | otherwise = pkg+ let b' = execState (iforMOf_ (names.>itraversed) a rename) b+ iforMOf_ (names.>itraversed) b' rename+ names %= M.union (b'^.names)+ deps %= M.unionWith mappend (b'^.deps) rename :: (MonadState Deps m) => ByteString -> ByteString -> m ()-rename (B.map Char.toLower -> old) (B.map Char.toLower -> new) = do- names %= M.insert old new- names %= M.map (\tgt -> if tgt == old then new else tgt)- deps %= M.map (renamePkgDeps old new)- ds <- get- deps %= M.mapKeysWith mappend (lookupNewName ds)--applyRenames :: Deps -> PkgDeps -> PkgDeps-applyRenames r = execState $ do- buildInputs %= S.map (lookupNewName r)- propagatedBuildInputs %= S.map (lookupNewName r)- nativeBuildInputs %= S.map (lookupNewName r)- propagatedNativeBuildInputs %= S.map (lookupNewName r)- propagatedUserEnvPkgs %= S.map (lookupNewName r)+rename old new = names %= M.insert old new type instance Index Deps = ByteString type instance IxValue Deps = PkgDeps instance Ixed Deps where- ix idx f r =- (deps . ix (lookupNewName r idx)) (fmap (applyRenames r) . f) r+ ix idx = deps . ix idx instance At Deps where- at idx f r =- (deps . at (lookupNewName r idx)) (fmap (fmap $ applyRenames r) . f) r+ at idx = deps . at idx
src/Autonix/Generate.hs view
@@ -29,11 +29,19 @@ writeDeps = liftIO . B.writeFile "dependencies.nix" . depsToNix writeRenames :: MonadIO m => Deps -> m ()-writeRenames ds = do- let renames = B.unlines $ do- (old, new) <- M.toList (ds^.names)- return $ old <> " " <> new- liftIO $ B.writeFile "renames.txt" renames+writeRenames ds = liftIO $ do+ let renames = do+ (old, new) <- M.toList (ds^.names)+ return ("\"" <> old <> "\" = \"" <> new <> "\";")+ B.writeFile+ "renames.nix"+ (B.unlines+ ([ "# DO NOT EDIT! This file is generated automatically."+ , "{ }:"+ , "{"+ ]+ ++ renames +++ [ "}" ])) packageDeps :: (ByteString, PkgDeps) -> ByteString packageDeps (name, ds) =