@@ -17,7 +17,8 @@ import GHC (mkModule, mkModuleName)
1717import GHC.Paths (libdir )
1818import GHC.Unit (Definite (.. ), GenUnit (RealUnit ), stringToUnitId )
1919import System.FilePath (takeDirectory )
20- import System.OsPath (encodeFS )
20+ import System.OsPath (OsPath , encodeUtf , encodeFS )
21+ import System.OsPath.Extra (fromOsPath , toOsPath )
2122import qualified Types.Args
2223import Types.Args (
2324 Args (Args ),
@@ -62,7 +63,7 @@ data BuckArgs =
6263 moduleName :: Maybe String ,
6364 depModules :: Maybe String ,
6465 depUnits :: Maybe String ,
65- homeUnit :: Maybe String ,
66+ homeUnit :: Maybe OsPath ,
6667 workerTargetId :: Maybe TargetId ,
6768 pluginDb :: Maybe String ,
6869 env :: Map String String ,
@@ -120,7 +121,7 @@ options =
120121 withArg " --buck2-packagedb-dep" \ z a -> z {buck2PackageDbDep = Just a},
121122 withArg " --dep-modules" \ z a -> z {depModules = Just a},
122123 withArg " --dep-units" \ z a -> z {depUnits = Just a},
123- withArg " --home-unit" \ z a -> z {homeUnit = Just a},
124+ withOsPathArg " --home-unit" \ z a -> z {homeUnit = Just a},
124125 withArg " --extra-env-key" \ z a -> z {envKey = Just a},
125126 withArgErr " --extra-env-value" \ z a -> addEnv z a,
126127 withArg " --worker-target-id" \ z a -> z {workerTargetId = Just (TargetId a)},
@@ -153,12 +154,18 @@ options =
153154
154155 withArgErr name f = (name, \ argv z -> takeArg name argv (f z))
155156
157+ withOsPathArg name f = (name, \ argv z -> takeOsPathArg name argv (Right . f z))
158+
156159 takeArg name argv store = case argv of
157160 [] -> Left (name ++ " needs an argument" )
158161 arg : rest -> do
159162 new <- store arg
160163 Right (rest, new)
161164
165+ takeOsPathArg name argv store = takeArg name argv $ \ arg -> case encodeUtf arg of
166+ Left e -> Left (" could not encode " ++ name ++ " =" ++ arg ++ " : " ++ show e)
167+ Right p -> store p
168+
162169parseBuckArgs :: CommandEnv -> RequestArgs -> Either String BuckArgs
163170parseBuckArgs env =
164171 spin (emptyBuckArgs (coerce env)) . coerce
@@ -184,12 +191,12 @@ parseBuckArgs env =
184191decodeJsonArg ::
185192 FromJSON a =>
186193 String ->
187- String ->
194+ OsPath ->
188195 IO a
189196decodeJsonArg desc file =
190- eitherDecodeFileStrict' file >>= \ case
197+ eitherDecodeFileStrict' (fromOsPath file) >>= \ case
191198 Right a -> pure a
192- Left err -> throwIO (userError (" Invalid JSON in file for " ++ desc ++ " : " ++ err ++ " (" ++ file ++ " )" ))
199+ Left err -> throwIO (userError (" Invalid JSON in file for " ++ desc ++ " : " ++ err ++ " (" ++ fromOsPath file ++ " )" ))
193200
194201-- | @CompileHpt@ can either process a source file or pick a previously constructed @ModSummary@ from the module graph.
195202-- In the latter case, we need both a unit ID and a module name, which is ensured here.
@@ -217,8 +224,8 @@ parseField = \case
217224
218225toGhcArgs :: BuckArgs -> IO Args
219226toGhcArgs args = do
220- cachedDeps <- traverse (decodeJsonArg " --dep-modules" ) args. depModules
221- cachedBuildPlans <- traverse (decodeJsonArg " --dep-units" ) args. depUnits
227+ cachedDeps <- traverse (decodeJsonArg " --dep-modules" . toOsPath ) args. depModules
228+ cachedBuildPlans <- traverse (decodeJsonArg " --dep-units" . toOsPath ) args. depUnits
222229 -- Buck specifies @-B@, which can be used to include more packages in the global package DB.
223230 -- While this is done by @ghcWithPackages@ from nixpkgs, it is likely redundant, but doesn't hurt.
224231 -- In any case, we default to @libdir@ from @ghc-paths@, which returns the directory in the distribution used by the
0 commit comments