Merge pull request #3 from steinwurf/add-to-buildbot

Add .astylerc, waf and related scripts
This commit is contained in:
Peter Vingelmann 2016-09-16 23:47:16 +02:00 committed by GitHub
commit 77516152ef
6 changed files with 474 additions and 0 deletions

26
.astylerc Normal file
View File

@ -0,0 +1,26 @@
# No backup files
--suffix=none
--exclude="build"
--exclude="bundle_dependencies"
--ignore-exclude-errors-x
--style=allman
--indent-namespaces
--pad-header
--unpad-paren
--convert-tabs
--indent=spaces=4
--indent-preproc-block
--align-pointer=type
--align-reference=type
--attach-extern-c
--keep-one-line-blocks
--keep-one-line-statements
--min-conditional-indent=0
--max-instatement-indent=50
--max-code-length=80
--break-after-logical
--lineend=linux

View File

@ -10,6 +10,54 @@ as closely as possible: http://docs.steinwurf.com/coding_style.html
Steinwurf uses heavily-templated C++11 code that can be a true challenge Steinwurf uses heavily-templated C++11 code that can be a true challenge
for a code formatting tool. for a code formatting tool.
Quick start
-----------
If you already installed a C++11 compiler, git and python on your system,
then you can clone this repository to a suitable folder::
git clone git@github.com:steinwurf/astyle.git
Configure and build the project (use the ``cxx_default`` mkspec, because
fabric will look for the ``astyle`` binary at this default location)::
cd astyle
python waf configure --cxx_mkspec=cxx_default
python waf build
Running astyle manually
-----------------------
First of all, you should copy the ``.astylerc`` options file to your home
folder.
On Unix systems::
cp .astylerc ~
On Windows::
copy .astylerc %USERPROFILE%\astylerc
After this, you can call ``astyle`` to format a single file (be careful,
because **it will not make a backup** for the original file)::
build/cxx_default/astyle test.cpp --print-changes
The ``--print-changes`` option prints out every line that is changed
during the formatting. This is especially useful with the ``--dry-run``
option that will not write any modifications to the file::
build/cxx_default/astyle test.cpp --print-changes --dry-run
**Warning**: Be careful about the working directory if you invoke the
following command, because you can accidentally format a lot of files!
You can format all C/C++ source files within the current directory with the
recursive search (``-R``) option::
cd my-project
path/to/astyle -Q -R *.cpp *.hpp *.c *.h --print-changes
With the ``-Q`` option, astyle will only display information about the
formatted files (it will not list the unchanged files).

107
buildbot.py Normal file
View File

@ -0,0 +1,107 @@
#!/usr/bin/env python
# encoding: utf-8
import os
import sys
import json
import subprocess
project_name = 'astyle'
def run_command(args):
print("Running: {}".format(args))
sys.stdout.flush()
subprocess.check_call(args)
def get_tool_options(properties):
options = []
if 'tool_options' in properties:
# Make sure that the values are correctly comma separated
for key, value in properties['tool_options'].items():
if value is None:
options += ['--{0}'.format(key)]
else:
options += ['--{0}={1}'.format(key, value)]
return options
def configure(properties):
command = [sys.executable, 'waf']
if properties.get('build_distclean'):
command += ['distclean']
command += ['configure', '--git-protocol=git@']
if 'waf_bundle_path' in properties:
command += ['--bundle-path=' + properties['waf_bundle_path']]
if 'dependency_project' in properties:
command += ['--{0}-use-checkout={1}'.format(
properties['dependency_project'],
properties['dependency_checkout'])]
command += ["--cxx_mkspec={}".format(properties['cxx_mkspec'])]
command += get_tool_options(properties)
run_command(command)
def build(properties):
command = [sys.executable, 'waf', 'build', '-v']
run_command(command)
def run_tests(properties):
command = [sys.executable, 'waf', '-v', '--run_tests']
run_cmd = None
if properties.get('valgrind_run'):
run_cmd = 'valgrind --error-exitcode=1 %s'
if run_cmd:
command += ["--run_cmd={}".format(run_cmd)]
command += get_tool_options(properties)
run_command(command)
def install(properties):
command = [sys.executable, 'waf', '-v', 'install']
if 'install_path' in properties:
command += ['--install_path={0}'.format(properties['install_path'])]
if properties.get('install_relative'):
command += ['--install_relative']
run_command(command)
def main():
argv = sys.argv
if len(argv) != 3:
print("Usage: {} <command> <properties>".format(argv[0]))
sys.exit(0)
cmd = argv[1]
properties = json.loads(argv[2])
if cmd == 'configure':
configure(properties)
elif cmd == 'build':
build(properties)
elif cmd == 'run_tests':
run_tests(properties)
elif cmd == 'install':
install(properties)
else:
print("Unknown command: {}".format(cmd))
if __name__ == '__main__':
main()

