Created
June 13, 2012 06:09
-
-
Save wuputah/2922172 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
$task_to_check = ARGV[0] | |
begin | |
require 'rake' | |
rescue LoadError => e | |
exit(4) | |
end | |
Rake.application.options.rakelib = ['rakelib'] | |
begin | |
Rake.application.raw_load_rakefile | |
rescue Exception => e | |
if e.is_a?(RuntimeError) && e.message =~ /^No Rakefile found/ | |
exit(5) | |
end | |
exit(2) | |
end | |
unless Rake::Task.task_defined?($task_to_check) | |
exit(3) | |
end | |
exit(0) | |
__END__ | |
exit codes: | |
0: task exists | |
1: this script raised an uncaught exception (from line 11) | |
2: exception while loading rakefile (app has a bug or depends on env) | |
3: Task doesnt exist | |
4: rake not present | |
5: rakefile not present | |
problems: | |
* The rakelib workaround might not work in all versions of rake | |
* Rake.application.raw_load_rakefile is not a public API for rake | |
* Brittle error message checking for exit code 5 | |
* $PWD probably matters; might need to chdir() to the right directory first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment