-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from idris-hackers/ipkg
add Ipkg support
- Loading branch information
Showing
11 changed files
with
204 additions
and
11 deletions.
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
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,37 @@ | ||
# IPKG files | ||
|
||
When you open a directory with a file at the top level in it that ends in `.ipkg`, all the commands | ||
in this package will read it and use it to find the path of your sources and resolve | ||
dependencies. | ||
|
||
Supported are the `opts` and `sourcedir` options. | ||
|
||
There is [more information](http://docs.idris-lang.org/en/latest/tutorial/packages.html) about `ipkg`-files in the idris documentation. | ||
|
||
|
||
## Example | ||
|
||
You have a folder that looks like this: | ||
|
||
``` | ||
src | ||
└───Main.idr | ||
└───OtherFile.idr | ||
your-project.ipkg | ||
``` | ||
|
||
with `your-project.ipkg` containing: | ||
|
||
``` | ||
package yourProject | ||
sourcedir = src | ||
modules = Main | ||
executable = yourExecutable | ||
main = Main | ||
opts = "-p lightyear" | ||
``` | ||
|
||
the package will search in the `src`-directory for your files and will | ||
load the dependencies specified in `opts`. |
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,15 @@ | ||
name: 'Idris Ipkg' | ||
scopeName: 'source.ipkg' | ||
fileTypes: ['ipkg'] | ||
patterns: | ||
[ | ||
{ | ||
name: 'keyword.control.ipkg' | ||
match: '\\b(package|opts|modules|sourcedir|makefile|objs|executable|main|libs)\\b' | ||
} | ||
{ | ||
name: 'string.quoted.double.ipkg' | ||
begin: '"' | ||
end: '"' | ||
} | ||
] |
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
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,63 @@ | ||
path = require 'path' | ||
fs = require 'fs' | ||
Rx = require 'rx-lite' | ||
|
||
optionsRegexp = /opts\s*=\s*\"([^\"]*)\"/ | ||
sourcedirRegexp = /sourcedir\s*=\s*([a-zA-Z/0-9.]+)/ | ||
|
||
# Find all ipkg-files in a directory and returns | ||
# an observable of an array of files | ||
findIpkgFile = (project) -> | ||
directory = project.getDirectories()[0].path | ||
readDir = Rx.Observable.fromNodeCallback fs.readdir | ||
|
||
r = readDir directory | ||
r | ||
.map (files) -> | ||
files | ||
.map (file) -> | ||
file: file | ||
directory: directory | ||
path: path.join directory, file | ||
ext: path.extname file | ||
.filter (file) -> | ||
file.ext == '.ipkg' | ||
|
||
parseIpkgFile = (fileInfo) -> | ||
(fileContents) -> | ||
optionsMatches = fileContents.match optionsRegexp | ||
sourcedirMatches = fileContents.match sourcedirRegexp | ||
|
||
compilerOptions = {} | ||
if optionsMatches | ||
compilerOptions.options = optionsMatches[1] | ||
|
||
compilerOptions.src = | ||
if sourcedirMatches | ||
path.join fileInfo.directory, sourcedirMatches[1] | ||
else | ||
fileInfo.directory | ||
|
||
compilerOptions | ||
|
||
readIpkgFile = (ipkgFile) -> | ||
readFile = Rx.Observable.fromNodeCallback fs.readFile | ||
readFile ipkgFile.path, | ||
encoding: 'utf8' | ||
|
||
# Find the ipkg file in the top directory of the project and return | ||
# the compiler options in it. | ||
compilerOptions = (project) -> | ||
ipkgFilesObserver = findIpkgFile project | ||
ipkgFilesObserver.flatMap (ipkgFiles) -> | ||
if ipkgFiles.length | ||
ipkgFile = ipkgFiles[0] | ||
readIpkgFile(ipkgFile) | ||
.map parseIpkgFile(ipkgFile) | ||
else | ||
Rx.Observable.return {} | ||
|
||
module.exports = | ||
findIpkgFile: findIpkgFile | ||
readIpkgFile: readIpkgFile | ||
compilerOptions: compilerOptions |
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,6 @@ | ||
# slow method to compare objects. | ||
objectEqual = (a, b) -> | ||
JSON.stringify(a) == JSON.stringify(b) | ||
|
||
module.exports = | ||
objectEqual: objectEqual |
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