Skip to content

Commit 16e5689

Browse files
committed
download foundation-pak if missing
1 parent 9798bb8 commit 16e5689

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

external-stg/lib/Stg/Program.hs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import qualified Data.ByteString.Char8 as BS8
3131
import qualified Data.ByteString.Lazy as BSL
3232
import qualified Data.Aeson as Aeson
3333

34+
import System.Process
3435
import System.Directory
3536
import System.FilePath
3637
import System.FilePath.Find
@@ -452,10 +453,6 @@ foundationPakCachePath = do
452453
home <- getHomeDirectory
453454
pure $ home </> ".estg/foundation-pak"
454455

455-
-- example URL: https://github.com/haskell/haskell-language-server/releases/download/2.0.0.0/haskell-language-server-2.0.0.0-aarch64-apple-darwin.tar.xz
456-
457-
foundationPakURL :: String -> String
458-
foundationPakURL ghcVersion = "https://github.com/grin-compiler/foundation-pak/releases/download/" ++ ghcVersion
459456

460457
getFoundationPakForGhcStgApp :: FilePath -> IO PakYaml
461458
getFoundationPakForGhcStgApp ghcstgapp = do
@@ -464,12 +461,15 @@ getFoundationPakForGhcStgApp ghcstgapp = do
464461
-- foundation-pak name schema: `ghc-name`-`ghc-version`-`target-platform`.pak.zip
465462
let foundationPakName = printf "%s-%s-%s" appGhcName appGhcVersion appTargetPlatform
466463
foundationPakPath = root </> foundationPakName
464+
ghcVersionString = printf "%s-%s" appGhcName appGhcVersion
465+
467466
{-
468-
TODO:
469467
check foundationPakPath locally
470468
if not present, create URL and download it to foundationPakPath
471469
load the content from foundationPakPath
472470
-}
471+
downloadFoundationPakIfMissing ghcVersionString foundationPakPath
472+
473473
let prefixPakUnitDirs :: FilePath -> PakYaml -> PakYaml
474474
prefixPakUnitDirs dir p@PakYaml{..} = p
475475
{ pakyamlPackages =
@@ -512,3 +512,20 @@ instance FromJSON PakYaml where
512512
<$> v .: "path-prefix"
513513
<*> v .: "packages"
514514
parseJSON _ = fail "Expected Object for PakYaml value"
515+
516+
-- example URL: https://github.com/grin-compiler/foundation-pak/releases/download/ghc-9.2.7/ghc-9.2.7-x86_64-unknown-linux.pak.tar.xz
517+
foundationPakURL :: String
518+
foundationPakURL = "https://github.com/grin-compiler/foundation-pak/releases/download/"
519+
520+
downloadFoundationPakIfMissing :: String -> FilePath -> IO ()
521+
downloadFoundationPakIfMissing ghcVersionString foundationPakPath = do
522+
exists <- doesDirectoryExist foundationPakPath
523+
when (not exists) $ do
524+
let (pakDir, pakName) = splitFileName foundationPakPath
525+
pakFileName = pakName <.> ".pak.tar.xz"
526+
pakURL = foundationPakURL </> ghcVersionString </> pakFileName
527+
printf "downloading %s into %s\n" pakURL pakDir
528+
createDirectoryIfMissing True pakDir
529+
callCommand $ printf "(cd %s ; curl -L %s -o %s)" pakDir pakURL pakFileName
530+
callCommand $ printf "(cd %s ; tar xf %s)" pakDir pakFileName
531+
callCommand $ printf "(cd %s ; rm %s)" pakDir pakFileName

0 commit comments

Comments
 (0)