LoginSignup
1
1

More than 5 years have passed since last update.

WafでそれっぽいD言語環境構築た際のwscriptの内容について

Posted at

wafはpythoで書かれてるビルドツールです。
なんかD言語のコンパイル環境をある程度自動で作ってくれるとかで導入してみました。
pythonで書かれてるのでpythonが動く環境が必要です。

wafとか.dコードとかある環境は以下のとおり。

フォルダ環境

.sublime-projectとか.sublime-wokspaceとかはSublimeText2で使っているプロジェクト関連のファイルなので無視して下さい。

wafがコンパイルツール本体。wscriptがビルドルールを記述してます。
.dファイルのimport関係(Phobosは除外)は以下のとおり

  • src/main.dがsrc/unipa/courceinfo.dと/src/unipa/webdata.dをimport
  • /src/unipa/courceinfo.dはなし
  • /src/unipa/webdata.dがsrc/unipa/courceinfo.dをimport

ただ、/src/unipa/courceinfo.dはstd.net.curlをimportしてるので、curlのライブラリ参照とかしないといけないです。

では、wscriptの中身を

wscript
import os.path

APPNAME='UNIPA_UFCS'
VERSION='1.0'

top='.'
out='./build'

def options(opt):
    opt.load('compiler_d')

def configure(conf):
    conf.load('compiler_d')

def build(bld):
    bld.add_post_fun(target_run)

    bld.program(
        source='./src/main.d ./src/unipa/webdata.d ./src/unipa/courceinfo.d',
        target=APPNAME,
        includes = './src/',
        libpath = '/dmd2/osx/lib',
        lib = 'curl'
        )

def target_run(ctx):
    ctx.exec_command(os.path.join(out, APPNAME) + '> result.txt')

APPNAMEは実行ファイルの名前、VIRSIONはそのまま、topはwscriptのあるフォルダ、outは.oとか実行ファイルとかの出力先です。
optionsとconfigureは上記の通り書くとD言語の開発環境に適した設定を構築してくれます。楽。
buildがビルドルール本体、bld.programにビルドのルール書きます。
色々書いてあります。まぁ大体意味は分かると思います。libpathとlibでcurlのライブラリ参照してたりとか。
bld.add_post_funの引数に関数を入れると、ビルドが成功した時に渡した関数を実行してくれます。
target_runはコンパイル成功時に実行ファイルを走らせて出力をresult.txtに出してます。

まぁ大体こんな感じです。

後はSublimeText2側でビルドの設定するとより幸せな環境になります。それはまた今度。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1