Skip to content

Instantly share code, notes, and snippets.

@sahara-ooga
Last active June 10, 2019 11:13
Show Gist options
  • Save sahara-ooga/85b61e70eadf53c1f8d689c8a538ef0d to your computer and use it in GitHub Desktop.
Save sahara-ooga/85b61e70eadf53c1f8d689c8a538ef0d to your computer and use it in GitHub Desktop.
Rake memo

Rakeとは

Rakeは、MakeをRubyで実装したものを超越したビルドツールである。 世間では、ビルドツールというとMakeやApache Antが有名で、よく使われている。 Rakeは、これらのいいとこ取りをした上で、特有のフィーチャーを追加した新しいビルドツールであり、複雑なビルドを柔軟に書きこなすことができる。その秘密は内部DSLという仕組みにあり、このおかげでビルドの記述にRubyの強力な文法をそのまま使うことができる。この自由度の高さは、ビルドの記述に独自の言語の使用を選択したMakeとAntには無い強みだ。 その代わりと言ってはなんだが、Rubyにある程度習熟していないと扱えないツールである。

http://www2s.biglobe.ne.jp/~idesaku/sss/tech/rake/

Example

Compile Single Source Code

Source code (hello.c)

save as hello.c.

#include <stdio.h>

int main()
{
    printf("hello, world\n");
    return 0;
}

Rakefile

CC = "clang"

task :default => "hello"

file "hello" => ["hello.o"] do
  sh "#{CC} -o hello hello.o"
end

file "hello.o" => "hello.c" do
  sh "#{CC} -c hello.c"
end

Command & Result

$ gem install rake --remote # if needed
$ rake
clang -c hello.c
clang -o hello hello.o
$ ls
Rakefile        hello           hello.c         hello.o
$ ./hello
hello, world

Dependence of Tasks

task "dist" => ["init", "compile"] # task "タスク名" => ["依存するタスク1", "依存するタスク2"]

task "init"

task "compile"
$ rake -t dist
** Invoke dist (first_time)
** Invoke init (first_time)
** Execute init
** Invoke compile (first_time)
** Execute compile
** Execute dist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment