Skip to content

Commit

Permalink
Bump to 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
berberman committed Nov 9, 2020
1 parent 509daed commit a6c265d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 107 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
`uusi` uses [PVP Versioning][1].
The changelog is available [on GitHub][2].

## 0.1.0.0

* Remove diff

* Reduce dependencies as much as possible

## 0.0.1.0

* Support sub-libraries and legacy build tools.
Expand Down
18 changes: 18 additions & 0 deletions app/Lens.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Lens
( module Distribution.Compat.Lens,
mapped,
(|>),
(<&>),
)
where

import Data.Functor ((<&>))
import Data.Functor.Identity (Identity (..))
import Distribution.Compat.Lens

mapped :: Functor f => ASetter (f a) (f b) a b
mapped k = Identity . fmap (runIdentity . k)

-- qwq
(|>) :: a -> (a -> b) -> b
(|>) = (&)
84 changes: 26 additions & 58 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

module Main (main) where

import qualified Colourista as C
import qualified Control.Exception as CE
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
import Distribution.Types.CondTree
Expand All @@ -17,66 +17,34 @@ import Distribution.Types.LegacyExeDependency (LegacyExeDependency (..))
import Distribution.Types.Lens
import Distribution.Types.VersionRange (anyVersion)
import qualified Distribution.Verbosity as Verbosity
import Lens.Micro
import Options.Applicative
import System.Directory (getTemporaryDirectory, removeFile)
import System.IO (hClose, hFlush, hPutStr, openTempFile)
import System.Process (readCreateProcessWithExitCode, shell)

newtype Options = Options
{ optPath :: FilePath
}

cmdOptions :: Parser Options
cmdOptions = Options <$> strArgument (metavar "PATH" <> help "Path to .cabal file")

runArgsParser :: IO Options
runArgsParser =
execParser $
info
(cmdOptions <**> helper)
( fullDesc
<> progDesc "Try to reach the TARGET QAQ."
<> header "uusi - a program removing all version constraints of dependencies in .cabal file"
)
import Lens
import System.Environment (getArgs)

-----------------------------------------------------------------------------

main :: IO ()
main = CE.catch @CE.IOException
( do
Options {..} <- runArgsParser
C.infoMessage "Start running..."
uusiCabal optPath >>= putStrLn
args <- getArgs
case args of
["--help"] -> showHelp
["-help"] -> showHelp
["help"] -> showHelp
[path] -> uusiCabal path
_ -> showHelp
)
$ \e -> C.errorMessage $ "IOException: " <> (T.pack . show $ e)
$ \e -> T.putStrLn $ "IOException: " <> (T.pack . show $ e)

genPatch :: FilePath -> FilePath -> IO String
genPatch a b = (^. _2) <$> readCreateProcessWithExitCode (shell $ "diff -u " <> a <> " " <> b) ""
showHelp :: IO ()
showHelp = putStrLn "uusi - remove all version constraints of dependencies in a .cabal file (replace inplace)\nUsage: uusi PATH_TO_TARGET"

uusiCabal :: FilePath -> IO String
uusiCabal :: FilePath -> IO ()
uusiCabal originPath = do
C.infoMessage $ "Parsing cabal file from " <> T.pack originPath <> "..."

T.putStrLn $ "Parsing cabal file from " <> T.pack originPath <> "..."
cabal <- readGenericPackageDescription Verbosity.normal originPath
temp <- getTemporaryDirectory
(oldPath, oldHandle) <- openTempFile temp "uusi"

let old = showGenericPackageDescription cabal
uusied = showGenericPackageDescription $ uusiGenericPackageDescription cabal

hPutStr oldHandle old
writeFile originPath uusied

C.infoMessage $ "Write file: " <> T.pack originPath

hFlush oldHandle
hClose oldHandle

result <- genPatch oldPath originPath
removeFile oldPath

return result
let uusi = showGenericPackageDescription $ uusiGenericPackageDescription cabal
writeFile originPath uusi
T.putStrLn $ "Write file: " <> T.pack originPath

-----------------------------------------------------------------------------

