diff --git a/cpm/README.md b/cpm/README.md index bfb873a726d064f5902cb940f854dc0adb85380f..d787cd3fc7573a0a7209b4444eee57f4c9bd8a2d 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 8f6ab5e20b410791c9f9ceae47d8a8a8fc6d095b..6c866bee676c558d755a3b10b3195eef12e5bc06 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 418e02be0dd86a96e094eb7fdf50727c80be9ee7..e8a8aff242ff9cd21459b0463391c8cf62cf5284 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 43861eb817a1f1350ee9dded891ea0e004fa62bf..5fd51ae1b465b3fecb733961a8af17147ea7e2a5 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 28601537a514a2e3883fdc48e253c029fcb5cdd0..4e868b897ea3bc2304b866ffa9e10e8cf9f53fae 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 9291bb92427153d6c8f132d42e9f1cc80259333a..9a41d7a988153547f925dbfe862189386825e52e 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 c7e99f8476ec2d19270370a53f67ae9facec18bf..a1616932943edaeb0d0307a0efc2acec90cc7b6e 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)