From: stevenknight Date: Thu, 13 Oct 2005 13:26:39 +0000 (+0000) Subject: Have the QT UIC Scanner use the env.FindFile method. (Leanid Nazdrynau) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=16e737bc5bdd9fdf53920d0fdb79f5edaad49455;hp=ef577093c3ea051fb6ae931aeade1c05bfb684a2;p=scons.git Have the QT UIC Scanner use the env.FindFile method. (Leanid Nazdrynau) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1372 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/bin/import-test.py b/bin/import-test.py new file mode 100644 index 00000000..13995578 --- /dev/null +++ b/bin/import-test.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# tree2test.py - turn a directory tree into TestSCons code +# +# A quick script for importing directory hierarchies containing test +# cases that people supply (typically in a .zip or .tar.gz file) into a +# TestSCons.py script. No error checking or options yet, it just walks +# the first command-line argument (assumed to be the directory containing +# the test case) and spits out code looking like the following: +# +# test.subdir(['sub1'], +# ['sub1', 'sub2']) +# +# test.write(['sub1', 'file1'], """\ +# contents of file1 +# """) +# +# test.write(['sub1', 'sub2', 'file2'], """\ +# contents of file2 +# """) +# +# There's no massaging of contents, so any files that themselves contain +# """ triple-quotes will need to have their contents edited by hand. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os.path +import sys + +directory = sys.argv[1] + +Top = None +TopPath = None + +class Dir: + def __init__(self, path): + self.path = path + self.entries = {} + def call_for_each_entry(self, func): + entries = self.entries + names = entries.keys() + names.sort() + for name in names: + func(name, entries[name]) + +def lookup(dirname): + global Top, TopPath + if not Top: + Top = Dir([]) + TopPath = dirname + os.sep + return Top + dirname = dirname.replace(TopPath, '') + dirs = dirname.split(os.sep) + t = Top + for d in dirs[:-1]: + t = t.entries[d] + node = t.entries[dirs[-1]] = Dir(dirs) + return node + +def make_nodes(arg, dirname, fnames): + dir = lookup(dirname) + for f in fnames: + dir.entries[f] = None + +def collect_dirs(l, dir): + if dir.path: + l.append(dir.path) + def recurse(n, d): + if d: + collect_dirs(l, d) + dir.call_for_each_entry(recurse) + +def print_files(dir): + def print_a_file(n, d): + if not d: + l = dir.path + [n] + sys.stdout.write('\ntest.write(%s, """\\\n' % l) + p = os.path.join(*([directory] + l)) + sys.stdout.write(open(p, 'r').read()) + sys.stdout.write('""")\n') + dir.call_for_each_entry(print_a_file) + + def recurse(n, d): + if d: + print_files(d) + dir.call_for_each_entry(recurse) + +os.path.walk(directory, make_nodes, None) + +subdir_list = [] +collect_dirs(subdir_list, Top) +subdir_list = [ str(l) for l in subdir_list ] +sys.stdout.write('test.subdir(' + ',\n '.join(subdir_list) + ')\n') + +print_files(Top) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 39c0c8a2..e49d391d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -431,6 +431,9 @@ RELEASE 0.97 - XXX - Fix the Java parser's handling of backslashes in strings. + - Fix the Qt UIC scanner to work with generated .ui files (by using + the FindFile() function instead of checking by-hand for the file). + From Christian Neeb: - Fix the Java parser's handling of string definitions to avoid ignoring diff --git a/src/engine/SCons/Tool/qt.py b/src/engine/SCons/Tool/qt.py index 04b62150..5077901d 100644 --- a/src/engine/SCons/Tool/qt.py +++ b/src/engine/SCons/Tool/qt.py @@ -219,19 +219,17 @@ def uicEmitter(target, source, env): return target, source def uicScannerFunc(node, env, path): - #print "uicScannerFunc" dir = node.dir + lookout = [] + lookout.extend(env['CPPPATH']) + lookout.append(str(node.rfile().dir)) includes = re.findall("(.*?)", node.get_contents()) - res = [] + result = [] for incFile in includes: - incNode = dir.File(incFile) - if incNode.rexists(): - #print "uicdep: ", incNode - res.append(dir.File(incFile)) - else: - #print "uicdep: ", incNode, "not found" - pass - return res + dep = env.FindFile(incFile,lookout) + if dep: + result.append(dep) + return result uicScanner = SCons.Scanner.Scanner(uicScannerFunc, name = "UicScanner", diff --git a/test/QT/generated-ui.py b/test/QT/generated-ui.py new file mode 100644 index 00000000..16744879 --- /dev/null +++ b/test/QT/generated-ui.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that the UI scanning logic correctly picks up scansG +""" + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir(['layer'], + ['layer', 'aclock'], + ['layer', 'aclock', 'qt_bug']) + +test.write(['SConstruct'], """\ +import os +aa=os.getcwd() + +env=Environment(tools=['default','expheaders','qt'],toolpath=[aa]) +env['ENV']['HOME'] = os.environ['HOME'] +env["EXP_HEADER_ABS"]=os.path.join(os.getcwd(),'include') +if not os.access(env["EXP_HEADER_ABS"],os.F_OK): + os.mkdir (env["EXP_HEADER_ABS"]) +Export('env') +env.SConscript('layer/aclock/qt_bug/SConscript') +""") + +test.write(['expheaders.py'], """\ +import SCons.Defaults +def ExpHeaderScanner(node, env, path): + return [] +def generate(env): + HeaderAction=SCons.Action.Action([SCons.Defaults.Copy('$TARGET','$SOURCE'),SCons.Defaults.Chmod('$TARGET',0755)]) + HeaderBuilder= SCons.Builder.Builder(action=HeaderAction) + env['BUILDERS']['ExportHeaders'] = HeaderBuilder +def exists(env): + return 0 +""") + +test.write(['layer', 'aclock', 'qt_bug', 'SConscript'], """\ +import os + +Import ("env") +#src=os.path.join(env.Dir('.').srcnode().abspath, 'testfile.h') +env.ExportHeaders(os.path.join(env["EXP_HEADER_ABS"],'main.h'), 'main.h') +env.ExportHeaders(os.path.join(env["EXP_HEADER_ABS"],'migraform.h'), 'migraform.h') +env.Append(CPPPATH=env["EXP_HEADER_ABS"]) +env.StaticLibrary('all',['main.ui','migraform.ui']) +""") + +test.write(['layer', 'aclock', 'qt_bug', 'main.ui'], """\ + +Main + + + Main + + + + 0 + 0 + 600 + 385 + + + + + migraform.h + + +""") + +test.write(['layer', 'aclock', 'qt_bug', 'migraform.ui'], """\ + +MigrateForm + + + MigrateForm + + + + 0 + 0 + %s + 385 + + + + +""") + +test.run(arguments = '.', + stderr = TestSCons.noisy_ar, + match = TestSCons.match_re_dotall) + +test.up_to_date(arguments = '.') + +test.pass_test()