Permalink
Browse files

First draft of .pkg support for Leopard

  • Loading branch information...
1 parent 881f4d1 commit 1800952697fc7df7b57923b6e630795fcb1247cf @gregorycollins committed May 18, 2009
Showing with 117 additions and 31 deletions.
  1. +69 −0 Distribution/OSX/PackageInfo.hs
  2. +21 −28 Program/MakePackage.hs
  3. +26 −2 Program/Util.hs
  4. +1 −1 cabal2macpkg.cabal
@@ -0,0 +1,69 @@
+module Distribution.OSX.PackageInfo
+where
+
+import Data.Maybe
+
+import Text.XML.HXT.Arrow
+
+------------------------------------------------------------------------
+data PackageInfo = PackageInfo
+ { pinfo_installKBytes :: Int
+ , pinfo_numberOfFiles :: Int
+ , pinfo_id :: String
+ , pinfo_preinstall :: Maybe String
+ , pinfo_postinstall :: Maybe String }
+
+
+emptyPackageInfo :: PackageInfo
+emptyPackageInfo = PackageInfo {
+ pinfo_installKBytes = 0
+ , pinfo_numberOfFiles = 0
+ , pinfo_id = ""
+ , pinfo_preinstall = Nothing
+ , pinfo_postinstall = Nothing
+ }
+
+
+mkPreinstall :: ArrowXml a => Maybe String -> [ a n XmlTree ]
+mkPreinstall Nothing = []
+mkPreinstall (Just s) = [ mkelem "preinstall"
+ [ sattr "file" ("./" ++ s) ]
+ [] ]
+
+mkPostinstall :: ArrowXml a => Maybe String -> [ a n XmlTree ]
+mkPostinstall Nothing = []
+mkPostinstall (Just s) = [ mkelem "postinstall"
+ [ sattr "file" ("./" ++ s) ]
+ [] ]
+
+
+mkPackageInfo :: ArrowXml a => PackageInfo -> a n XmlTree
+mkPackageInfo (PackageInfo kb nf ident pre post) =
+ root [] [ mkelem "pkg-info"
+ [ sattr "format-version" "2"
+ , sattr "identifier" ident
+ , sattr "version" "1"
+ , sattr "install-location" "/"
+ , sattr "auth" "root" ]
+ [ mkelem "payload"
+ [ sattr "installKBytes" (show kb)
+ , sattr "numberOfFiles" (show nf) ]
+ []
+ , mkelem "scripts" []
+ (concat [ mkPreinstall pre, mkPostinstall post ] ) ]
+ ]
+
+
+
+writePackageInfo :: String -> PackageInfo -> IO ()
+writePackageInfo file pkg = runX (mkPackageInfo pkg
+ >>>
+ writeDocument [(a_indent, v_1)] file)
+ >> return ()
+
+packageInfoToString :: PackageInfo -> IO String
+packageInfoToString pkg = runX (mkPackageInfo pkg
+ >>>
+ writeDocumentToString [(a_indent, v_1)])
+ >>= return . concat
+
@@ -26,7 +26,7 @@ import Text.Regex
------------------------------------------------------------------------
-- local imports
-import Distribution.OSX.Info
+import Distribution.OSX.PackageInfo
import Program.Options
import Program.Util
@@ -84,7 +84,6 @@ makeMacPkg opts tmpdir pkgDesc = do
-- directories
cabalBuildDir = tmpdir </> "dist"
contentsDir = stagingDir </> "Contents"
- resourceDir = tmpdir </> "Resources"
scriptsDir = tmpdir </> "Scripts"
stagingDir = tmpdir </> "stage"
@@ -94,9 +93,8 @@ makeMacPkg opts tmpdir pkgDesc = do
-- output files
temporaryPkgConfig = tmpdir </> "temp.pkgconfig"
- infoPath = tmpdir </> "Info.plist"
- descInfoPath = resourceDir </> "Description.plist"
- postflightScriptFile = resourceDir </> "postflight"
+ infoPath = tmpdir </> "PackageInfo"
+ postflightScriptFile = scriptsDir </> "postflight"
outputPackageDir = fromMaybe "." (packageOutputDir opts)
@@ -113,14 +111,14 @@ makeMacPkg opts tmpdir pkgDesc = do
--------------------------------------------------------------------
-- creates necessary directories inside the work area
createDirectories =
- (createDirectoryIfMissing True) `mapM_` [stagingDir, scriptsDir,
- resourceDir, contentsDir]
+ (createDirectoryIfMissing True)
+ `mapM_` [stagingDir, scriptsDir, contentsDir]
--------------------------------------------------------------------
-- uses cabal to build the package into the work area
buildPackageContents = do
- runSetup "configure" ["--global", "--prefix=/usr/local"]
+ runSetup "configure" ["--global", "--prefix="++prefix]
runSetup "build" []
runSetup "haddock" []
runSetup "copy" ["--destdir=" ++ contentsDir]
@@ -144,19 +142,15 @@ makeMacPkg opts tmpdir pkgDesc = do
--------------------------------------------------------------------
- -- populate the package .info file in the resource directory
+ -- populate the packageinfo file in the resource directory
mkInfoFiles :: IO ()
mkInfoFiles = do
- writeFile infoPath (show pinfo)
- writeFile descInfoPath (show dpinfo)
- where
- pinfo = mkInfoPlist pkgBaseName
- pkgVersionString
- pkgDescription
- prefix
-
- dpinfo = mkDescriptionPlist pkgBaseName pkgVersionString
+ nf <- getNumFiles contentsDir
+ kb <- getFileSizesInKB contentsDir
+ let pinfo = PackageInfo kb nf ("haskell."++pkgTitle)
+ Nothing (Just "postinstall")
+ writePackageInfo infoPath pinfo
--------------------------------------------------------------------
@@ -176,18 +170,17 @@ makeMacPkg opts tmpdir pkgDesc = do
putStrLn $ "building " ++ outputPackagePath
hFlush stdout
- runCmd packageMakerCmd [ "-build"
- , "-p"
+ runCmd packageMakerCmd [ "-o"
, outputPackagePath
- , "-f"
+ , "--root"
, contentsDir
- , "-ds"
- , "-r"
- , resourceDir
- , "-i"
- , infoPath
- , "-d"
- , descInfoPath ]
+ , "--scripts"
+ , scriptsDir
+ , "--target"
+ , "10.5"
+ , "--root-volume-only"
+ , "--info"
+ , infoPath ]
View
@@ -1,6 +1,13 @@
-- | Utility functions
-module Program.Util(runCmd, getTempDirectory, cleanupTempDirectory, checkRootPrivileges)
-where
+module Program.Util
+ ( runCmd
+ , runCmdWithOutput
+ , getFileSizesInKB
+ , getNumFiles
+ , getTempDirectory
+ , cleanupTempDirectory
+ , checkRootPrivileges
+ ) where
@@ -36,6 +43,23 @@ runCmd cmd args = do
++ intercalate " " args
+runCmdWithOutput :: String
+ -> IO String
+runCmdWithOutput cmd = do
+ readProcess "sh" ["-c", cmd] ""
+
+
+getNumFiles :: FilePath -> IO Int
+getNumFiles fp =
+ runCmdWithOutput ("find '" ++ fp ++ "' -type f | wc -l")
+ >>= return . (read :: String -> Int)
+
+getFileSizesInKB :: FilePath -> IO Int
+getFileSizesInKB fp = do
+ txt <- runCmdWithOutput ("du -kd0 " ++ fp)
+ let (n,_) = span isDigit txt
+ return $ read n
+
------------------------------------------------------------------------
-- | grab a temporary directory. Produces the path to the new
View
@@ -25,7 +25,7 @@ executable cabal2macpkg
filepath,
hxt,
pretty,
- process == 1.0.1.0,
+ process,
pureMD5 >= 0.2.1,
regex-compat,
split,

0 comments on commit 1800952

Please sign in to comment.