Archive

Posts Tagged ‘dialyzer’

erl命令行工具链的设计思路

November 25th, 2009 2 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: erl命令行工具链的设计思路

erlang otp标准发布包里面的命令行工具都在bin目录下
dialyzer
erlc
escript
typer

erlang的这些命令行工具基本上都是erl模块的c的wrapper, 最后都是调用erl来运行相应的模块完成任务。

实验如下:

root@nd-desktop:~# touch test.erl

root@nd-desktop:~# erlc -d test.erl
 erl -noinput -mode minimal -boot start_clean -s erl_compile compile_cmdline @cwd /root @files test.erl

首先crack erts/etc/common/escript.c:33 static int debug = 1; 让之显示调用参数

root@nd-desktop:~# escript test.erl
 erl +B -boot start_clean -noshell -run escript start -extra test.erl

我们可以清楚的看到是如何调用相应的模块的。

那我们再看下 erl

root@nd-desktop:/usr/src/otp_src_R13B03# cat bin/erl
#!/bin/sh
#
# %CopyrightBegin%
# 
# Copyright Ericsson AB 1996-2009. All Rights Reserved.
# 
# The contents of this file are subject to the Erlang Public License,
# Version 1.1, (the "License"); you may not use this file except in
# compliance with the License. You should have received a copy of the
# Erlang Public License along with this software. If not, it can be
# retrieved online at http://www.erlang.org/.
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
# 
# %CopyrightEnd%
#
ROOTDIR=/usr/src/otp_src_R13B03
BINDIR=$ROOTDIR/bin/i686-pc-linux-gnu
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\///'`
export EMU
export ROOTDIR
export BINDIR
export PROGNAME
exec $BINDIR/erlexec ${1+"$@"}

这个erl程序其实是个shell script, 简单的设置下环境变量 然后调用erlexec来调用相应的VM。

但是为什么其他的都是binary程序, 唯独erl是script呢。 我能想出的唯一理由是: OTP team的人为了我们方便修改erl的行为 特地用脚本来写, 这样用户就可以很方便的定制erl.

如果我的猜测没错的话,那么erlang真的很细心。

Post Footer automatically generated by wp-posturl plugin for wordpress.

Categories: Erlang探索 Tags: , ,