Commit b1c2eaac authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Preprocess cabal-install.cabal

- Disable cabal-install's haddock on CI
- Temporarily disable cabal check (`-main-is` in tests)
- Remove this is not a lib note
- Tell to run git update-index --assume-unchanged

    ... when changing to -dev or -monolithic configuration.

    Run --no-assume-unchanged unconditionally, when
    changing to the production build.
- Improve auto-gen note in cabal-install.cabal
- Try to build haddock (with GHC-8.4.3 only)
parent 81a90a0a
.PHONY : all lexer sdpx lib exe doctest gen-extra-source-files
.PHONY : all lexer sdpx lib exe doctest
.PHONY : gen-extra-source-files gen-extra-source-files-lib gen-extra-source-files-cli
.PHONY : cabal-install-dev cabal-install-prod
LEXER_HS:=Cabal/Distribution/Parsec/Lexer.hs
SPDX_LICENSE_HS:=Cabal/Distribution/SPDX/LicenseId.hs
......@@ -21,6 +23,20 @@ $(SPDX_LICENSE_HS) : boot/SPDX.LicenseId.template.hs cabal-dev-scripts/src/GenUt
$(SPDX_EXCEPTION_HS) : boot/SPDX.LicenseExceptionId.template.hs cabal-dev-scripts/src/GenUtils.hs cabal-dev-scripts/src/GenSPDXExc.hs license-list-data/exceptions-3.0.json license-list-data/exceptions-3.2.json
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-spdx-exc -- boot/SPDX.LicenseExceptionId.template.hs license-list-data/exceptions-3.0.json license-list-data/exceptions-3.2.json $(SPDX_EXCEPTION_HS)
cabal-install-prod : cabal-install/cabal-install.cabal.pp
runghc cabal-dev-scripts/src/Preprocessor.hs -o cabal-install/cabal-install.cabal cabal-install/cabal-install.cabal.pp
git update-index --no-assume-unchanged cabal-install/cabal-install.cabal
cabal-install-dev : cabal-install/cabal-install.cabal.pp
runghc cabal-dev-scripts/src/Preprocessor.hs -o cabal-install/cabal-install.cabal -f CABAL_FLAG_LIB cabal-install/cabal-install.cabal.pp
@echo "tell git to ignore changes to cabal-install.cabal:"
@echo "git update-index --assume-unchanged cabal-install/cabal-install.cabal"
cabal-install-monolithic : cabal-install/cabal-install.cabal.pp
runghc cabal-dev-scripts/src/Preprocessor.hs -o cabal-install/cabal-install.cabal -f CABAL_FLAG_LIB -f CABAL_FLAG_MONOLITHIC cabal-install/cabal-install.cabal.pp
@echo "tell git to ignore changes to cabal-install.cabal:"
@echo "git update-index --assume-unchanged cabal-install/cabal-install.cabal"
lib : $(LEXER_HS)
cabal new-build --enable-tests Cabal
......@@ -30,9 +46,16 @@ exe : $(LEXER_HS)
doctest :
doctest --fast Cabal/Distribution Cabal/Language
gen-extra-source-files:
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- Cabal/Cabal.cabal
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- cabal-install/cabal-install.cabal
gen-extra-source-files : gen-extra-source-files-lib gen-extra-source-files-cli
gen-extra-source-files-lib :
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- $$(pwd)/Cabal/Cabal.cabal
# We need to generate cabal-install-dev so the test modules are in .cabal file!
gen-extra-source-files-cli :
$(MAKE) cabal-install-dev
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- $$(pwd)/cabal-install/cabal-install.cabal.pp $$(pwd)/cabal-install/cabal-install.cabal
$(MAKE) cabal-install-prod
cabal-install-test:
cabal new-build -j3 all --disable-tests --disable-benchmarks
......
......@@ -34,6 +34,7 @@ cache:
- "C:\\sr"
build_script:
- runghc cabal-dev-scripts/src/Preprocessor.hs -o cabal-install/cabal-install.cabal -f CABAL_FLAG_LIB cabal-install/cabal-install.cabal.pp
- cabal %CABOPTS% new-configure --enable-tests
- appveyor-retry cabal %CABOPTS% new-build lib:Cabal --only-dependencies
- cabal %CABOPTS% new-build lib:Cabal
......@@ -41,7 +42,7 @@ build_script:
- cabal %CABOPTS% new-test Cabal
- appveyor-retry cabal %CABOPTS% new-build exe:cabal exe:cabal-tests --only-dependencies
- cabal %CABOPTS% new-build exe:cabal
- cabal %CABOPTS% new-run cabal-tests -- -j3 --with-cabal=dist-newstyle\build\x86_64-windows\ghc-8.0.2\cabal-install-2.5.0.0\build\cabal\cabal.exe
- cabal %CABOPTS% new-run cabal-tests -- -j3 --with-cabal=dist-newstyle\build\x86_64-windows\ghc-8.0.2\cabal-install-2.5.0.0\x\cabal\build\cabal\cabal.exe
- appveyor-retry cabal %CABOPTS% new-build cabal-install:tests --only-dependencies
- cd cabal-install
- cabal %CABOPTS% new-run cabal-install:memory-usage-tests
......
......@@ -18,10 +18,11 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified System.IO as IO
main' :: FilePath -> IO ()
main' fp' = do
main' :: FilePath -> FilePath -> IO ()
main' templateFp fp' = do
fp <- canonicalizePath fp'
setCurrentDirectory (takeDirectory fp)
print $ takeDirectory fp
-- Read cabal file, so we can determine test modules
contents <- BS.readFile fp
......@@ -33,6 +34,7 @@ main' fp' = do
-- We skip some files
testModuleFiles <- getOtherModulesFiles cabal
let skipPredicates' = skipPredicates ++ map (==) testModuleFiles
print testModuleFiles
-- Read all files git knows about under "tests"
files0 <- lines <$> readProcess "git" ["ls-files", "tests"] ""
......@@ -46,16 +48,17 @@ main' fp' = do
let files = files3
-- Read current file
templateContents <- BS.readFile templateFp
let topLine' = BS8.pack topLine
bottomLine' = BS8.pack bottomLine
inputLines = BS8.lines contents
inputLines = BS8.lines templateContents
linesBefore = takeWhile (/= topLine') inputLines
linesAfter = dropWhile (/= bottomLine') inputLines
-- Output
let outputLines = linesBefore ++ [topLine']
++ map ((<>) " " . BS8.pack) files ++ linesAfter
BS.writeFile fp (BS8.unlines outputLines)
BS.writeFile templateFp (BS8.unlines outputLines)
topLine, bottomLine :: String
......@@ -108,10 +111,11 @@ main :: IO ()
main = do
args <- getArgs
case args of
[fp] -> main' fp
_ -> do
[fp] -> main' fp fp
[fp,fp'] -> main' fp fp'
_ -> do
progName <- getProgName
putStrLn "Error too few arguments!"
putStrLn $ "Usage: " ++ progName ++ " FILE"
putStrLn $ "Usage: " ++ progName ++ " <FILE | FILE CABAL>"
putStrLn $ " where FILE is Cabal.cabal, cabal-testsuite.cabal, "
++ "or cabal-install.cabal"
{-# LANGUAGE DeriveFunctor #-}
module Main (main) where
import Control.Applicative
import Control.Monad (ap, unless)
import Data.Char (isSpace)
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr)
import qualified Data.Map as Map
import qualified System.Console.GetOpt as O
-------------------------------------------------------------------------------
-- Types
-------------------------------------------------------------------------------
type Flag = String
type Var = String
data Token
= Raw String
| Var Int Var
| If Flag
| Else
| Endif
| Def Var
| Enddef
| Comment
| Error String
deriving Show
data Tree
= TRaw String
| TVar Int Var
| TDef Var Forest
| TIf Flag Forest Forest
deriving Show
type Forest = [Tree]
-------------------------------------------------------------------------------
-- Lex
-------------------------------------------------------------------------------
tokens :: String -> [Token]
tokens = map classify . lines where
classify :: String -> Token
classify s0 = case s1 of
[] -> Raw ""
('#' : _) -> Comment
('$' : s) -> Var (length ws) s
('%' : s)
| Just s' <- "if" `isPrefixOf'` s -> If $ dropWhile isSpace s'
| Just _ <- "else" `isPrefixOf'` s -> Else
| Just _ <- "endif" `isPrefixOf'` s -> Endif
| Just s' <- "def" `isPrefixOf'` s -> Def $ dropWhile isSpace s'
| Just _ <- "enddef" `isPrefixOf'` s -> Enddef
| otherwise -> Error $ "Unknown command: " ++ s
_ -> Raw s0
where
(ws, s1) = span isSpace s0
-- | 'isPrefixOf' returning the rest of the string
isPrefixOf' :: String -> String -> Maybe String
isPrefixOf' [] ys = Just ys
isPrefixOf' (_:_) [] = Nothing
isPrefixOf' (x:xs) (y:ys) | x == y = isPrefixOf' xs ys
| otherwise = Nothing
-------------------------------------------------------------------------------
-- Parse
-------------------------------------------------------------------------------
newtype P a = P { unP :: [Token] -> Either String ([Token], a) }
deriving Functor
instance Applicative P where
pure x = P $ \toks -> Right (toks, x)
(<*>) = ap
instance Alternative P where
empty = P $ \_ -> Left "empty"
x <|> y = P $ \toks -> case unP x toks of
Right res -> Right res
Left _ -> unP y toks
instance Monad P where
return = pure
m >>= k = P $ \toks0 -> do
(toks1, x) <- unP m toks0
unP (k x) toks1
runP :: P a -> [Token] -> Either String a
runP (P p) = fmap snd . p
forest :: [Token] -> Either String Forest
forest = runP (forestP <* eof) where
forestP = many tree
tree = rawP <|> varP <|> ifP <|> defP
ifP :: P Tree
ifP = do
f <- if_
c <- forestP
a <- else_ *> forestP <|> pure []
endif_
return (TIf f c a)
defP :: P Tree
defP = do
v <- def_
t <- forestP
enddef_
return (TDef v t)
rawP :: P Tree
rawP = token "Raw " $ \tok -> case tok of
Raw s -> Just (TRaw s)
_ -> Nothing
varP :: P Tree
varP = token "Var" $ \toks -> case toks of
Var n v -> Just (TVar n v)
_ -> Nothing
if_ :: P Flag
if_ = token "If" $ \toks -> case toks of
If f -> Just f
_ -> Nothing
def_ :: P Var
def_ = token "Def" $ \toks -> case toks of
Def v -> Just v
_ -> Nothing
else_ :: P ()
else_ = token "Else" $ \toks -> case toks of
Else -> Just ()
_ -> Nothing
enddef_ :: P ()
enddef_ = token "Enddef" $ \toks -> case toks of
Enddef -> Just ()
_ -> Nothing
endif_ :: P ()
endif_ = token "Endif" $ \toks -> case toks of
Endif -> Just ()
_ -> Nothing
token :: String -> (Token -> Maybe a) -> P a
token name f = P $ \toks -> case toks of
(tok : toks') | Just x <- f tok -> Right (toks', x)
_ -> Left $ "Expected " ++ name
eof :: P ()
eof = P $ \toks ->
if null toks
then Right (toks, ())
else Left $ "expected end-of-input, got: " ++ show (take 1 toks)
-------------------------------------------------------------------------------
-- Process
-------------------------------------------------------------------------------
process :: [Flag] -> String -> String
process flags
= either error (unlines . go Map.empty)
. forest
. filter (not . isComment)
. tokens
where
isComment Comment = True
isComment _ = False
go :: Map.Map Var Forest -> Forest -> [String]
go _ [] = []
go vars (TRaw s : toks) = s : go vars toks
go vars (TVar _ v : toks) = case Map.lookup v vars of
Nothing -> go vars toks
Just f -> go vars (f ++ toks)
go vars (TIf f c a : toks)
| f `elem` flags = go vars (c ++ toks)
| otherwise = go vars (a ++ toks)
go vars (TDef n f : toks) = go (Map.insert n f vars) toks
-------------------------------------------------------------------------------
-- Main
-------------------------------------------------------------------------------
data Opts = Opts
{ optsFlags :: [Flag]
, optsOutput :: Maybe FilePath
}
emptyOpts :: Opts
emptyOpts = Opts [] Nothing
optDescrs :: [O.OptDescr (Opts -> Opts)]
optDescrs =
[ O.Option "o" []
(O.ReqArg (\arg opts -> opts { optsOutput = Just arg }) "OUTPUT")
"Output"
, O.Option "f" []
(O.ReqArg (\arg opts -> opts { optsFlags = arg : optsFlags opts }) "FLAG")
"Flag"
]
main :: IO ()
main = do
(optEndos, args, errs) <- O.getOpt O.RequireOrder optDescrs <$> getArgs
let opts = foldr ($) emptyOpts optEndos :: Opts
unless (null errs) $ do
mapM_ (hPutStrLn stderr) errs
fail "errors"
case args of
[fp] -> do
contents <- readFile fp
let output = process (optsFlags opts) contents
maybe putStr writeFile (optsOutput opts) output
_ -> fail "Expecting exactly one argument"
Cabal-Version: >= 1.10
-- NOTE: This file is autogenerated from 'cabal-install.cabal.pp'.
-- DO NOT EDIT MANUALLY.
-- To update this file, edit 'cabal-install.cabal.pp' and run
-- 'make cabal-install-prod' in the project's root folder.
Name: cabal-install
Version: 2.5.0.0
Synopsis: The command-line interface for Cabal and Hackage.
......@@ -5,9 +10,6 @@ Description:
The \'cabal\' command-line program simplifies the process of managing
Haskell software by automating the fetching, configuration, compilation
and installation of Haskell libraries and programs.
.
This package only provides an executable and cannot be used as a
library (ignore the module listing below.)
homepage: http://www.haskell.org/cabal/
bug-reports: https://github.com/haskell/cabal/issues
License: BSD3
......@@ -17,7 +19,6 @@ Maintainer: Cabal Development Team <cabal-devel@haskell.org>
Copyright: 2003-2018, Cabal Development Team
Category: Distribution
Build-type: Custom
Cabal-Version: >= 1.10
Extra-Source-Files:
README.md bash-completion/cabal bootstrap.sh changelog
tests/README.md
......@@ -121,32 +122,30 @@ Flag debug-tracetree
default: False
manual: True
flag lib
description: Build cabal-install as a library. Please only use this if you are a cabal-install developer.
Default: False
manual: True
-- Build everything (including the test binaries) as a single static binary
-- instead of 5 discrete binaries.
-- This is useful for CI where we build our binaries on one machine, and then
-- ship them to another machine for testing. Since the test binaries are
-- statically linked (making deployment easier), if we build five executables,
-- that means we need to ship ALL 5 binaries (with 5 versions of all the
-- statically linked libraries) to the test machines. This reduces that to one
-- binary and one set of linked libraries.
flag monolithic
description: Build cabal-install also with all of its test and support code. Used by our continuous integration.
default: False
manual: True
custom-setup
setup-depends:
Cabal >= 2.2,
base,
process >= 1.1.0.1 && < 1.7,
filepath >= 1.3 && < 1.5
library
executable cabal
main-is: Main.hs
hs-source-dirs: main
default-language: Haskell2010
ghc-options: -Wall -fwarn-tabs
if impl(ghc >= 8.0)
ghc-options: -Wcompat
-Wnoncanonical-monad-instances
-Wnoncanonical-monadfail-instances
exposed-modules:
ghc-options: -rtsopts -threaded
-- On AIX, some legacy BSD operations such as flock(2) are provided by libbsd.a
if os(aix)
extra-libraries: bsd
hs-source-dirs: .
other-modules:
Distribution.Client.BuildReports.Anonymous
Distribution.Client.BuildReports.Storage
Distribution.Client.BuildReports.Types
......@@ -297,8 +296,6 @@ library
Distribution.Solver.Types.Variable
Paths_cabal_install
-- NOTE: when updating build-depends, don't forget to update version regexps
-- in bootstrap.sh.
build-depends:
async >= 2.0 && < 3,
array >= 0.4 && < 0.6,
......@@ -306,7 +303,7 @@ library
base16-bytestring >= 0.1.1 && < 0.2,
binary >= 0.7 && < 0.9,
bytestring >= 0.10.2 && < 1,
Cabal == 2.5.*,
Cabal == 2.4.*,
containers >= 0.5 && < 0.7,
cryptohash-sha256 >= 0.11 && < 0.12,
deepseq >= 1.3 && < 1.5,
......@@ -352,459 +349,3 @@ library
if flag(debug-tracetree)
cpp-options: -DDEBUG_TRACETREE
build-depends: tracetree >= 0.1 && < 0.2
if !flag(lib)
buildable: False
default-language: Haskell2010
executable cabal
main-is: Main.hs
hs-source-dirs: main
ghc-options: -Wall -fwarn-tabs -rtsopts
if impl(ghc >= 8.0)
ghc-options: -Wcompat
-Wnoncanonical-monad-instances
-Wnoncanonical-monadfail-instances
other-modules: Paths_cabal_install
if flag(lib)
build-depends:
cabal-install,
Cabal,
base,
directory,
filepath
else
hs-source-dirs: .
build-depends:
async >= 2.0 && < 3,
array >= 0.4 && < 0.6,
base >= 4.5 && < 5,
base16-bytestring >= 0.1.1 && < 0.2,
binary >= 0.7 && < 0.9,
bytestring >= 0.10.2 && < 1,
Cabal == 2.5.*,
containers >= 0.5 && < 0.7,
cryptohash-sha256 >= 0.11 && < 0.12,
deepseq >= 1.3 && < 1.5,
directory >= 1.2.2.0 && < 1.4,
echo >= 0.1.3 && < 0.2,
edit-distance >= 0.2.2 && < 0.3,
filepath >= 1.3 && < 1.5,
hashable >= 1.0 && < 2,
HTTP >= 4000.1.5 && < 4000.4,
mtl >= 2.0 && < 3,
network >= 2.6 && < 2.8,
network-uri >= 2.6 && < 2.7,
pretty >= 1.1 && < 1.2,
process >= 1.2 && < 1.7,
random >= 1 && < 1.2,
stm >= 2.0 && < 3,
tar >= 0.5.0.3 && < 0.6,
time >= 1.4 && < 1.10,
zlib >= 0.5.3 && < 0.7,
hackage-security >= 0.5.2.2 && < 0.6,
text >= 1.2.3 && < 1.3,
zip-archive >= 0.3.2.5 && < 0.4,
parsec >= 3.1.13.0 && < 3.2
other-modules:
Distribution.Client.BuildReports.Anonymous
Distribution.Client.BuildReports.Storage
Distribution.Client.BuildReports.Types
Distribution.Client.BuildReports.Upload
Distribution.Client.Check
Distribution.Client.CmdBench
Distribution.Client.CmdBuild
Distribution.Client.CmdClean
Distribution.Client.CmdConfigure
Distribution.Client.CmdUpdate
Distribution.Client.CmdErrorMessages
Distribution.Client.CmdExec
Distribution.Client.CmdFreeze
Distribution.Client.CmdHaddock
Distribution.Client.CmdInstall
Distribution.Client.CmdLegacy
Distribution.Client.CmdRepl
Distribution.Client.CmdRun
Distribution.Client.CmdTest
Distribution.Client.CmdSdist
Distribution.Client.Compat.Directory
Distribution.Client.Compat.ExecutablePath
Distribution.Client.Compat.FileLock
Distribution.Client.Compat.FilePerms
Distribution.Client.Compat.Prelude
Distribution.Client.Compat.Process
Distribution.Client.Compat.Semaphore
Distribution.Client.Config
Distribution.Client.Configure
Distribution.Client.Dependency
Distribution.Client.Dependency.Types
Distribution.Client.DistDirLayout
Distribution.Client.Exec
Distribution.Client.Fetch
Distribution.Client.FetchUtils
Distribution.Client.FileMonitor
Distribution.Client.Freeze
Distribution.Client.GZipUtils
Distribution.Client.GenBounds
Distribution.Client.Get
Distribution.Client.Glob
Distribution.Client.GlobalFlags
Distribution.Client.Haddock
Distribution.Client.HttpUtils
Distribution.Client.IndexUtils
Distribution.Client.IndexUtils.Timestamp
Distribution.Client.Init
Distribution.Client.Init.Heuristics
Distribution.Client.Init.Licenses
Distribution.Client.Init.Types
Distribution.Client.Install
Distribution.Client.InstallPlan
Distribution.Client.InstallSymlink
Distribution.Client.JobControl
Distribution.Client.List
Distribution.Client.Manpage
Distribution.Client.Nix
Distribution.Client.Outdated
Distribution.Client.PackageHash
Distribution.Client.PackageUtils
Distribution.Client.ParseUtils
Distribution.Client.ProjectBuilding
Distribution.Client.ProjectBuilding.Types
Distribution.Client.ProjectConfig
Distribution.Client.ProjectConfig.Legacy
Distribution.Client.ProjectConfig.Types
Distribution.Client.ProjectOrchestration
Distribution.Client.ProjectPlanOutput
Distribution.Client.ProjectPlanning
Distribution.Client.ProjectPlanning.Types
Distribution.Client.RebuildMonad
Distribution.Client.Reconfigure
Distribution.Client.Run
Distribution.Client.Sandbox
Distribution.Client.Sandbox.Index
Distribution.Client.Sandbox.PackageEnvironment
Distribution.Client.Sandbox.Timestamp
Distribution.Client.Sandbox.Types
Distribution.Client.SavedFlags
Distribution.Client.Security.DNS
Distribution.Client.Security.HTTP
Distribution.Client.Setup
Distribution.Client.SetupWrapper
Distribution.Client.SolverInstallPlan
Distribution.Client.SourceFiles
Distribution.Client.SourceRepoParse
Distribution.Client.SrcDist
Distribution.Client.Store
Distribution.Client.Tar
Distribution.Client.TargetSelector
Distribution.Client.Targets
Distribution.Client.Types
Distribution.Client.Update
Distribution.Client.Upload
Distribution.Client.Utils
Distribution.Client.Utils.Assertion
Distribution.Client.Utils.Json
Distribution.Client.VCS
Distribution.Client.Win32SelfUpgrade
Distribution.Client.World
Distribution.Solver.Compat.Prelude
Distribution.Solver.Modular
Distribution.Solver.Modular.Assignment
Distribution.Solver.Modular.Builder
Distribution.Solver.Modular.Configured
Distribution.Solver.Modular.ConfiguredConversion
Distribution.Solver.Modular.ConflictSet
Distribution.Solver.Modular.Cycles
Distribution.Solver.Modular.Dependency
Distribution.Solver.Modular.Explore
Distribution.Solver.Modular.Flag
Distribution.Solver.Modular.Index
Distribution.Solver.Modular.IndexConversion
Distribution.Solver.Modular.LabeledGraph
Distribution.Solver.Modular.Linking
Distribution.Solver.Modular.Log
Distribution.Solver.Modular.Message
Distribution.Solver.Modular.PSQ
Distribution.Solver.Modular.Package
Distribution.Solver.Modular.Preference
Distribution.Solver.Modular.RetryLog
Distribution.Solver.Modular.Solver
Distribution.Solver.Modular.Tree