add HOST_PATH support#1
Conversation
HOST_PATH is set in Nixpkgs during cross-compilation to detect binaries available at runtime. It makes sure you get the right architecture in your cross-compiled binaries. When HOST_PATH is not set, fall back to PATH.
This does what we want
findExecutablesInDirectories was only added in 1.2.4.0.
| which :: FilePath -> IO (Maybe FilePath) | ||
| which f = fmap (fmap (T.unpack . Sh.toTextIgnore)) $ Sh.shelly $ Sh.which $ Sh.fromText $ T.pack f | ||
| which f = do | ||
| path <- runMaybeT $ MaybeT (lookupEnv "HOST_PATH") <|> MaybeT (lookupEnv "PATH") |
There was a problem hiding this comment.
How is the behavior different now compared to when we used which from Shelly?
There was a problem hiding this comment.
The only difference is that HOST_PATH is now used when it is available.
| | otherwise -> compileError $ "Path to executable " <> show f <> " was found in " <> show f' <> " which is not in /nix/store. Be sure to add the relevant package to 'backendTools' in default.nix." | ||
| | otherwise -> compileError $ | ||
| "Path to executable " <> show f <> " was found in " <> show f' | ||
| <> " which is not in /nix/store. Be sure to add the relevant package to 'backendTools' in default.nix." |
There was a problem hiding this comment.
This comment assumes that this package is being used in the context of an obelisk project, it seems. The reference to "backendTools in default.nix" should be changed.
There was a problem hiding this comment.
Oops, I removed this for my rhyolite PR https://github.com/obsidiansystems/rhyolite/pull/100/files#diff-8e11fb146d567575b09cdf4138230cebR24, but then copied my project's which to a separate package and accidentally re-introduced this.
| appendFile (bin3 </> "hello") "hello" | ||
| makeExecutable $ bin3 </> "hello" | ||
| appendFile (bin3 </> "hello2") "hello2" | ||
| -- makeExecutable $ bin3 </> "hello2" |
There was a problem hiding this comment.
This was just to make sure that non-executable files don't end up in which results.
|
|
||
| makeExecutable :: FilePath -> IO () | ||
| makeExecutable f = setPermissions f . setOwnerExecutable True =<< getPermissions f | ||
|
|
There was a problem hiding this comment.
Is there a test here that fails with the old Shelly implementation but passes now?
There was a problem hiding this comment.
Probably not, this was just to make sure the new implementation of which is correct.
|
What is HOST_PATH?
…On Wed, Sep 11, 2019, 21:18 Ali Abrar ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Please also update the changelog.
------------------------------
In src/System/Which.hs
<#1 (comment)>:
> which :: FilePath -> IO (Maybe FilePath)
-which f = fmap (fmap (T.unpack . Sh.toTextIgnore)) $ Sh.shelly $ Sh.which $ Sh.fromText $ T.pack f
+which f = do
+ path <- runMaybeT $ MaybeT (lookupEnv "HOST_PATH") <|> MaybeT (lookupEnv "PATH")
How is the behavior different now compared to when we used which from
Shelly?
------------------------------
In src/System/Which.hs
<#1 (comment)>:
> staticWhich :: FilePath -> Q Exp
staticWhich f = do
mf' <- runIO $ which f
case mf' of
Nothing -> compileError $ "Could not find executable for " <> show f
Just f'
| "/nix/store/" `isPrefixOf` f' -> [| f' |]
- | otherwise -> compileError $ "Path to executable " <> show f <> " was found in " <> show f' <> " which is not in /nix/store. Be sure to add the relevant package to 'backendTools' in default.nix."
+ | otherwise -> compileError $
+ "Path to executable " <> show f <> " was found in " <> show f'
+ <> " which is not in /nix/store. Be sure to add the relevant package to 'backendTools' in default.nix."
This comment assumes that this package is being used in the context of an
obelisk project, it seems. The reference to "backendTools in default.nix"
should be changed.
------------------------------
In test/Spec.hs
<#1 (comment)>:
> +setup :: IO (FilePath, FilePath, FilePath)
+setup = do
+ bin <- mkdtemp "bin"
+ bin2 <- mkdtemp "bin2"
+ bin3 <- mkdtemp "bin3"
+
+ appendFile (bin </> "hello") "hello"
+ makeExecutable $ bin </> "hello"
+ appendFile (bin2 </> "hello") "hello2"
+ makeExecutable $ bin2 </> "hello"
+ appendFile (bin2 </> "hello2") "hello2"
+ makeExecutable $ bin2 </> "hello2"
+ appendFile (bin3 </> "hello") "hello"
+ makeExecutable $ bin3 </> "hello"
+ appendFile (bin3 </> "hello2") "hello2"
+ -- makeExecutable $ bin3 </> "hello2"
Why is this commented out?
------------------------------
In test/Spec.hs
<#1 (comment)>:
> +import System.Directory
+import System.Environment
+import System.Exit
+import System.FilePath
+import System.Posix.Temp
+import System.Which
+
+shouldEqual :: Eq a => Show a => a -> a -> IO ()
+shouldEqual a b | a /= b = do
+ putStrLn $ show a <> " does not equal " <> show b
+ exitFailure
+shouldEqual a b = putStrLn $ show a <> " == " <> show b
+
+makeExecutable :: FilePath -> IO ()
+makeExecutable f = setPermissions f . setOwnerExecutable True =<< getPermissions f
+
Is there a test here that fails with the old Shelly implementation but
passes now?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1?email_source=notifications&email_token=AAI2KYDOKC3WZUABFGPGFX3QJGKEZA5CNFSM4IVZURI2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCEOZCHA#pullrequestreview-287150364>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAI2KYFX73LAUTGGTGSIH5DQJGKEZANCNFSM4IVZURIQ>
.
|
|
@ryantrinkle HOST_PATH is a Nix thing Matt and I added to distinguish between build-time executables and run-time executables, so when you cross compile you get a binary you can actually use. |
|
This should be done in a package called |
staticWhich already requires that which results be in |
|
I think we just need a version of |
So, we could make something like |
/cc @Ericson2314