Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #!/usr/bin/env runghc
 - import System.FilePath
 - import System.Environment
 - import System.Process
 - import System.Exit
 - import System.Posix.Process
 - import System.Directory
 - import Data.Char (isSpace)
 - -- Remove trailing whitespace
 - rstrip = reverse . dropWhile isSpace . reverse
 - -- Prints a sequence of string pairs to stdout
 - printEnv = mapM_ $ \(k, v) -> putStrLn $ k ++ ": " ++ v
 - main = do
 - args <- getArgs
 - let installArgs = takeWhile ((==) '-' . head) args
 - let package:packageArgs =
 - if null remainder
 - then ["."] else remainder
 - where remainder = drop (length installArgs) args
 - gOBIN <- getTemporaryDirectory
 - -- Take our environment and clobber GOBIN.
 - installEnv <- getEnvironment >>= return . (:) ("GOBIN", gOBIN)
 - -- Run go install with modified environment.
 - (_, _, _, handle) <- createProcess
 - (proc "go" $ "install":installArgs++[package])
 - { env = Just installEnv }
 - code <- waitForProcess handle
 - case code of
 - ExitSuccess -> return ()
 - ExitFailure _ -> exitWith code
 - gOEXE <- readProcess "go" ["env", "GOEXE"] "" >>= return . rstrip
 - let exeFilePath = joinPath [gOBIN, packageBase <.> gOEXE]
 - where packageBase = last . splitDirectories $ package
 - in executeFile exeFilePath False packageArgs Nothing
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment