on master help sign in
Merge pull request #2728 from jeremy-w/jeremy-w/ipkg-allow-arbitrary-executable-names-2721

IPKG: Relax requirement that executable name be a valid identifier [#2721]

commitd2f892b502248429822df5bd51d8db9776e29e7c authorNiklas Larsson <metaniklas@gmail.com> dateWed 14 Oct 2015, 23:22 (11 years ago) parentaabda6e9229b62
16 files changed+92−5
CHANGELOG+1−1 CONTRIBUTING.md+1−1 CONTRIBUTORS+1 src/Pkg/PParser.hs+34−3 test/pkg002/Main.idr+4 test/pkg002/expected+1 test/pkg002/run+5 test/pkg002/test.ipkg+6 test/pkg003/Main.idr+4 test/pkg003/expected+1 test/pkg003/run+6 test/pkg003/test.ipkg+6 test/pkg004/Main.idr+4 test/pkg004/expected+6 test/pkg004/run+6 test/pkg004/test.ipkg+6
CHANGELOG+1−1
@@ -41,7 +41,7 @@ Tool updates
4141 datatype
4242* iPKG files have a new option `pkgs` which takes a comma-separated list
4343 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.
4545
4646Miscellaneous updates
4747---------------------
CONTRIBUTING.md+1−1
@@ -166,4 +166,4 @@ To help increase the chance of your pull request being accepted:
166166* [General GitHub Documentation](https://help.github.com/).
167167
168168
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
3535Seo Sanghyeon
3636Benjamin Saunders
3737Alexander Shabalin
38+Jeremy W. Sherman
3839Timo Petteri Sinnemäki
3940JP Smith
4041startling
src/Pkg/PParser.hs+34−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP, ConstraintKinds #-}
22#if !(MIN_VERSION_base(4,8,0))
33{-# LANGUAGE OverlappingInstances #-}
44#endif
@@ -14,6 +14,7 @@ import Idris.CmdOptions
1414
1515import Control.Monad.State.Strict
1616import Control.Applicative
17+import System.FilePath (takeFileName, isValid)
1718
1819import Util.System
1920
@@ -62,11 +63,41 @@ pPkg = do
6263 eof
6364 return st
6465
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+
6596pClause :: PParser ()
6697pClause = do reserved "executable"; lchar '=';
67− exec <- fst <$> iName []
98+ exec <- filename
6899 st <- get
69− put (st { execout = Just (show exec) })
100+ put (st { execout = Just exec })
70101 <|> do reserved "main"; lchar '=';
71102 main <- fst <$> iName []
72103 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"