Skip to content

Commit

Permalink
revise ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhuangxinyu1 committed Dec 5, 2019
1 parent 8e9a82b commit 6b51460
Show file tree
Hide file tree
Showing 6 changed files with 428 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ build/*
*.swp
*.log
*.out
tools/waf-plugins/*
*.swp
*.pyc
backend/tools/waf-plugins/*
backend/tools/.*
.lock-waf_linux2_build
src/build-*
*.pro.user
Expand Down
5 changes: 5 additions & 0 deletions backend/tools/waf-plugins/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local_rpath:
wget http://waf.googlecode.com/git-history/8dc822fded66db8041a0b71f3c7e451f6d07aa43/waflib/extras/local_rpath.py

unittest_gtest:
wget http://github.com/tanakh/waf-unittest/raw/master/unittest_gtest.py
39 changes: 39 additions & 0 deletions backend/tools/waf-plugins/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env python
# encoding: utf-8

def options(opt):
opt.add_option('-d', '--debug-level',
action = 'store',
default = 'release',
help = 'Specify the debugging level [debug, release]',
choices = [ 'debug', 'release' ],
dest = 'debug_level')

opt.load('compiler_cxx unittest_gtest lint')

def configure(conf):
conf.load('compiler_cxx local_rpath unittest_gtest lint')

conf.env.CXXFLAGS = [
'-Werror',
'-Wall',
'-Woverloaded-virtual',
'-Wextra',
'-Wfloat-equal',
'-Wno-unused-parameter',
'-Wno-unused-function' ]

if conf.options.debug_level == 'release':
conf.env.CXXFLAGS += [ '-O2' ]
else:
conf.env.CXXFLAGS += [ '-g' ]
conf.env.DEFINES += [ 'DEBUG' ]

#######################################
# Tag to disable program installation
#######################################
from waflib.TaskGen import before, feature
@feature('noinst')
@before('apply_link')
def no_inst(self):
self.install_path = None
85 changes: 85 additions & 0 deletions backend/tools/waf-plugins/lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#! /usr/bin/env python
# encoding: utf-8

import os

def configure(conf):
conf.find_program('cpplint.py', var='LINT', path_list=[os.path.dirname(Context.waf_dir)])

#########################################
# Lint
#########################################
from waflib.TaskGen import before, feature, after_method
from waflib import Task, Context

lint_ignore_patterns = set(['unittest-gtest'])
def add_lint_ignore(pattern):
lint_ignore_patterns.add(pattern)

def lint_should_ignore(path):
for pattern in lint_ignore_patterns:
if pattern in path:
return True
return False

files_linted = set()

@feature('cxx')
@after_method('process_source')
def add_files_to_lint(self):
if self.target != 'testprog':
for task in self.compiled_tasks:
if not task.inputs[0] in files_linted:
files_linted.add(task.inputs[0])
lint = self.create_task('lint', task.inputs[0])
lint.source_task = task
lint.lint_done = False

to_lint = set()

class lint(Task.Task):
after = [ 'cxx' ]

def __init__(self, *k, **kw):
Task.Task.__init__(self, *k, **kw)
self.lint_done = True

def runnable_status(self):
if not self.lint_done:
for t in self.run_after:
if not t.hasrun:
return Task.ASK_LATER;
self.add_lint_tasks()

return Task.Task.runnable_status(self)

def add_lint_tasks(self):
bld = self.generator.bld
deps = bld.node_deps.get(self.source_task.uid())
for dep in deps:
if not dep in to_lint and not lint_should_ignore(dep.abspath()):
to_lint.add(dep)

task = Task.classes['lint'](env=self.env, generator=self.generator)
task.set_inputs(dep)

gen = bld.producer
gen.outstanding.insert(0, task)
gen.total += 1

self.lint_done = True

def run(self):
bld = self.generator.bld;
path = self.inputs[0].path_from(self.generator.bld.bldnode)
if lint_should_ignore(path):
return 0

# Execute lint
cmd = '%s %s' % (self.env['LINT'], path)
try:
bld.cmd_and_log(cmd, quiet=Context.BOTH, cwd=bld.variant_dir)
except Exception, e:
print(e.stderr)
return 1
return 0
20 changes: 20 additions & 0 deletions backend/tools/waf-plugins/local_rpath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2011 (ita)

from waflib.TaskGen import after_method, feature

@after_method('propagate_uselib_vars')
@feature('cprogram', 'cshlib', 'cxxprogram', 'cxxshlib', 'fcprogram', 'fcshlib')
def add_rpath_stuff(self):
all = self.to_list(getattr(self, 'use', []))
while all:
name = all.pop()
try:
tg = self.bld.get_tgen_by_name(name)
except:
continue

if hasattr(tg, 'link_task'):
self.env.append_value('RPATH', tg.link_task.outputs[0].parent.abspath())
all.extend(self.to_list(getattr(tg, 'use', [])))
Loading

0 comments on commit 6b51460

Please sign in to comment.