On Tue, May 29, 2007 at 09:33:54AM -0700, Andy Gill wrote:
> 
> My suggestion (after taking input from #ghc and #darcs) is
>  * Having a web page that contains the contexts (or hash numbers)
>   of the various darcs repos that went into making the latest
>   good build.
>  * This page also contains the darcs gets commands you type
>    to get this working copy.

I attempted to do something along these lines a while ago. I've attached
the summary mail, which in turn has attached the script I had.

If anyone is interested in making something usable from it then that
would be great! My impression seems to have been that it would require
some darcs hacking.


Thanks
Ian

--- Begin Message ---
Hi all,

Following on from a conversation with Thorkil a while ago, I've written
a script that in theory would allow us to make it easy to get a
known-working darcs GHC.

Basically, you run the attached Haskell program in a checked-out GHC tree
that you know works (e.g. because you're a nightly builder, and you just
sucessfully built it), and it creates another Haskell program that will
recreate the checked-out copy (in a nutshell, it works by running
"darcs changes --context" in each checkout and then writing a program
that does "darcs get --context ..." on each in turn). For the nightly
builders this would then appear on darcs.haskell.org somewhere, although
that bit isn't quite ready yet.

Unfortunately, there are some problems:

* It looks you you have to do a get rather than a pull, i.e. you can't
  just say "update this tree to the more recent one that works".

* If you do a --partial get then darcs falls over, even in the simple
  case where you want the whole thing.

* If you don't do --partial then it'll take ages. I haven't actually
  successfully tested it as I was testing with a 6.6 repo and it broke
  upon trying to do a full get of the partial 6.6 nofib repo, but it
  had taken 2 hours already to get that far.

I think that once 6.6.1 has released it'll be worth me at least looking
at darcs to see how much work would be involved in fixing either of the
first 2 problems. I'm not sure if fixing the second one would also fix
the other problems with --partial repos we've had.

So, not much good news in this e-mail really, I'm just letting you know
what the situation is. Feel free to play with the program should you
wish, of course.


Thanks
Ian

import Control.Concurrent
import Control.Concurrent.MVar
import Control.Exception
import Control.Monad
import Data.Word
import System.Directory
import System.Exit
import System.IO
import System.Process

type Verbosity = Int
type Directory = FilePath
type URL = String
type Context = String
type Depth = Int
type Acc = [(Directory, Context)]
type Data = [(URL, Directory, Context)]

main :: IO ()
main = do

    let verbosity = 0
        initial_depth = 2
        url_root = "http://darcs.haskell.org/ghc-6.6/";
        base_repo = "ghc"

    let debug :: Verbosity -> Depth -> String -> IO ()
        debug v n s = let s' = replicate (initial_depth - n) ' ' ++ s
                      in when (verbosity >= v) $ hPutStrLn stderr s'

        getContexts :: Directory -> Depth -> Acc -> IO Acc
        getContexts dir n acc
         = do debug 1 n ("In " ++ dir)
              subdirs <- getDirectoryContents "."
              let subdirs' = filter (`notElem` [".", "..", "_darcs"]) subdirs
                  isRepo = "_darcs" `elem` subdirs
              debug 2 n ("Potential subdirectories are " ++ show subdirs')
              acc' <- if n == 0
                      then return acc
                      else foldM (doSubdir dir (n-1)) acc subdirs'
              if isRepo then do debug 1 n "Getting my context"
                                getContext n dir acc'
                        else do debug 1 n "No context from me"
                                return acc'

        getContext :: Depth -> Directory -> Acc -> IO Acc
        getContext n dir acc
         = do let args = ["changes", "--context"]
              debug 1 n "Running darcs"
              (hin, hout, herr, ph) <-
                  runInteractiveProcess "darcs" args Nothing Nothing
              hClose hin
              mout <- newEmptyMVar
              merr <- newEmptyMVar
              forkIO $ do out <- hGetContents hout
                          evaluate $ length out
                          putMVar mout out
              forkIO $ do err <- hGetContents herr
                          evaluate $ length err
                          putMVar merr err
              ec <- waitForProcess ph
              out <- readMVar mout
              err <- readMVar merr
              case ec of
                  ExitSuccess
                   | null err ->
                      return ((dir, out):acc)
                  _ -> error "XXX"

        doSubdir :: Directory -> Depth -> Acc -> Directory -> IO Acc
        doSubdir dir n acc subdir
         = do e <- try $ setCurrentDirectory subdir
              case e of
                  Right () ->
                      do acc' <- getContexts (dir ++ "/" ++ subdir) n acc
                         setCurrentDirectory ".."
                         return acc'
                  Left e ->
                      -- XXX We assume that any error means it isn't
                      -- a directory
                      return acc

        mkData :: Acc -> Data
        mkData ((".", cxt):acc)
         = (url_root ++ "/" ++ base_repo, base_repo, cxt)
         : [ (url_root ++ "/" ++ d, base_repo ++ "/" ++ d, c) | (d, c) <- acc ]
        mkData _ = error "XXX"

    cs <- getContexts "." initial_depth []
    writeFile "foo.hs" ("\
\import System.Cmd\n\
\import System.Exit\n\
\\n\
\main :: IO ()\n\
\main = mapM_ getRepo the_data\n\
\\n\
\getRepo :: (String, String, String) -> IO ()\n\
\getRepo (url, dir, cxt)\n\
\ = do writeFile \"context\" cxt\n\
\      let args = [\"get\", \"--partial\", \"--context\", \"context\",\n\
\                  url, dir]\n\
\      putStrLn (\"Running darcs with \" ++ show args)\n\
\      ec <- rawSystem \"darcs\" args\n\
\      case ec of\n\
\          ExitSuccess -> return ()\n\
\          _ -> error (\"darcs returned \" ++ show ec)\n\
\\n\
\the_data :: [(String, String, String)]\n\
\the_data = " ++ show (mkData cs) ++ "\n\n")


--- End Message ---
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to