Adding an option to cabal-install

Hi, I was planning to make a small change to Fetch.hs to let it be used behind a proxy server, using the value of $http_proxy or $HTTP_PROXY where one of them exists -- hope that sounds OK? This is easy to do, but so that windows users can benefit it would be good to make this an option read from the config file and/or opts and I'm having a much harder time working out how to do that. I tried to mimic the way other options work but can't get it working. Can you point out why? Several of the functions below aren't expected to work properly but should allow this line to be read from .cabal/conf: http_proxy:http://proxy.server.com:80 But I get this:
$ ~/haskell/bin/cabal -v3 clean Config file warning: Unrecognized stanza on line 5 Configuration: compiler: GHC ... http_proxy: Nothing
Here are the main places that I thought I needed to make changes: -- added to Types.hs data Option = OptCompilerFlavor CompilerFlavor ... | OptHttpProxy ProxyInfo deriving (Eq,Show) data ConfigFlags = ConfigFlags { configCompiler :: CompilerFlavor, ... configHttpProxy :: Maybe ProxyInfo } deriving (Show) data ProxyInfo = ProxyInfo { proxyhost :: String , proxyport :: Int , proxyuser :: Maybe String , proxypass :: Maybe String } deriving (Show, Eq) -- added to Config.hs defaultConfigFlags = do ... return $ ConfigFlags { configCompiler = defaultCompiler ... , configHttpProxy = Nothing } configFieldDescrs :: [FieldDescr ConfigFlags] configFieldDescrs = configWriteFieldDescrs ++ map userInstallDirField installDirDescrs ++ map globalInstallDirField installDirDescrs ++ [proxyField] proxyField :: FieldDescr ConfigFlags proxyField = liftProxyField "http_proxy" (text . show) parseProxy configProxy (\p cfg -> cfg { configHttpProxy = p} ) {- This will need to be in IO, using getEnv to read the env vars by preference -} parseProxy :: ReadP r (Maybe ProxyInfo) parseProxy = do host <- munch1 (\c -> isAlphaNum c || c `elem` "_-.") char ':' port <- munch1 (\c -> isAlphaNum c) return $ Just (ProxyInfo host ((read port)::Int) Nothing Nothing) {- For consistency these functions should be in Distribution.ParseUtils -} configProxy :: ConfigFlags -> Maybe ProxyInfo configProxy = configHttpProxy liftProxyField :: String -> (a -> Doc) -> (ReadP a a) -> (b -> a) -> (a -> b -> b) -> FieldDescr b liftProxyField name showF readF get set = liftField get set $ field name showF readF ----------------------------------------------------- Thanks, Jim

On Sun, 2007-11-25 at 16:06 +0000, jim burton wrote:
Hi, I was planning to make a small change to Fetch.hs to let it be used behind a proxy server, using the value of $http_proxy or $HTTP_PROXY where one of them exists -- hope that sounds OK?
Yes, that'd be great.
This is easy to do, but so that windows users can benefit it would be good to make this an option read from the config file and/or opts and I'm having a much harder time working out how to do that.
Actually I'm just at the moment rewriting the way cabal-install handles command line arguments.
I tried to mimic the way other options work but can't get it working. Can you point out why? Several of the functions below aren't expected to work properly but should allow this line to be read from .cabal/conf:
http_proxy:http://proxy.server.com:80
Ok, seems sensible. (We seem to be using a convention like .cabal files with -'s in field names rather than _'s. It's only a minor consistency nit.)
But I get this:
$ ~/haskell/bin/cabal -v3 clean Config file warning: Unrecognized stanza on line 5
parseProxy :: ReadP r (Maybe ProxyInfo) parseProxy = do host <- munch1 (\c -> isAlphaNum c || c `elem` "_-.") char ':' port <- munch1 (\c -> isAlphaNum c) return $ Just (ProxyInfo host ((read port)::Int) Nothing Nothing)
So this doesn't work. It doesn't parse your example:
readP_to_S parseProxy "http://proxy.server.com:80" []
Though this does work:
readP_to_S parseProxy "proxy.server.com:80"
I would suggest not rewriting a parser for URIs and instead use the standard Network.URI which provides a URI data type and a parser. Duncan

Hi Duncan, On Tue, 2007-11-27 at 02:02 +0000, Duncan Coutts wrote:
Actually I'm just at the moment rewriting the way cabal-install handles command line arguments.
OK, I'll look out for your changes.
I tried to mimic the way other options work but can't get it working. Can you point out why? Several of the functions below aren't expected to work properly but should allow this line to be read from .cabal/conf:
http_proxy:http://proxy.server.com:80
Ok, seems sensible. (We seem to be using a convention like .cabal files with -'s in field names rather than _'s. It's only a minor consistency nit.)
I'll change that to http-proxy -- I thought _ looked out of place but was sticking with the name of the env var.
I would suggest not rewriting a parser for URIs and instead use the standard Network.URI which provides a URI data type and a parser.
Thanks, I didn't know a URI included usernames etc too. Then ProxyInfo isn't needed and we can just have Maybe URI. Jim.
Duncan

On Tue, 2007-11-27 at 09:35 +0000, jb162@brighton.ac.uk wrote:
Hi Duncan,
On Tue, 2007-11-27 at 02:02 +0000, Duncan Coutts wrote:
Actually I'm just at the moment rewriting the way cabal-install handles command line arguments.
OK, I'll look out for your changes.
It's pretty much all in now. I've got some further cleanups but I don't have time to get them polished now and I don't want to hold up your contributions. I can adapt any further cleanups after your proxy changes. You'll also note that there is now an upload command too. I don't know how uploads work with proxies. BTW, do you think it is necessary to put the http proxy in the ~/.cabal/config file? If it's just necessary for windows, perhaps we should be getting the value from the registry somewhere. It'd be nice if the HTTP library could do this for us - get the proxy from system's native way of configuring such things. Duncan
participants (3)
-
Duncan Coutts
-
jb162ï¼ brighton.ac.uk
-
jim burton