pythonプログラマーのruby 3日間(3)-構築ツール


構築上、ルビーはPythonより強くなります.
RubyはRake、Pythonはsconsかもしれませんが、pythonに使うならshovelを使うことができますが、このPythonには良い基準はありません.RakefileはRubyの基準です.
Rakeの概要
MakeはUNIXです® のネイティブユーティリティは、ソフトウェアのコンパイルプロセスを管理するために設計されています.ドキュメントを本にコンパイルしたり、Webサイトを維持したり、リリース版を削減したりするのに使用されている場合でも、多くの他の環境で使用するのに十分です.しかし、makeにも独自の制約がある.タブの空白領域と非タブの空白領域に依存する独自の構文があります.他の多くのツールはすでに拡張されており、AegisやAntなどのmakeの不足を補うことができますが、この2つにも独自の問題があります.Makeや類似のツールには改善の余地がありますが、ルビーハッカーを喜ばせることはできません.ここからどこへ行きますか.幸いなことに、いくつかのRubyオプションを使用することができます.RantはStefan Langによって作成されたツールです(参考資料を参照).Rantはまだ開発サイクルの初期段階にあるので、一人一人に適用できるほど成熟していない可能性があります.Jim Weirichが作成したRakeはRubyコミュニティで広く使われている成熟したシステムである.(転送保留Phodal's Blog Phodal's zenthink)RakeはRubyで記述され、Rubyを文法として使用するため、曲線が短い.RakeはRubyのメタプログラミング機能を用いて言語を拡張し,自動化タスクにより効率的に適応させる.Rakeに付属のrdocには、いくつかの利点が記載されています(最初の2つはmakeなどの他のタスク自動化ツールで共有されていることに注意してください):
  • ユーザーは、前提条件を使用してタスクを指定できます.
  • Rakeは、暗黙的なタスクをマージするためのルール・モードをサポートします.
  • Rakeは軽量級です.他のプロジェクトで単一のファイルとしてパブリッシュできます.Rakeに依存するプロジェクトでは、ターゲットシステムにRakeをインストールする必要はありません.

  • Rakefileイニシャル
    Rakeのインストール
    gem install rake
    ですが、通常はこれはすでにありますので、その前にRVMでRubyのバージョン管理を行うことをお勧めします.
    RVMの概要
    Ruby Version Manager、Rubyバージョンマネージャ、Rubyのバージョン管理とGemライブラリ管理(gemset)を含む.現在、Rubyのほとんどのバージョンがサポートされており、1.8.7、1.9.1、1.9.2、Ruby Enterprise Editonがあり、RVMによって複数のRubyバージョンを簡単に切り替えることができます.RVMはJRubyもサポートしています.
    RVMインストール
    curl -L https://get.rvm.io | bash -s stable
    残りの部分は、ネット上で書かれたガイドラインを参考にすることができます.
    #     ruby  
    rvm list known
    #    ruby  
    rvm install 1.9.3
    #        1.9.3, rvm list known            。
    #    ruby  
    rvm use 1.9.3
    #          ,    
    rvm use 1.9.3 --default 

    簡単なRakefile
    task :default do
      puts "Simple Rakefile Example"
    end
    

    実行結果
    Simple Rakefile Example
    [Finished in 0.2s]

    Shovel
    公式にはこう紹介されています
    Shovel is like Rake for python. Turn python functions into tasks simply, and access and invoke them from the command line. 'Nuff said. New Shovel also now has support for invoking the same tasks in the browser you'd normally run from the command line, without any modification to your shovel scripts.
    では
    git clone https://github.com/seomoz/shovel.git
    cd shovel
    python setup.py install 

    公式の例で
    fooがあります.py
    from shovel import task
    
    @task
    def howdy(times=1):
        '''Just prints "Howdy" as many times as requests.
        
        Examples:
            shovel foo.howdy 10
            http://localhost:3000/foo.howdy?15'''
        print('
    '.join(['Howdy'] * int(times)))
    shovelちょっと
            shovel foo.howdy 10
    

    C言語を構築するハロー、World
    Makefile
    Cコード
    #include<stdio.h>
    
    int main(){
    	printf("Hello,world
    "); return 0; }
    簡単なmakefileの例
    hello:c 
    	gcc hello.c -o hello
    clean:
    	rm hello
    実行:
    make

    helloの実行可能ファイルが生成され、実行されます
    make clean
    クリーンアップ.
    Rakefile
    task :default => :make
    
    file 'hello.o' => 'hello.c' do  
        `gcc -c hello.c`  
    end  
      
    task :make => 'hello.o' do  
        `gcc hello.o -o hello`  
    end  
      
    task :clean do  
        `rm -f *.o hello`  
    end  

    さらにRakeは、RubyのRakeがコンストラクションツールとして使われているようで、もちろん他の言語でもMakefileに代わることができるようになっています.
    Scons
    新しいSConstruct
    Program('hello.c')
    Program('hello.c')
    scons、プロセスは次のとおりです.
    phodal@linux-dlkp:~/helloworld> scons
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    gcc -o hello.o -c hello.c
    gcc -o hello hello.o
    scons: done building targets.
    

    まとめRakefile