Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83773 - trunk/tools/build/v2/test
From: steven_at_[hidden]
Date: 2013-04-05 21:32:37


Author: steven_watanabe
Date: 2013-04-05 21:32:36 EDT (Fri, 05 Apr 2013)
New Revision: 83773
URL: http://svn.boost.org/trac/boost/changeset/83773

Log:
Initial tests for zlib configuration.
Added:
   trunk/tools/build/v2/test/MockToolset.py (contents, props changed)
   trunk/tools/build/v2/test/zlib.py (contents, props changed)
Text files modified:
   trunk/tools/build/v2/test/test_all.py | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Added: trunk/tools/build/v2/test/MockToolset.py
==============================================================================
--- (empty file)
+++ trunk/tools/build/v2/test/MockToolset.py 2013-04-05 21:32:36 EDT (Fri, 05 Apr 2013)
@@ -0,0 +1,194 @@
+#!/usr/bin/python
+
+# Copyright (C) 2013 Steven Watanabe
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import sys
+
+def create(t):
+ t.write('''mockinfo.py''', '''
+import re
+import optparse
+import os
+
+parser = optparse.OptionParser()
+parser.add_option('-o', dest="output_file")
+parser.add_option('-x', dest="language")
+parser.add_option('-c', dest="compile", action="store_true")
+parser.add_option('-I', dest="includes", action="append")
+parser.add_option('--dll', dest="dll", action="store_true")
+parser.add_option('--archive', dest="archive", action="store_true")
+parser.add_option('--static-lib', dest="static_libraries", action="append")
+parser.add_option('--shared-lib', dest="shared_libraries", action="append")
+
+class MockInfo(object):
+ def __init__(self):
+ self.files = dict()
+ self.commands = list()
+ def source_file(self, name, pattern):
+ self.files[name] = pattern
+ def action(self, command, status=0):
+ self.commands.append((command, status))
+ def check(self, command):
+ for (raw, status) in self.commands:
+ if self.matches(raw, command):
+ return status
+ def matches(self, raw, command):
+ (expected_options, expected_args) = parser.parse_args(raw.split())
+ options = command[0]
+ input_files = list(command[1])
+ if len(expected_args) != len(input_files):
+ return False
+ for arg in expected_args:
+ if arg.startswith('$'):
+ fileid = arg[1:]
+ pattern = self.files[fileid] if fileid in self.files else fileid
+ matching_file = None
+ for input_file in input_files:
+ with open(input_file, 'r') as f:
+ contents = f.read()
+ if pattern == contents:
+ matching_file = input_file
+ break
+ if matching_file is not None:
+ input_files.remove(matching_file)
+ else:
+ return False
+ else:
+ if arg in input_files:
+ input_files.remove(arg)
+ else:
+ return False
+
+ if options.language != expected_options.language:
+ return False
+
+ if options.compile != expected_options.compile:
+ return False
+
+ # order matters
+ if options.includes is None:
+ options.includes = []
+ if expected_options.includes is None:
+ expected_options.includes = []
+ if map(os.path.abspath, options.includes) != \
+ map(os.path.abspath, expected_options.includes):
+ return False
+
+ if options.static_libraries != expected_options.static_libraries:
+ return False
+
+ if options.shared_libraries != expected_options.shared_libraries:
+ return False
+
+ if options.dll != expected_options.dll:
+ return False
+
+ if options.archive != expected_options.archive:
+ return False
+
+ # The output must be handled after everything else
+ # is validated
+ if expected_options.output_file is not None:
+ if options.output_file is not None:
+ if expected_options.output_file.startswith('$'):
+ fileid = expected_options.output_file[1:]
+ if fileid not in self.files:
+ self.files[fileid] = fileid
+ else:
+ assert(self.files[fileid] == fileid)
+ with open(options.output_file, 'w') as output:
+ output.write(fileid)
+ else:
+ return False
+ elif options.output_file is not None:
+ return False
+
+ # if we've gotten here, then everything matched
+ return True
+
+_instance = MockInfo()
+
+def instance():
+ return _instance
+
+''')
+
+ t.write('mock.py', '''
+import mockinfo
+import markup
+import sys
+
+status = markup.info.check(mockinfo.parser.parse_args())
+if status is not None:
+ exit(status)
+else:
+ print("Unrecognized command: " + ' '.join(sys.argv))
+ exit(1)
+''')
+
+ t.write('mock.jam', '''
+import feature ;
+import toolset ;
+
+python-cmd = "\"%s\"" ;
+
+rule init ( )
+{
+}
+
+feature.extend toolset : mock ;
+
+generators.register-c-compiler mock.compile.c++ : CPP : OBJ : <toolset>mock ;
+generators.register-c-compiler mock.compile.c : C : OBJ : <toolset>mock ;
+
+generators.register-linker mock.link : LIB OBJ : EXE : <toolset>mock ;
+generators.register-linker mock.link.dll : LIB OBJ : SHARED_LIB : <toolset>mock ;
+generators.register-archiver mock.archive : OBJ : STATIC_LIB : <toolset>mock ;
+
+toolset.flags mock.compile INCLUDES <include> ;
+
+actions compile.c
+{
+ $(python-cmd) mock.py -c -x c -I$(INCLUDES) $(>) -o $(<)
+}
+
+actions compile.c++
+{
+ $(python-cmd) mock.py -c -x c++ $(>) -o $(<)
+}
+
+toolset.flags mock.link USER_OPTIONS <linkflags> ;
+toolset.flags mock.link FINDLIBS-STATIC <find-static-library> ;
+toolset.flags mock.link FINDLIBS-SHARED <find-shared-library> ;
+toolset.flags mock.link LINK_PATH <library-path> ;
+toolset.flags mock.link LIBRARIES <library-file> ;
+
+actions link
+{
+ $(python-cmd) mock.py $(>) -o $(<) $(USER_OPTIONS) -L$(LINK_PATH) --static-lib=$(FINDLIBS-STATIC) --shared-lib=$(FINDLIBS-SHARED)
+}
+
+actions archive
+{
+ $(python-cmd) mock.py --archive $(>) -o $(<) $(USER_OPTIONS)
+}
+
+actions link.dll
+{
+ $(python-cmd) mock.py --dll $(>) -o $(<) $(USER_OPTIONS) -L$(LINK_PATH) --static-lib=$(FINDLIBS-STATIC) --shared-lib=$(FINDLIBS-SHARED)
+}
+
+''' % sys.executable.replace('\\', '\\\\'))
+
+def set_expected(t, markup):
+ t.write('markup.py', '''
+import mockinfo
+info = mockinfo.MockInfo()
+def source_file(name, contents):
+ info.source_file(name, contents)
+def action(command, status=0):
+ info.action(command, status)
+''' + markup)

