Waf编译器

https://gitlab.com/ita1024/waf
os.getcwd() //获取当前工作路径,不包含文件名

waf编译过程

cd ardupilot
./waf --help
./waf configure //cofigure后面不加命令,默认sitl配置
./waf copter

多旋翼固件arducopter存在于ardupilot/build/sitl/bin中。
编译是由ardupilot/waf.py脚本启动的,ardupilot/wscript.py是waf命令的解释脚本,不能缺少,否则无法编译。

waf.py

from __future__ import print_function
import subprocess
import os.path as p
import sys

d = p.dirname(p.realpath(__file__))
//__file__指“waf.py”
//os.path.realpath(__file__)指“/home/yxq/ardupilot/waf.py”
//os.path.dirname(os.path.realpath(__file__))指“/home/yxq/ardupilot”
waf_light = p.join(d, 'modules', 'waf', 'waf-light')
// waf_light= home/yxq/ardupilot/modules/waf/waf-light
python = sys.executable
// /usr/bin/python
try:
    subprocess.check_call([python, waf_light] + sys.argv[1:])
    //通过/usr/bin/python环境执行'home/yxq/ardupilot/modules/waf/waf-light'脚本及附加命令
   比如"./waf  configure”,那么sys.argv[0]返回‘./waf’,sys.argv[1]返回‘configure’。
后面的except部分,表示异常

waf_light.py:

waf_light.py是waf编译器的启动脚本,主函数“Scripting.waf_entry_point(cwd, VERSION, wafdir)”。

Scripting.py脚本:

def waf_entry_point(current_directory, version, wafdir):
参数:
current_directory:当前目录的绝对路径;
version: waf版本号
wafdir: waf library的绝对路径。

if Context.WAFVERSION != version: //版本号不匹配
    Logs.error('Waf script and library do not match', version, Context.WAFVERSION, wafdir )   //记录异常信息
    sys.exit(1)   //不正常退出
    Context.waf_dir = wafdir
    Context.run_dir = Context.launch_dir = current_directory
    start_dir = current_directory
    no_climb = os.environ.get('NOCLIMB')
    
    if len(sys.argv) >1:
        potential_wscript = os.path.join(current_directory, sys.argv[1])
        if os.path.basename(potential_wscript) == Context.WSCRIPT_FILE and os.path.isfile(potential_wscript): //os.path.basename(path)返回path最后的文件名; os.path.isfile(path),如果path是一个存在的文件,则返回True
        path = os.path.normpath(os.path.dirname(potential_wscript)) //os.path.dirname(path)返回文件所在目录;os.path.normpath(path)规范化路径
        start_dir = os.path.abspath(path) //绝对路径
        no_climb = True
        sys.argv.pop(1) 
    ctx = Context.creat_context('options')
    (options, commands, env) = ctx.parse_cmd_args(allow_unknown = True)
    if options.top:
        start_dir = Context.run_dir = Context.top_dir = options.top
        no_climb = True
    if options.out:
        Context.out_dir = options.out
    
    if not no_climb:
         for k in no_climb_commands:
              for y in commands:
                  if y.startswitch(k):
                      no_climb = True
                      break
      
     cur = start_dir
     while cur
         try:
             lst = os.listdir(cur)
         except OSError:
             lst = []
             Logs.error('Directory is unreadable!', cur)
          if Options.lockfile in lst:
              env = ConfigSet.ConfigSet()
              try:
                  env.load(os.path.join(cur, Options.lockfile))
                  ino = os.start(cur) [stat.ST_INO]
              except EnvironmentError
                  pass
              else:
                  for x in (env.run_dir, env.top_dir, env.out_dir):
                      if not x:
                          continue
                      if Utils.is_win32:
                          if cur == x:
                              load = True
                              break
                          else:
                              
                              try: 
                                  ino2 = os.stat(x) [stat.ST_INO]
                              except OSError:
                                      pass
                              else:
                                  if ino == ino2:
                                      load = True
                                      break
                  else:
                      Logs.warn(' invalid lock file in %s', cur)
                      load = False
                   if load:
                       Context.run_dir = env.run_dir
                       Context.top_dir = env.top_dir
                       Context.out_dir = env.out_dir
                       break
          

waf命令

查看:

cd ardupilot
./waf --help

commands有:

all:   builds all programs of all  group
bin:   builds all programs of bin group
build: excutes the build
check: builds all programs and run tests
check-all:  "waf check --alltests"
clean:   cleans the project
configure:  configures the project
dist:       makes a tarball for redistributing the sources
distcheck:  checks if the project compiles
distclean:   removes build folder and data
examples:   builds all programs of examples group
list: 
copter:     builds copter programs
plane:      builds plane programs
rover:      builds rover programs
tests:      builds all programs of tests group
tools:     builds all programs of tools group
uninstall:   removes the targets installed

options有:

--version: 查看版本   
-c COLORS:
-j JOBS: 选择处理器
-h:     查看help
--notests: 不执行单元测试
--alltests:  全部执行单元测试

Configuration options:

--out=OUT:  build dir for the project定义build文件存储位置
--top=TOP:  src dir for the project 定义源文件
--board=BOARD:  Target board to build
//linux, Pixhawk1, Pixhawk4, Pixracer, sitl
--debug:
--upload:  上传固件,比如waf copter --upload

Pixhwak4固件编译

cd ardupilot
./waf distclean //清除以前所有编译信息
./waf configure --board=Pixhawk4  //配置硬件

可以发现:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
对比sitl配置:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值