Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit 0cec10708abbb4f66f541b2f92037a0eea728921 0 parents
@gregorycollins authored
3  .gitignore
@@ -0,0 +1,3 @@
+dist/**
+dist
+*~
30 LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2008 Gregory D. Collins
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the author nor the names of his contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
156 Main.hs
@@ -0,0 +1,156 @@
+-- |
+-- Module : cabal2macpkg: convert cabal packages to OSX package format
+-- Copyright : (c) Gregory D. Collins, 2008
+-- License : BSD3
+--
+-- Maintainer: greg@gregorycollins.net
+-- Stability : early stage project
+--
+-- Loosely based on cabal2arch by Don Stewart.
+--
+-- Rough outline of the process:
+--
+-- 1) find a .cabal file in the current working directory
+-- 2) run "cabal build; cabal haddock" into a staging area
+-- 3) run "cabal register --gen-script" to generate a registration
+-- script that will be run by the OS X installer
+-- 4) turn the staging area into a mac package file using the OS X
+-- developer tools
+--
+-- A consequence of this quick n' dirty approach is that in order to
+-- build the installer for a cabal package, you need to have already
+-- installed all of its dependencies on the build machine.
+
+
+import Distribution.PackageDescription
+import Distribution.PackageDescription.Configuration
+import Distribution.PackageDescription.Parse
+import Distribution.Simple.Build
+import Distribution.Simple.Configure
+import Distribution.Simple.Setup
+import Distribution.Simple.Utils
+import Distribution.Verbosity as Verbosity
+
+import qualified Data.ByteString.Lazy as B
+
+import Control.Monad
+import Control.Concurrent
+import Control.Exception
+
+import Data.List
+import Data.Maybe
+import Data.Monoid
+import Data.Char
+import Debug.Trace
+
+import System.Directory
+import System.Exit
+import System.FilePath
+import System.IO
+import System.Process
+
+import System.Posix.User (getEffectiveUserName)
+
+
+main :: IO ()
+main = do
+ bracket getTempDirectory cleanupTempDirectory runMain
+
+
+runMain :: String -> IO ()
+runMain tmpdir = do
+ findPackageDesc "." >>= makeMacPkg tmpdir
+
+
+whoami :: IO String
+whoami = getEffectiveUserName
+
+
+makeMacPkg :: FilePath -> FilePath -> IO ()
+makeMacPkg tmpdir cabalFile = do
+ -- some portions of package building process require root
+ -- privileges
+ whoiam <- whoami
+
+ if whoiam /= "root" then
+ die "must be root to run cabal2macpkg"
+ else
+ return ()
+
+ -- build into our temporary directory
+ createDirectory stagingDir
+ let buildFlags = defaultBuildFlags { buildDistPref = toFlag stagingDir }
+ putStrLn $ "found a cabal file at '" ++ cabalFile ++ "'"
+
+ -- pkgDesc <- flattenPackageDescription $
+ -- readPackageDescription Verbosity.normal
+ -- cabalFile
+
+ pkgDesc <- flattenPackageDescription `liftM`
+ (readPackageDescription Verbosity.normal cabalFile)
+
+ let prefix = "/Library/Frameworks/GHC.framework/Versions/Current/usr"
+
+ runSetup "configure" ["--global", "--prefix=" ++ prefix]
+ runSetup "build" []
+ runSetup "haddock" []
+ runSetup "copy" ["--destdir=" ++ stagingDir]
+ runSetup "register" ["--gen-script"]
+
+ copyFile "register.sh" $ tmpdir </> "register.sh"
+ removeFile "register.sh"
+
+ --setRootPrivileges
+
+ putStrLn $ "tmpdir is " ++ tmpdir
+ where
+ cabalBuildDir = tmpdir </> "dist"
+ stagingDir = tmpdir </> "stage"
+
+ runSetup :: String -> [String] -> IO ()
+ runSetup cmd opts =
+ runCmd "runghc" $ ["Setup", cmd] ++ (mkOpts opts)
+
+ mkOpts s = s ++ ["--builddir=" ++ cabalBuildDir]
+
+
+-- |
+-- run a subprocess with the given arguments, ignoring the output. Die
+-- if the program returns an error.
+--
+runCmd :: String -> [String] -> IO ()
+runCmd cmd args = do
+ e <- rawSystem cmd args
+ case e of ExitSuccess -> return ()
+ ExitFailure _ -> die $ "command failed: " ++
+ cmd ++ " " ++ (Data.List.intercalate " " args)
+
+
+
+-- |
+-- grab a temporary directory and change into it. Returns the path to
+-- the new directory and the path to the old working directory.
+--
+getTempDirectory :: IO FilePath
+getTempDirectory =
+ do (ecode, out, err) <- readProcessWithExitCode
+ "mktemp"
+ ["-d", "-t", "cabal2macpkg"] []
+
+ case ecode of
+ ExitSuccess -> do
+ let dir = makeValid (init out)
+ return dir
+ ExitFailure _ -> die $ "mktemp failed, saying '" ++ err ++ "'"
+
+
+-- |
+-- removes the temporary directory and returns back to the previous
+-- cwd
+--
+cleanupTempDirectory :: FilePath -> IO ()
+cleanupTempDirectory dir = do
+ --removeDirectoryRecursive dir
+ return ()
+
+
35 README.text
@@ -0,0 +1,35 @@
+cabal2macpkg
+============
+
+This is (will be) a tool to turn cabal libraries into Macintosh
+packages. Cabal2macpkg is in its very early stages, and doesn't work
+yet, sorry.
+
+Status
+------
+Rough outline of the process:
+
+1. find a .cabal file in the current working directory
+2. run "cabal build; cabal haddock" into a staging area
+3. run "cabal register --gen-script" to generate a registration
+ script that will be run by the OS X installer
+4. turn the staging area into a mac package file using the OS X
+ developer tools
+
+I've gotten up to number three here.
+
+A consequence of this quick n' dirty approach is that in order to
+build the installer for a cabal package, you need to have already
+installed all of its dependencies on the build machine.
+
+
+TODO/Requirements
+-----------------
+
+First round:
+* get it generating a .pkg file for an individual cabal library
+* .pkg contents should be installable into any given prefix
+
+Next round:
+* Get it building a .mpkg metapackage from the haskell platform
+ toplevel project
3  Setup.lhs
@@ -0,0 +1,3 @@
+#!/usr/bin/env runhaskell
+> import Distribution.Simple
+> main = defaultMain
29 cabal2macpkg.cabal
@@ -0,0 +1,29 @@
+name: cabal2macpkg
+version: 0.1
+homepage: http://gregorycollins.net/
+synopsis: Create OSX installation packages from Cabal packages
+description: Create OSX installation packages from Cabal packages
+category: Distribution
+license: BSD3
+license-file: LICENSE
+author: Gregory D. Collins
+maintainer: greg@gregorycollins.net
+cabal-version: >= 1.6
+build-type: Simple
+
+executable cabal2macpkg
+ main-is: Main.hs
+ ghc-options: -Wall
+
+ build-depends:
+ base >= 3,
+ pretty,
+ process,
+ directory,
+ containers,
+ bytestring,
+ Cabal >= 1.6,
+ pureMD5 >= 0.2.1,
+ filepath,
+ unix
+
Please sign in to comment.
Something went wrong with that request. Please try again.