Expand All @@ -94,20 +62,20 @@ uusiExeDependency (ExeDependency name component _) = ExeDependency name componen
uusiBuildInfo :: Uusi BuildInfo
uusiBuildInfo i =
i
& (targetBuildDepends %~ fmap uusiDependency)
& (buildToolDepends %~ fmap uusiExeDependency)
& (buildTools %~ fmap uusiLegacyExeDependency)
|> (targetBuildDepends %~ fmap uusiDependency)
|> (buildToolDepends %~ fmap uusiExeDependency)
|> (buildTools %~ fmap uusiLegacyExeDependency)

uusiCondTree :: (HasBuildInfo a) => Uusi (CondTree ConfVar [Dependency] a)
uusiCondTree = mapTreeData (buildInfo %~ uusiBuildInfo) . mapTreeConstrs (fmap uusiDependency)

uusiGenericPackageDescription :: Uusi GenericPackageDescription
uusiGenericPackageDescription cabal =
cabal
& (condExecutables %~ uusiTrees)
& (condTestSuites %~ uusiTrees)
& (condBenchmarks %~ uusiTrees)
& (condSubLibraries %~ uusiTrees)
& (condLibrary . mapped %~ uusiCondTree)
|> (condExecutables %~ uusiTrees)
|> (condTestSuites %~ uusiTrees)
|> (condBenchmarks %~ uusiTrees)
|> (condSubLibraries %~ uusiTrees)
|> (condLibrary . mapped %~ uusiCondTree)
where
uusiTrees trees = trees <&> _2 %~ uusiCondTree
94 changes: 45 additions & 49 deletions uusi.cabal
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
cabal-version: 2.4
name: uusi
version: 0.0.1.0
synopsis: Remove all version constraints of dependencies in .cabal file
cabal-version: 2.4
name: uusi
version: 0.1.0.0
synopsis:
Remove all version constraints of dependencies in .cabal file

description:
@uusi@ is a command-line program to remove all version constraints of dependencies in .cabal files.
It is used in distribution packaging because @--allow-newer@ is not present when calling @Setup.hs@
instead of cabal-install.
homepage: https://github.com/berberman/uusi
bug-reports: https://github.com/berberman/uusi/issues
license: MIT
license-file: LICENSE
author: berberman
maintainer: berberman <1793913507@qq.com>
copyright: 2020 berberman
category: Distribution
build-type: Simple
extra-doc-files: README.md
CHANGELOG.md
tested-with: GHC == 8.10.2
@uusi@ is a command-line program to remove all version constraints of dependencies in .cabal files.
It is used in distribution packaging because @--allow-newer@ is not present when calling @Setup.hs@
instead of cabal-install.

homepage: https://github.com/berberman/uusi
bug-reports: https://github.com/berberman/uusi/issues
license: MIT
license-file: LICENSE
author: berberman
maintainer: berberman <1793913507@qq.com>
copyright: 2020 berberman
category: Distribution
build-type: Simple
extra-doc-files:
CHANGELOG.md
README.md

tested-with: GHC ==8.10.2

source-repository head
type: git
location: https://github.com/berberman/uusi.git
type: git
location: https://github.com/berberman/uusi.git

common common-options
build-depends: base ^>= 4.14.0,
Cabal ^>= 3.2.0,
process ^>= 1.6.9,
directory ^>= 1.3.6,
microlens ^>= 0.4.11,
optparse-applicative ^>= 0.15.1 || ^>= 0.16,
colourista ^>= 0.1,
text ^>= 1.2.3

ghc-options: -Wall
-Wcompat
-Widentities
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-fhide-source-paths
-Wmissing-export-lists
-Wpartial-fields
-Wmissing-deriving-strategies

default-language: Haskell2010
build-depends:
, base ^>=4.14.0
, Cabal ^>=3.2.0
, text ^>=1.2.3

ghc-options:
-Wall -Wcompat -Widentities -Wincomplete-uni-patterns
-Wincomplete-record-updates -Wredundant-constraints
-fhide-source-paths -Wmissing-export-lists -Wpartial-fields
-Wmissing-deriving-strategies

default-language: Haskell2010

executable uusi
import: common-options
hs-source-dirs: app
main-is: Main.hs

ghc-options: -threaded
-rtsopts
-with-rtsopts=-N
import: common-options
hs-source-dirs: app
main-is: Main.hs
other-modules: Lens
ghc-options: -threaded -rtsopts -with-rtsopts=-N

0 comments on commit a6c265d

Please sign in to comment.