summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-07-04 13:22:59 +0200
committerDavid Robillard <d@drobilla.net>2020-07-04 13:22:59 +0200
commit984e0cdb0f22cf227b87cb9c71cdf858dd6f64e5 (patch)
treed296081cb9e999b1a9088b78841c920f1b5b45c2
parentb6958e34a03488f5615c91c5e1e29c0085e324cb (diff)
downloadautowaf-984e0cdb0f22cf227b87cb9c71cdf858dd6f64e5.tar.gz
autowaf-984e0cdb0f22cf227b87cb9c71cdf858dd6f64e5.tar.bz2
autowaf-984e0cdb0f22cf227b87cb9c71cdf858dd6f64e5.zip
Cleanup: Fix top-level Python spacing
Fixes flake8 warning E302.
-rw-r--r--extras/autowaf.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/extras/autowaf.py b/extras/autowaf.py
index 8c314b5..871a282 100644
--- a/extras/autowaf.py
+++ b/extras/autowaf.py
@@ -20,11 +20,13 @@ else:
# import preproc
# preproc.go_absolute = True
+
@feature('c', 'cxx')
@after('apply_incpaths')
def include_config_h(self):
self.env.append_value('INCPATHS', self.bld.bldnode.abspath())
+
class OptionsContext(Options.OptionsContext):
def __init__(self, **kwargs):
super(OptionsContext, self).__init__(**kwargs)
@@ -39,6 +41,7 @@ class OptionsContext(Options.OptionsContext):
group.add_option('--' + name, action='store_true',
dest=name.replace('-', '_'), help=desc)
+
def set_options(opt, debug_by_default=False):
"Add standard autowaf options"
opts = opt.get_option_group('Configuration options')
@@ -101,6 +104,7 @@ def set_options(opt, debug_by_default=False):
run_opts.add_option('--cmd', type='string', dest='cmd',
help='command to run from build directory')
+
class ConfigureContext(Configure.ConfigurationContext):
"""configures the project"""
@@ -146,6 +150,7 @@ def get_check_func(conf, lang):
else:
Logs.error("Unknown header language `%s'" % lang)
+
def check_header(conf, lang, name, define='', mandatory=True):
"Check for a header"
check_func = get_check_func(conf, lang)
@@ -156,6 +161,7 @@ def check_header(conf, lang, name, define='', mandatory=True):
else:
check_func(header_name=name, mandatory=mandatory)
+
def check_function(conf, lang, name, **args):
"Check for a function"
header_names = Utils.to_list(args['header_name'])
@@ -179,10 +185,12 @@ int main(void) {
args['msg'] = 'Checking for %s' % name
check_func(fragment=fragment, **args)
+
def nameify(name):
return (name.replace('/', '_').replace('++', 'PP')
.replace('-', '_').replace('.', '_'))
+
def check_pkg(conf, spec, **kwargs):
"Check for a package iff it hasn't been checked for yet"
@@ -224,6 +232,7 @@ def check_pkg(conf, spec, **kwargs):
conf.system_include_paths.update(
conf.env['INCLUDES_' + nameify(kwargs['uselib_store'])])
+
def normpath(path):
if sys.platform == 'win32':
return os.path.normpath(path).replace('\\', '/')
@@ -384,6 +393,7 @@ def configure(conf):
conf.env.prepend_value('CFLAGS', '-I' + os.path.abspath('.'))
conf.env.prepend_value('CXXFLAGS', '-I' + os.path.abspath('.'))
+
def display_summary(conf, msgs=None):
if len(conf.stack_path) == 1:
display_msg(conf, "Install prefix", conf.env['PREFIX'])
@@ -397,6 +407,7 @@ def display_summary(conf, msgs=None):
if msgs is not None:
display_msgs(conf, msgs)
+
def set_c_lang(conf, lang):
"Set a specific C language standard, like 'c99' or 'c11'"
if conf.env.MSVC_COMPILER:
@@ -408,6 +419,7 @@ def set_c_lang(conf, lang):
msg="Checking for flag '%s'" % flag)
conf.env.append_unique('CFLAGS', [flag])
+
def set_cxx_lang(conf, lang):
"Set a specific C++ language standard, like 'c++11', 'c++14', or 'c++17'"
if conf.env.MSVC_COMPILER:
@@ -420,6 +432,7 @@ def set_cxx_lang(conf, lang):
msg="Checking for flag '%s'" % flag)
conf.env.append_unique('CXXFLAGS', [flag])
+
def set_modern_c_flags(conf):
"Use the most modern C language available"
if 'COMPILER_CC' in conf.env:
@@ -433,6 +446,7 @@ def set_modern_c_flags(conf):
conf.env.append_unique('CFLAGS', [flag])
break
+
def set_modern_cxx_flags(conf, mandatory=False):
"Use the most modern C++ language available"
if 'COMPILER_CXX' in conf.env:
@@ -446,6 +460,7 @@ def set_modern_cxx_flags(conf, mandatory=False):
conf.env.append_unique('CXXFLAGS', [flag])
break
+
def set_local_lib(conf, name, has_objects):
var_name = 'HAVE_' + nameify(name.upper())
conf.define(var_name, 1)
@@ -459,12 +474,14 @@ def set_local_lib(conf, name, has_objects):
conf.env['AUTOWAF_LOCAL_HEADERS'] = {}
conf.env['AUTOWAF_LOCAL_HEADERS'][name.lower()] = True
+
def append_property(obj, key, val):
if hasattr(obj, key):
setattr(obj, key, getattr(obj, key) + val)
else:
setattr(obj, key, val)
+
@feature('c', 'cxx')
@before('apply_link')
def version_lib(self):
@@ -475,6 +492,7 @@ def version_lib(self):
if [x for x in applicable if x in self.features]:
self.target = self.target + 'D'
+
def set_lib_env(conf,
name,
version,
@@ -506,6 +524,7 @@ def set_lib_env(conf,
conf.run_env.append_unique(lib_path_name, [lib_path])
conf.define(NAME + '_VERSION', version)
+
def display_msg(conf, msg, status=None, color=None):
color = 'CYAN'
if type(status) == bool and status:
@@ -518,18 +537,22 @@ def display_msg(conf, msg, status=None, color=None):
Logs.pprint('BOLD', ":", sep='')
Logs.pprint(color, status)
+
def display_msgs(conf, msgs):
for k, v in msgs.items():
display_msg(conf, k, v)
+
def link_flags(env, lib):
return ' '.join(map(lambda x: env['LIB_ST'] % x,
env['LIB_' + lib]))
+
def compile_flags(env, lib):
return ' '.join(map(lambda x: env['CPPPATH_ST'] % x,
env['INCLUDES_' + lib]))
+
def build_pc(bld, name, version, version_suffix, libs, subst_dict={}):
"""Build a pkg-config file for a library.
@@ -584,6 +607,7 @@ def build_pc(bld, name, version, version_suffix, libs, subst_dict={}):
obj.__dict__.update(subst_dict)
+
def make_simple_dox(name):
"Clean up messy Doxygen documentation after it is built"
name = name.lower()
@@ -625,6 +649,7 @@ def make_simple_dox(name):
finally:
os.chdir(top)
+
def build_dox(bld, name, version, srcdir, blddir, outdir='', versioned=True):
"""Build Doxygen API documentation"""
if not bld.env['DOCS']:
@@ -664,6 +689,7 @@ def build_dox(bld, name, version, srcdir, blddir, outdir='', versioned=True):
bld.path.get_bld().ant_glob('doc/man/man%d/*' % i,
excl='**/_*'))
+
def build_version_files(header_path, source_path, domain, major, minor, micro):
"""Generate version code header"""
header_path = os.path.abspath(header_path)
@@ -696,6 +722,7 @@ def build_version_files(header_path, source_path, domain, major, minor, micro):
return None
+
def build_i18n_pot(bld, srcdir, dir, name, sources, copyright_holder=None):
Logs.info('Generating pot file from %s' % name)
pot_file = '%s.pot' % name
@@ -714,6 +741,7 @@ def build_i18n_pot(bld, srcdir, dir, name, sources, copyright_holder=None):
Logs.info('Updating ' + pot_file)
subprocess.call(cmd, cwd=os.path.join(srcdir, dir))
+
def build_i18n_po(bld, srcdir, dir, name, sources, copyright_holder=None):
pwd = os.getcwd()
os.chdir(os.path.join(srcdir, dir))
@@ -728,6 +756,7 @@ def build_i18n_po(bld, srcdir, dir, name, sources, copyright_holder=None):
subprocess.call(cmd)
os.chdir(pwd)
+
def build_i18n_mo(bld, srcdir, dir, name, sources, copyright_holder=None):
pwd = os.getcwd()
os.chdir(os.path.join(srcdir, dir))
@@ -744,11 +773,13 @@ def build_i18n_mo(bld, srcdir, dir, name, sources, copyright_holder=None):
subprocess.call(cmd)
os.chdir(pwd)
+
def build_i18n(bld, srcdir, dir, name, sources, copyright_holder=None):
build_i18n_pot(bld, srcdir, dir, name, sources, copyright_holder)
build_i18n_po(bld, srcdir, dir, name, sources, copyright_holder)
build_i18n_mo(bld, srcdir, dir, name, sources, copyright_holder)
+
class ExecutionEnvironment:
"""Context that sets system environment variables for program execution"""
def __init__(self, changes):
@@ -773,6 +804,7 @@ class ExecutionEnvironment:
def __exit__(self, type, value, traceback):
os.environ = self.original_environ
+
class RunContext(Build.BuildContext):
"runs an executable from the build directory"
cmd = 'run'
@@ -792,6 +824,7 @@ class RunContext(Build.BuildContext):
else:
Logs.error("error: Missing --cmd option for run command")
+
def show_diff(from_lines, to_lines, from_filename, to_filename):
import difflib
import sys
@@ -806,6 +839,7 @@ def show_diff(from_lines, to_lines, from_filename, to_filename):
return same
+
def test_file_equals(patha, pathb):
import filecmp
import io
@@ -822,12 +856,14 @@ def test_file_equals(patha, pathb):
with io.open(pathb, 'rU', encoding='utf-8') as fb:
return show_diff(fa.readlines(), fb.readlines(), patha, pathb)
+
def bench_time():
if hasattr(time, 'perf_counter'): # Added in Python 3.3
return time.perf_counter()
else:
return time.time()
+
class TestOutput:
"""Test output that is truthy if result is as expected"""
def __init__(self, expected, result=None):
@@ -840,11 +876,13 @@ class TestOutput:
__nonzero__ = __bool__
+
def is_string(s):
if sys.version_info[0] < 3:
return isinstance(s, basestring)
return isinstance(s, str)
+
class TestScope:
"""Scope for running tests that maintains pass/fail statistics"""
def __init__(self, tst, name, defaults):
@@ -964,6 +1002,7 @@ class TestScope:
return output
+
class TestContext(Build.BuildContext):
"runs test suite"
fun = cmd = 'test'
@@ -1139,6 +1178,7 @@ class TestContext(Build.BuildContext):
except Exception:
Logs.warn('Failed to run lcov to generate coverage report')
+
class TestGroup:
def __init__(self, tst, suitename, name, **kwargs):
self.tst = tst
@@ -1178,6 +1218,7 @@ class TestGroup:
self.tst.log_bad('-' * 10, '%d/%d tests from %s (%d ms total)',
n_passed, scope.n_total, self.label(), duration)
+
def run_ldconfig(ctx):
should_run = (ctx.cmd == 'install' and
not ctx.env['RAN_LDCONFIG'] and
@@ -1193,6 +1234,7 @@ def run_ldconfig(ctx):
except Exception:
pass
+
def run_script(cmds):
for cmd in cmds:
subprocess.check_call(cmd, shell=True)