73
config.py Normal file
View File

@ -0,0 +1,73 @@
#!/usr/bin/env python
# encoding: utf-8
import urllib2
import traceback
import sys
project_name = 'astyle'
project_dependencies = \
[
'waf-tools',
]
# Importing a dynamically generated module
# Python recipe from http://code.activestate.com/recipes/82234
def importCode(code, name, add_to_sys_modules=0):
"""
Import dynamically generated code as a module. code is the
object containing the code (a string, a file handle or an
actual compiled code object, same types as accepted by an
exec statement). The name is the name to give to the module,
and the final argument says whether to add it to sys.modules
or not. If it is added, a subsequent import statement using
name will return this module. If it is not added to sys.modules
import will try to load it in the normal fashion.
import foo
is equivalent to
foofile = open("/path/to/foo.py")
foo = importCode(foofile,"foo",1)
Returns a newly generated module.
"""
import imp
module = imp.new_module(name)
exec code in module.__dict__
if add_to_sys_modules:
sys.modules[name] = module
return module
if __name__ == '__main__':
print('Updating Smart Project Config Tool...')
url = "https://raw.github.com/steinwurf/steinwurf-labs/" \
"master/config_helper/config-impl.py"
try:
# Fetch the code file from the given url
req = urllib2.Request(url)
response = urllib2.urlopen(req)
code = response.read()
print("Update complete. Code size: {}\n".format(len(code)))
try:
# Import the code string as a module
mod = importCode(code, "config_helper")
# Run the actual config tool from the dynamic module
mod.config_tool(project_dependencies)
except:
print("Unexpected error:")
print traceback.format_exc()
except Exception as e:
print("Could not fetch code file from:\n\t{}".format(url))
print(e)
raw_input('Press ENTER to exit...')

169
waf vendored Executable file

File diff suppressed because one or more lines are too long

51
wscript Normal file
View File

@ -0,0 +1,51 @@
#! /usr/bin/env python
# encoding: utf-8
APPNAME = 'astyle'
VERSION = '0.1.0'
import waflib.extras.wurf_options
def options(opt):
opt.load('wurf_common_tools')
def resolve(ctx):
import waflib.extras.wurf_dependency_resolve as resolve
ctx.load('wurf_common_tools')
ctx.add_dependency(resolve.ResolveVersion(
name='waf-tools',
git_repository='github.com/steinwurf/waf-tools.git',
major=3))
def configure(conf):
conf.load("wurf_common_tools")
def build(bld):
bld.load("wurf_common_tools")
bld.env.append_unique(
'DEFINES_STEINWURF_VERSION',
'STEINWURF_ASTYLE_VERSION="{}"'.format(VERSION))
if bld.is_toplevel():
static_libs = []
if bld.is_mkspec_platform('windows'):
static_libs = ['Shell32']
bld.program(
features='cxx',
source=bld.path.ant_glob('src/*.cpp'),
lib=static_libs,
target='astyle')