on master help sign in
Merge pull request #2728 from jeremy-w/jeremy-w/ipkg-allow-arbitrary-executable-names-2721
d2f892bNiklas Larsson
CHANGELOG+1−1
@@ -41,7 +41,7 @@ Tool updates
41 datatype
41 datatype
42* iPKG files have a new option `pkgs` which takes a comma-separated list
42* iPKG files have a new option `pkgs` which takes a comma-separated list
43 of package names that the idris project depends on. This reduces bloat
43 of package names that the idris project depends on. This reduces bloat
44− in the `opts` option with mutliple package declarations.
44+ in the `opts` option with multiple package declarations.
45
45
46Miscellaneous updates
46Miscellaneous updates
47---------------------
47---------------------
CONTRIBUTING.md+1−1
@@ -166,4 +166,4 @@ To help increase the chance of your pull request being accepted:
166* [General GitHub Documentation](https://help.github.com/).
166* [General GitHub Documentation](https://help.github.com/).
167
167
168
168
169−Adapted from the most excellent contributing files from the [Puppet project](https://github.com/puppetlabs/puppet) and [Factroy Girl Rails](https://github.com/thoughtbot/factory_girl_rails/blob/master/CONTRIBUTING.md)
169+Adapted from the most excellent contributing files from the [Puppet project](https://github.com/puppetlabs/puppet) and [Factory Girl Rails](https://github.com/thoughtbot/factory_girl_rails/blob/master/CONTRIBUTING.md)
CONTRIBUTORS+1
@@ -35,6 +35,7 @@ Adam Sandberg Eriksson
35Seo Sanghyeon
35Seo Sanghyeon
36Benjamin Saunders
36Benjamin Saunders
37Alexander Shabalin
37Alexander Shabalin
38+Jeremy W. Sherman
38Timo Petteri Sinnemäki
39Timo Petteri Sinnemäki
39JP Smith
40JP Smith
40startling
41startling
src/Pkg/PParser.hs+34−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP, ConstraintKinds #-}
2#if !(MIN_VERSION_base(4,8,0))
2#if !(MIN_VERSION_base(4,8,0))
3{-# LANGUAGE OverlappingInstances #-}
3{-# LANGUAGE OverlappingInstances #-}
4#endif
4#endif
@@ -14,6 +14,7 @@ import Idris.CmdOptions
14
14
15import Control.Monad.State.Strict
15import Control.Monad.State.Strict
16import Control.Applicative
16import Control.Applicative
17+import System.FilePath (takeFileName, isValid)
17
18
18import Util.System
19import Util.System
19
20
@@ -62,11 +63,41 @@ pPkg = do
62 eof
63 eof
63 return st
64 return st
64
65
66+
67+-- | Parses a filename.
68+-- |
69+-- | Treated for now as an identifier or a double-quoted string.
70+filename :: (MonadicParsing m, HasLastTokenSpan m) => m String
71+filename = (do
72+ filename <- token $
73+ -- Treat a double-quoted string as a filename to support spaces.
74+ -- This also moves away from tying filenames to identifiers, so
75+ -- it will also accept hyphens
76+ -- (https://github.com/idris-lang/Idris-dev/issues/2721)
77+ stringLiteral
78+ <|>
79+ -- Through at least version 0.9.19.1, IPKG executable values were
80+ -- possibly namespaced identifiers, like foo.bar.baz.
81+ show <$> fst <$> iName []
82+ if isValidFilename filename
83+ then return filename
84+ else fail "a filename must be non-empty and have no directory component")
85+ <?> "filename"
86+ where
87+ isValidFilename :: FilePath -> Bool
88+ isValidFilename path =
89+ and [isNonEmpty, isValidPath, hasNoDirectoryComponent]
90+ where
91+ isNonEmpty = path /= ""
92+ isValidPath = System.FilePath.isValid path
93+ hasNoDirectoryComponent = path == takeFileName path
94+
95+
65pClause :: PParser ()
96pClause :: PParser ()
66pClause = do reserved "executable"; lchar '=';
97pClause = do reserved "executable"; lchar '=';
67− exec <- fst <$> iName []
98+ exec <- filename
68 st <- get
99 st <- get
69− put (st { execout = Just (show exec) })
100+ put (st { execout = Just exec })
70 <|> do reserved "main"; lchar '=';
101 <|> do reserved "main"; lchar '=';
71 main <- fst <$> iName []
102 main <- fst <$> iName []
72 st <- get
103 st <- get
test/pkg002/Main.idrnew file+4
@@ -0,0 +1,4 @@
1+module Main
2+
3+main : IO ()
4+main = putStrLn "CouCou!"
test/pkg002/expectednew file+1
@@ -0,0 +1 @@
1+Type checking ./Main.idr
test/pkg002/runnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/env bash
2+### Test: IPKG executable names can be any namespaced identifier.
3+idris $@ --build test.ipkg
4+rm -f *.ibc
5+rm -f some.namespaced.identifier
test/pkg002/test.ipkgnew file+6
@@ -0,0 +1,6 @@
1+package test
2+
3+modules = Main
4+
5+main = Main
6+executable = some.namespaced.identifier
test/pkg003/Main.idrnew file+4
@@ -0,0 +1,4 @@
1+module Main
2+
3+main : IO ()
4+main = putStrLn "CouCou!"
test/pkg003/expectednew file+1
@@ -0,0 +1 @@
1+Type checking ./Main.idr
test/pkg003/runnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/env bash
2+### Test: IPKG executable names can be a quoted string
3+### containing a valid filename.
4+idris $@ --build test.ipkg
5+rm -f *.ibc
6+rm -f 'quoting-allows-hyphens and spaces? and fun stuff!'
test/pkg003/test.ipkgnew file+6
@@ -0,0 +1,6 @@
1+package test
2+
3+modules = Main
4+
5+main = Main
6+executable = "quoting-allows-hyphens and spaces? and fun stuff!"
test/pkg004/Main.idrnew file+4
@@ -0,0 +1,4 @@
1+module Main
2+
3+main : IO ()
4+main = putStrLn "CouCou!"
test/pkg004/expectednew file+6
@@ -0,0 +1,6 @@
1+Uncaught error: user error (test.ipkg:7:1: error: a filename
2+ must be non-empty and have no
3+ directory
4+ component, expected: space
5+<EOF>
6+^ )
test/pkg004/runnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/env bash
2+### Test: IPKG executable names CANNOT include a directory separator.
3+# TODO: Verify that a name like "a/b\c" is rejected by both *NIX and Windows
4+# (assuming these tests get run on Windows).
5+idris $@ --consolewidth 80 --nobanner --nocolor --build test.ipkg
6+rm -f *.ibc
test/pkg004/test.ipkgnew file+6
@@ -0,0 +1,6 @@
1+package test
2+
3+modules = Main
4+
5+main = Main
6+executable = "filenames/cannot include\a directory separator"