From d3c6104853300477bc48a809c6e8ce32853331b6 Mon Sep 17 00:00:00 2001 From: Michael Hanus <mh@informatik.uni-kiel.de> Date: Fri, 6 Jan 2023 13:33:51 +0100 Subject: [PATCH] Update CPM --- cpm/README.md | 2 +- cpm/src/CPM/Config.curry | 11 ++++++----- cpm/src/CPM/FileUtil.curry | 4 ++-- cpm/src/CPM/Helpers.curry | 14 +++++++++++--- cpm/src/CPM/Main.curry | 7 +++++-- cpm/src/CPM/Options.curry | 3 ++- cpm/src/CPM/Package/Helpers.curry | 7 ++++--- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/cpm/README.md b/cpm/README.md index bfb873a7..d787cd3f 100644 --- a/cpm/README.md +++ b/cpm/README.md @@ -82,7 +82,7 @@ A good set of packages to start with is the following: - `package.json`: Since CPM is also implemented in the form of a Curry package, this file contains the package specification for CPM. -- `package.json.schema`: +- `package.schema.json`: A description of the format of package specification files used by CPM in the format as a [JSON schema](https://json-schema.org/). JSON schema is a widely adopted format that makes it easier diff --git a/cpm/src/CPM/Config.curry b/cpm/src/CPM/Config.curry index 8f6ab5e2..6c866bee 100644 --- a/cpm/src/CPM/Config.curry +++ b/cpm/src/CPM/Config.curry @@ -28,7 +28,7 @@ import System.Path ( getFileInPath ) import CPM.ErrorLogger import CPM.FileUtil ( ifFileExists ) -import CPM.Helpers ( strip ) +import CPM.Helpers ( stripSpaces ) --- The default URL prefix to the directory containing tar files of all packages packageTarFilesDefaultURLs :: [String] @@ -165,9 +165,9 @@ setCompilerVersion cfg0 = do then return cfg { compilerVersion = currVersion , compilerBaseVersion = Dist.baseVersion } else do (sname,svers,sbver) <- getCompilerVersion (curryExec cfg) - let cname = strip sname - cvers = strip svers - bvers = strip sbver + let cname = stripSpaces sname + cvers = stripSpaces svers + bvers = stripSpaces sbver (majs:mins:revs:_) = split (=='.') cvers logDebug $ unwords ["Compiler version:",cname,cvers] logDebug $ "Base lib version: " ++ bvers @@ -264,7 +264,8 @@ mergeConfigSettings cfg props = applyEither setters cfg --- --- @param opts - the options stripProps :: [(String, String)] -> [(String, String)] -stripProps = map (\(a,b) -> ((map toUpper $ filter (/='_') $ strip a), strip b)) +stripProps = + map (\(a,b) -> (map toUpper $ filter (/='_') $ stripSpaces a, stripSpaces b)) --- A map from option names to functions that will update a configuration --- record with a value for that option. diff --git a/cpm/src/CPM/FileUtil.curry b/cpm/src/CPM/FileUtil.curry index 418e02be..e8a8aff2 100644 --- a/cpm/src/CPM/FileUtil.curry +++ b/cpm/src/CPM/FileUtil.curry @@ -34,7 +34,7 @@ import Data.List ( intercalate, isPrefixOf, splitOn ) import Control.Monad ( when ) import System.IOExts ( evalCmd, readCompleteFile ) -import CPM.Helpers ( strip ) +import CPM.Helpers ( stripSpaces ) --- Joins a list of directories into a search path. joinSearchPath :: [FilePath] -> String @@ -85,7 +85,7 @@ linkTarget link = do getRealPath :: String -> IO String getRealPath path = do (rc, out, _) <- evalCmd "realpath" [path] "" - if rc == 0 then return (strip out) + if rc == 0 then return (stripSpaces out) else getAbsolutePath path --- Puts a file argument into quotes to avoid problems with files containing diff --git a/cpm/src/CPM/Helpers.curry b/cpm/src/CPM/Helpers.curry index 43861eb8..5fd51ae1 100644 --- a/cpm/src/CPM/Helpers.curry +++ b/cpm/src/CPM/Helpers.curry @@ -1,8 +1,16 @@ --- Some auxiliary operations that might fit better into system libraries. -module CPM.Helpers ( strip ) where +module CPM.Helpers ( stripSpaces, stripEnclosing ) where import Data.Char ( isSpace ) +import Data.List ( init, last ) -strip :: String -> String -strip = reverse . dropWhile isSpace . reverse . dropWhile isSpace +--- Strips leading and tailing spaces: +stripSpaces :: String -> String +stripSpaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace + +--- Strips a leading and tailing character if they are present. +stripEnclosing :: Char -> Char -> String -> String +stripEnclosing lc tc s = case s of + c1:cs@(_:_) | c1 == lc && last cs == tc -> init cs + _ -> s diff --git a/cpm/src/CPM/Main.curry b/cpm/src/CPM/Main.curry index 28601537..4e868b89 100644 --- a/cpm/src/CPM/Main.curry +++ b/cpm/src/CPM/Main.curry @@ -70,7 +70,7 @@ cpmBanner = unlines [bannerLine, bannerText, bannerLine] where bannerText = "Curry Package Manager <curry-lang.org/tools/cpm> (Version " ++ - packageVersion ++ ", 20/07/2022)" + packageVersion ++ ", 06/01/2023)" bannerLine = take (length bannerText) (repeat '-') main :: IO () @@ -1016,6 +1016,8 @@ execWithCurryPath o _ currypath = do liftIOEL $ unsetEnv "CURRYPATH" liftIOEL $ unless (ecode==0) (exitWith ecode) +-- Compute the load path of the package as a string where +-- the directory of the `base` package is removed. computePackageLoadPath :: Config -> String -> ErrorLogger String computePackageLoadPath cfg pkgdir = do logDebug "Computing load path for package..." @@ -1257,7 +1259,8 @@ saveCurryPathToCache cfg pkgdir path = do (unlines [path, showCompilerVersion cfg, compilerBaseVersion cfg]) --- Gets CURRYPATH of the given package (either from the local cache file ---- in the package dir or compute it). +--- in the package dir or compute it). The directory of the `base` package +--- is removed from the path since it is part of the Curry system libraries. getCurryLoadPath :: Config -> String -> ErrorLogger String getCurryLoadPath cfg pkgdir = do mbp <- loadCurryPathFromCache cfg pkgdir diff --git a/cpm/src/CPM/Options.curry b/cpm/src/CPM/Options.curry index 9291bb92..9a41d7a9 100644 --- a/cpm/src/CPM/Options.curry +++ b/cpm/src/CPM/Options.curry @@ -11,6 +11,7 @@ import Data.List ( splitOn ) import OptParse +import CPM.Helpers ( stripEnclosing ) import CPM.Package ( Version, readVersion ) import CPM.ErrorLogger @@ -279,7 +280,7 @@ readRcOption :: String -> Either String (String,String) readRcOption s = let (option,value) = break (=='=') s in if null value then Left $ "Error in option definition: '=' missing" - else Right $ (option, tail value) + else Right $ (option, stripEnclosing '"' '"' (tail value)) readVersion' :: String -> Either String Version readVersion' s = case readVersion s of diff --git a/cpm/src/CPM/Package/Helpers.curry b/cpm/src/CPM/Package/Helpers.curry index c7e99f84..a1616932 100644 --- a/cpm/src/CPM/Package/Helpers.curry +++ b/cpm/src/CPM/Package/Helpers.curry @@ -27,7 +27,7 @@ import CPM.Executables ( getCurlCmd ) import CPM.FileUtil ( cleanTempDir, getRealPath, inDirectory, inTempDir , quote, removeDirectoryComplete, tempDir , whenFileExists ) -import CPM.Helpers ( strip ) +import CPM.Helpers ( stripSpaces ) import CPM.Package ------------------------------------------------------------------------------ @@ -175,7 +175,7 @@ renderPackageInfo allinfos plain installed pkg = pPrint doc ver = fill maxLen (boldText "Version") <+> (text $ showVersion $ version pkg) auth = fill maxLen (boldText "Author") <+> - indent 0 (fillSep (map (text . strip) + indent 0 (fillSep (map (text . stripSpaces) (concatMap (splitOn ",") $ author pkg))) synop = fill maxLen (boldText "Synopsis") <+> indent 0 (fillSep (map text (words (synopsis pkg)))) @@ -185,7 +185,8 @@ renderPackageInfo allinfos plain installed pkg = pPrint doc maintnr = case maintainer pkg of [] -> empty xs -> fill maxLen (boldText "Maintainer") <+> - indent 0 (fillSep (map (text . strip) (concatMap (splitOn ",") xs))) + indent 0 (fillSep (map (text . stripSpaces) + (concatMap (splitOn ",") xs))) cats = if null (category pkg) -- GitLab