-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve packaging support for staticWhich usage #4
Open
matthewbauer
wants to merge
17
commits into
obsidiansystems:develop
Choose a base branch
from
matthewbauer:allow-packaging-which
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9ee3342
Format long lines
matthewbauer c9c16e2
Specify exports in System.Which
matthewbauer bb693e1
Use HOST_PATH where available
matthewbauer b392f92
Add gitignore
matthewbauer 2c77380
Use findExecutablesInDirectories from directory
matthewbauer dd815ee
Add test suite
matthewbauer 19e1c47
Bump version to 0.2.0.0
matthewbauer 0ebf7c0
Cleanup
matthewbauer 16cdd63
Tighten directory bounds
matthewbauer 88a23fb
Cleanup test suite
matthewbauer a437030
Fix missing mappend in pre-8.4 ghc
matthewbauer f3e516b
Update template haskell error
matthewbauer e22ae84
Add comment on bin3/hello2
matthewbauer 571d577
Update template haskell error
matthewbauer 04da6f3
Don’t require which results to be in /nix/store
matthewbauer 03cd9da
Merge branch 'host-which' into allow-packaging-which
matthewbauer 68cb31f
Add fallback when Nix path does not exist
matthewbauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist-newstyle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import Control.Exception | ||
import Data.List | ||
import Data.Monoid ((<>)) | ||
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 | ||
|
||
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" | ||
|
||
-- Don’t make this one executable to make sure we don’t resolve | ||
-- non-executable exes below. | ||
-- makeExecutable $ bin3 </> "hello2" | ||
|
||
appendFile (bin3 </> "hello3") "hello3" | ||
makeExecutable $ bin3 </> "hello3" | ||
|
||
pure (bin, bin2, bin3) | ||
|
||
cleanup :: (FilePath, FilePath, FilePath) -> IO () | ||
cleanup (bin, bin2, bin3) = do | ||
removeDirectoryRecursive bin | ||
removeDirectoryRecursive bin2 | ||
removeDirectoryRecursive bin3 | ||
|
||
main :: IO () | ||
main = bracket setup cleanup $ \(bin, bin2, bin3) -> do | ||
unsetEnv "PATH" | ||
unsetEnv "HOST_PATH" | ||
|
||
fp <- which "hello" | ||
|
||
shouldEqual fp Nothing | ||
|
||
setEnv "PATH" $ concat $ intersperse ":" [bin, bin2, bin3] | ||
setEnv "HOST_PATH" $ concat $ intersperse ":" [bin, bin2] | ||
|
||
fp1 <- which "hello" | ||
fp2 <- which "hello2" | ||
fp3 <- which "hello3" | ||
|
||
shouldEqual fp1 (Just $ bin </> "hello") | ||
shouldEqual fp2 (Just $ bin2 </> "hello2") | ||
shouldEqual fp3 Nothing | ||
|
||
unsetEnv "PATH" | ||
|
||
fp4 <- which "hello" | ||
fp5 <- which "hello2" | ||
fp6 <- which "hello3" | ||
|
||
shouldEqual fp4 (Just $ bin </> "hello") | ||
shouldEqual fp5 (Just $ bin2 </> "hello2") | ||
shouldEqual fp6 Nothing | ||
|
||
unsetEnv "HOST_PATH" | ||
setEnv "PATH" $ concat $ intersperse ":" [bin3, bin2, bin] | ||
|
||
fp7 <- which "hello" | ||
fp8 <- which "hello2" | ||
fp9 <- which "hello3" | ||
|
||
shouldEqual fp7 (Just $ bin3 </> "hello") | ||
shouldEqual fp8 (Just $ bin2 </> "hello2") | ||
shouldEqual fp9 (Just $ bin3 </> "hello3") | ||
|
||
pure () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also check if it's executable?
Do we really want
"hello"
to map to./hello
and not ahello
that's on yourPATH
?