Skip to content

Commit

Permalink
ghcup: support vanilla and cross compilers (#126)
Browse files Browse the repository at this point in the history
* Update ghcupsync.hs

ghcup metadata 在 0.0.7 添加了 vanilla ,
并在 0.0.8 添加了 cross compiler ,
而在原本的 version parser 中并没有支持。

我修改了 parseVersionFromFileName 以添加支持,
同时考虑到未来可能的更多不同 metadata 版本,
实现了向前兼容(但性能更差的) parser 版本。

* fix typo of version
  • Loading branch information
Erchiusx authored Dec 25, 2024
1 parent b698e54 commit cf2948d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ghcup/ghcupsync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf2948d

Please sign in to comment.