Modified: trunk/tools/build/v2/test/test_all.py
==============================================================================
--- trunk/tools/build/v2/test/test_all.py (original)
+++ trunk/tools/build/v2/test/test_all.py 2013-04-05 21:32:36 EDT (Fri, 05 Apr 2013)
@@ -267,6 +267,7 @@
          "using",
          "wrapper",
          "wrong_project",
+ "zlib"
          ]
 
 if os.name == "posix":

Added: trunk/tools/build/v2/test/zlib.py
==============================================================================
--- (empty file)
+++ trunk/tools/build/v2/test/zlib.py 2013-04-05 21:32:36 EDT (Fri, 05 Apr 2013)
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+
+# Copyright (C) 2013 Steven Watanabe
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import BoostBuild
+import MockToolset
+
+t = BoostBuild.Tester(arguments=['toolset=mock'], pass_toolset=0)
+
+MockToolset.create(t)
+
+# Build from source
+t.write("zlib/zlib.h", 'zlib')
+t.write("zlib/deflate.c", 'deflate')
+
+t.write("Jamroot.jam", """
+path-constant here : . ;
+using zlib : : <source>$(here)/zlib ;
+alias zlib : /zlib//zlib : : <link>static <link>shared ;
+""")
+
+MockToolset.set_expected(t, '''
+source_file('deflate.c', 'deflate')
+action('-c -x c -I./zlib -o $deflate.o $deflate.c')
+action('--dll $deflate.o -o $deflate.so')
+action('--archive $deflate.o -o $deflate.a')
+''')
+
+t.run_build_system()
+t.expect_addition('bin/standalone/zlib/mock/debug/libz.so')
+t.expect_addition('bin/standalone/zlib/mock/debug/link-static/libz.a')
+
+# Default initialization - static library
+t.rm('bin')
+t.write("Jamroot.jam", """
+path-constant here : . ;
+using zlib ;
+exe test : test.cpp /zlib//zlib : : <link>static <link>shared ;
+""")
+
+t.write('test.cpp', 'test.cpp')
+
+MockToolset.set_expected(t, '''
+source_file('test.cpp', 'test.cpp')
+source_file('main.cpp', 'int main() {}')
+source_file('zlib.h.cpp', '#include <zlib.h>')
+action('-c -x c++ $main.cpp -o $main.o')
+action('$main.o --static-lib=z -o $config.exe')
+action('-c -x c++ $zlib.h.cpp -o $zlib.h.o')
+action('-c -x c++ $test.cpp -o $test.o')
+action('$test.o --static-lib=z -o $test')
+''')
+t.run_build_system()
+t.expect_addition('bin/mock/debug/test')
+t.expect_addition('bin/mock/debug/link-static/test')
+
+# Default initialization - shared library
+t.rm('bin')
+t.write("Jamroot.jam", """
+path-constant here : . ;
+using zlib ;
+exe test : test.cpp /zlib//zlib : : <link>static <link>shared ;
+""")
+
+t.write('test.cpp', 'test.cpp')
+
+MockToolset.set_expected(t, '''
+source_file('test.cpp', 'test.cpp')
+source_file('main.cpp', 'int main() {}')
+source_file('zlib.h.cpp', '#include <zlib.h>')
+action('-c -x c++ $main.cpp -o $main.o')
+action('$main.o --shared-lib=z -o $config.exe')
+action('-c -x c++ $zlib.h.cpp -o $zlib.h.o')
+action('-c -x c++ $test.cpp -o $test.o')
+action('$test.o --shared-lib=z -o $test')
+''')
+t.run_build_system()
+t.expect_addition('bin/mock/debug/test')
+t.expect_addition('bin/mock/debug/link-static/test')
+
+t.cleanup()


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk