From cf2948df0c2b7175c1dc91c8fd1a5bacb65b2c01 Mon Sep 17 00:00:00 2001 From: Erchiusx <99174225+Erchiusx@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:38:53 +0800 Subject: [PATCH] ghcup: support vanilla and cross compilers (#126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update ghcupsync.hs ghcup metadata 在 0.0.7 添加了 vanilla , 并在 0.0.8 添加了 cross compiler , 而在原本的 version parser 中并没有支持。 我修改了 parseVersionFromFileName 以添加支持, 同时考虑到未来可能的更多不同 metadata 版本, 实现了向前兼容(但性能更差的) parser 版本。 * fix typo of version --- ghcup/ghcupsync.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ghcup/ghcupsync.hs b/ghcup/ghcupsync.hs index a171244..aea8d1a 100644 --- a/ghcup/ghcupsync.hs +++ b/ghcup/ghcupsync.hs @@ -72,9 +72,22 @@ parseVersionFromFileName :: FilePath -> Maybe Version parseVersionFromFileName filename = do let basename = takeBaseName filename noPrefix <- stripPrefix "ghcup-prereleases-" basename + <|> stripPrefix "ghcup-cross-" basename + <|> stripPrefix "ghcup-vanilla-" basename <|> stripPrefix "ghcup-" basename listToMaybe $ map fst . filter (\(_, rem) -> null rem) $ readP_to_S parseVersion noPrefix +-- This version of parseVersionFromFileName may have more forward compatability +-- but poorer performance +-- parseVersionFromFileName filename = do +-- let basename = takeBaseName filename +-- case find isJust . map tryParse $ tails basename of +-- (Just m) -> m -- if found, it will be a double Just, i.e. (Just (Just Version)) +-- Nothing -> Nothing +-- where +-- tryParse :: String -> Maybe Version +-- tryParse = listToMaybe . map fst . reverse . readP_to_S parseVersion + ------------------------------------------------------------------------ syncByMetadata :: FilePath -> FilePath -> IO () syncByMetadata basedir mdpath = do