From 92f36a1d31418e747eeaaaad03aeb85cec939d21 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 14 Nov 2017 14:59:51 -0400 Subject: still can't express custom-setup deps They need unix on non-windows, for Utility.Env, which Build.Configure uses, but cabal can't express that in a custom-setup stanza. To avoid this problem, Utility.Env would need to be moved into unix-compat.. --- Annex/Environment.hs | 1 - Assistant/Upgrade.hs | 1 - Build/Configure.hs | 2 +- Build/TestConfig.hs | 2 +- Git/CurrentRepo.hs | 1 - Git/Index.hs | 1 - Test.hs | 11 +++++------ Utility/Env.hs | 24 ++++++++++++++++++++++++ Utility/Env/Set.hs | 40 ---------------------------------------- Utility/Gpg.hs | 1 - Utility/Lsof.hs | 2 +- git-annex.cabal | 6 ------ 12 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 Utility/Env/Set.hs diff --git a/Annex/Environment.hs b/Annex/Environment.hs index 0ddf9d2b7..4f0fda986 100644 --- a/Annex/Environment.hs +++ b/Annex/Environment.hs @@ -14,7 +14,6 @@ import Utility.UserInfo import qualified Git.Config import Config import Utility.Env -import Utility.Env.Set {- Checks that the system's environment allows git to function. - Git requires a GECOS username, or suitable git configuration, or diff --git a/Assistant/Upgrade.hs b/Assistant/Upgrade.hs index d7491c30f..cd1be4d4e 100644 --- a/Assistant/Upgrade.hs +++ b/Assistant/Upgrade.hs @@ -15,7 +15,6 @@ import qualified Annex import Assistant.Alert import Assistant.DaemonStatus import Utility.Env -import Utility.Env.Set import Types.Distribution import Types.Transfer import Logs.Web diff --git a/Build/Configure.hs b/Build/Configure.hs index 5df6857b1..f51ceef79 100644 --- a/Build/Configure.hs +++ b/Build/Configure.hs @@ -7,7 +7,6 @@ module Build.Configure where import Control.Applicative import Control.Monad.IfElse import Control.Monad -import System.Directory import Build.TestConfig import Build.Version @@ -19,6 +18,7 @@ import Utility.Env import Utility.Exception import qualified Git.Version import Utility.DottedVersion +import Utility.Directory tests :: [TestCase] tests = diff --git a/Build/TestConfig.hs b/Build/TestConfig.hs index 6c7139595..f6ad2df6f 100644 --- a/Build/TestConfig.hs +++ b/Build/TestConfig.hs @@ -7,10 +7,10 @@ module Build.TestConfig where import Utility.Path import Utility.Monad import Utility.SafeCommand +import Utility.Directory import System.IO import System.FilePath -import System.Directory type ConfigKey = String data ConfigValue = diff --git a/Git/CurrentRepo.hs b/Git/CurrentRepo.hs index df074cf8b..69a679ee3 100644 --- a/Git/CurrentRepo.hs +++ b/Git/CurrentRepo.hs @@ -12,7 +12,6 @@ import Git.Types import Git.Construct import qualified Git.Config import Utility.Env -import Utility.Env.Set {- Gets the current git repository. - diff --git a/Git/Index.hs b/Git/Index.hs index 0898569b4..85ea480b5 100644 --- a/Git/Index.hs +++ b/Git/Index.hs @@ -10,7 +10,6 @@ module Git.Index where import Common import Git import Utility.Env -import Utility.Env.Set indexEnv :: String indexEnv = "GIT_INDEX_FILE" diff --git a/Test.hs b/Test.hs index be814bbb3..424c3aacc 100644 --- a/Test.hs +++ b/Test.hs @@ -95,7 +95,6 @@ import qualified Utility.Process import qualified Utility.Misc import qualified Utility.InodeCache import qualified Utility.Env -import qualified Utility.Env.Set import qualified Utility.Matcher import qualified Utility.Exception import qualified Utility.Hash @@ -143,7 +142,7 @@ runner = Just go subenv = "GIT_ANNEX_TEST_SUBPROCESS" runsubprocesstests opts Nothing = do pp <- Annex.Path.programPath - Utility.Env.Set.setEnv subenv "1" True + Utility.Env.setEnv subenv "1" True ps <- getArgs (Nothing, Nothing, Nothing, pid) <-createProcess (proc pp ps) exitcode <- waitForProcess pid @@ -1932,9 +1931,9 @@ ensuretmpdir = do isolateGitConfig :: IO a -> IO a isolateGitConfig a = Utility.Tmp.withTmpDir "testhome" $ \tmphome -> do tmphomeabs <- absPath tmphome - Utility.Env.Set.setEnv "HOME" tmphomeabs True - Utility.Env.Set.setEnv "XDG_CONFIG_HOME" tmphomeabs True - Utility.Env.Set.setEnv "GIT_CONFIG_NOSYSTEM" "1" True + Utility.Env.setEnv "HOME" tmphomeabs True + Utility.Env.setEnv "XDG_CONFIG_HOME" tmphomeabs True + Utility.Env.setEnv "GIT_CONFIG_NOSYSTEM" "1" True a cleanup :: FilePath -> IO () @@ -2120,7 +2119,7 @@ setTestMode testmode = do currdir <- getCurrentDirectory p <- Utility.Env.getEnvDefault "PATH" "" - mapM_ (\(var, val) -> Utility.Env.Set.setEnv var val True) + mapM_ (\(var, val) -> Utility.Env.setEnv var val True) -- Ensure that the just-built git annex is used. [ ("PATH", currdir ++ [searchPathSeparator] ++ p) , ("TOPDIR", currdir) diff --git a/Utility/Env.hs b/Utility/Env.hs index dfebd9868..c56f4ec23 100644 --- a/Utility/Env.hs +++ b/Utility/Env.hs @@ -16,6 +16,7 @@ import Control.Applicative import Data.Maybe import Prelude import qualified System.Environment as E +import qualified System.SetEnv #else import qualified System.Posix.Env as PE #endif @@ -41,6 +42,29 @@ getEnvironment = PE.getEnvironment getEnvironment = E.getEnvironment #endif +{- Sets an environment variable. To overwrite an existing variable, + - overwrite must be True. + - + - On Windows, setting a variable to "" unsets it. -} +setEnv :: String -> String -> Bool -> IO () +#ifndef mingw32_HOST_OS +setEnv var val overwrite = PE.setEnv var val overwrite +#else +setEnv var val True = System.SetEnv.setEnv var val +setEnv var val False = do + r <- getEnv var + case r of + Nothing -> setEnv var val True + Just _ -> return () +#endif + +unsetEnv :: String -> IO () +#ifndef mingw32_HOST_OS +unsetEnv = PE.unsetEnv +#else +unsetEnv = System.SetEnv.unsetEnv +#endif + {- Adds the environment variable to the input environment. If already - present in the list, removes the old value. - diff --git a/Utility/Env/Set.hs b/Utility/Env/Set.hs deleted file mode 100644 index fd8d5140d..000000000 --- a/Utility/Env/Set.hs +++ /dev/null @@ -1,40 +0,0 @@ -{- portable environment variables - - - - Copyright 2013 Joey Hess - - - - License: BSD-2-clause - -} - -{-# LANGUAGE CPP #-} - -module Utility.Env.Set where - -#ifdef mingw32_HOST_OS -import qualified System.Environment as E -import qualified System.SetEnv -#else -import qualified System.Posix.Env as PE -#endif - -{- Sets an environment variable. To overwrite an existing variable, - - overwrite must be True. - - - - On Windows, setting a variable to "" unsets it. -} -setEnv :: String -> String -> Bool -> IO () -#ifndef mingw32_HOST_OS -setEnv var val overwrite = PE.setEnv var val overwrite -#else -setEnv var val True = System.SetEnv.setEnv var val -setEnv var val False = do - r <- getEnv var - case r of - Nothing -> setEnv var val True - Just _ -> return () -#endif - -unsetEnv :: String -> IO () -#ifndef mingw32_HOST_OS -unsetEnv = PE.unsetEnv -#else -unsetEnv = System.SetEnv.unsetEnv -#endif diff --git a/Utility/Gpg.hs b/Utility/Gpg.hs index cbe1e4f82..94d588cd7 100644 --- a/Utility/Gpg.hs +++ b/Utility/Gpg.hs @@ -15,7 +15,6 @@ import qualified Build.SysConfig as SysConfig import System.Posix.Types import qualified System.Posix.IO import Utility.Env -import Utility.Env.Set #endif import Utility.Tmp import Utility.Format (decode_c) diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs index d8f0deb32..e3ed709ec 100644 --- a/Utility/Lsof.hs +++ b/Utility/Lsof.hs @@ -11,7 +11,7 @@ module Utility.Lsof where import Common import Build.SysConfig as SysConfig -import Utility.Env.Set +import Utility.Env import System.Posix.Types diff --git a/git-annex.cabal b/git-annex.cabal index 2180fe453..0d3681aa5 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -303,11 +303,6 @@ source-repository head type: git location: git://git-annex.branchable.com/ -custom-setup - Setup-Depends: base (>= 4.5), hslogger, split, unix-compat, process, - filepath, exceptions, bytestring, directory, IfElse, data-default, - utf8-string, Cabal - Executable git-annex Main-Is: git-annex.hs Build-Depends: @@ -996,7 +991,6 @@ Executable git-annex Utility.Dot Utility.DottedVersion Utility.Env - Utility.Env.Set Utility.Exception Utility.ExternalSHA Utility.FileMode -- cgit v1.2.3