SCons / scons-contrib

A repo for user contributed SCons Builders and other tools. These are not supported directly by the SCons project.
MIT License
14 stars 18 forks source link

qt4 issue with missing 2 required positional arguments #45

Closed jhdub23 closed 2 years ago

jhdub23 commented 2 years ago

We just upgraded to scons-4.3.0 (using python-3.10.2) and also updated the qt4 tool as well. I'm getting many errors such as:

scons: *** [build/linux_x86_64_rhel7/Optimized/gui/moc_GUBase.cc] TypeError `_defines() missing 2 required positional arguments: 'target' and 'source'' trying to evaluate `${_defines(QT4_MOCDEFPREFIX, CPPDEFINES, QT4_MOCDEFSUFFIX, __env__)}'

Is there something obvious that I can fix? We are using qt-4.8.7.

bdbaddog commented 2 years ago

Rerun with --debug=stacktrace and post that output.

jhdub23 commented 2 years ago
scons: *** [build/linux_x86_64_rhel7/Optimized/gui/moc_GUBase.cc] TypeError `_defines() missing 2 required positional arguments: 'target' and 'source'' trying to evaluate `${_defines(QT4_MOCDEFPREFIX, CPPDEFINES, QT4_MOCDEFSUFFIX, __env__)}'
scons: internal stack trace:
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Job.py", line 391, in start
    task.prepare()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Script/Main.py", line 178, in prepare
    return SCons.Taskmaster.OutOfDateTask.prepare(self)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Taskmaster.py", line 167, in prepare
    self.exception_raise()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Taskmaster.py", line 540, in _exception_raise
    raise exc_value.with_traceback(exc_traceback)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Taskmaster.py", line 814, in _find_next_ready_node
    children = executor.get_all_children()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Executor.py", line 311, in get_all_children
    result.extend(target.children())
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/__init__.py", line 1412, in children
    self.scan()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/__init__.py", line 1101, in scan
    executor.scan_sources(self.builder.source_scanner)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Executor.py", line 476, in scan_sources
    self.scan(scanner, self.get_all_sources())
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Executor.py", line 493, in scan
    deps.extend(node.get_implicit_deps(env, scanner, path, kw))
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/__init__.py", line 996, in get_implicit_deps
    included_deps = [x for x in node.get_found_includes(env, scanner, path) if x not in seen]
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/FS.py", line 2980, in get_found_includes
    result = [n.disambiguate() for n in scanner(self, env, path)]
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Scanner/__init__.py", line 212, in __call__
    if self.scan_check and not self.scan_check(node, env):
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Scanner/__init__.py", line 323, in current_check
    return not node.has_builder() or node.is_up_to_date()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/FS.py", line 3562, in is_up_to_date
    self.changed()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/FS.py", line 3318, in changed
    has_changed = SCons.Node.Node.changed(self, node)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/__init__.py", line 1483, in changed
    children = self.children()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/__init__.py", line 1412, in children
    self.scan()
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Node/__init__.py", line 1101, in scan
    executor.scan_sources(self.builder.source_scanner)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Executor.py", line 476, in scan_sources
    self.scan(scanner, self.get_all_sources())
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Executor.py", line 495, in scan
    deps.extend(self.get_implicit_deps())
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Executor.py", line 543, in get_implicit_deps
    deps = act.get_implicit_deps(self.get_all_targets(),
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Action.py", line 1134, in get_implicit_deps
    return self._generate(target, source, env, 1, executor).get_implicit_deps(target, source, env)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Action.py", line 1134, in get_implicit_deps
    return self._generate(target, source, env, 1, executor).get_implicit_deps(target, source, env)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Action.py", line 985, in get_implicit_deps
    return self._get_implicit_deps_lightweight(target, source, env, executor)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Action.py", line 996, in _get_implicit_deps_lightweight
    cmd_list = env.subst_list(self.cmd_list, SUBST_SIG, target, source)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Environment.py", line 518, in subst_list
    return SCons.Subst.scons_subst_list(string, self, raw, target, source, gvars, lvars, conv)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Subst.py", line 920, in scons_subst_list
    ls.substitute(strSubst, lvars, 0)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Subst.py", line 642, in substitute
    self.expand(a, lvars, within_list)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Subst.py", line 590, in expand
    self.substitute(s, lv, 0)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Subst.py", line 642, in substitute
    self.expand(a, lvars, within_list)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Subst.py", line 569, in expand
    raise_exception(e, lvars['TARGETS'], old_s)
  File "/usr/local/pkgs/python-3.10.2/lib/python3.10/site-packages/SCons-4.3.0-py3.10.egg/SCons/Subst.py", line 52, in raise_exception
    raise SCons.Errors.BuildError(target[0], msg)
bdbaddog commented 2 years ago

Nothing in the stack trace is qt4.. Can you make a small reproducer?

jhdub23 commented 2 years ago

@bdbaddog : Thanks for looking into this. The error happens if there is both a .h file and .cpp (e.g. hello.h and hello.cpp). The following example reproduces the error. If the hello.h file is renamed, the compile is fine. Edit: Replaced with a new example testcase that compiles fine with scons-4.1.0.post1 example2.tar.gz This testcase fails with scons-4.2.0 and scons-4.3.0.

bdbaddog commented 2 years ago

Builds for me.

$ python ~/devel/scons//git/as_scons/scripts/scons.py
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o hello.os -c -fPIC -DQT_NO_KEYWORDS -I/usr/include/qt4 hello.cpp
/usr/share/qt4/bin/moc -DQT_NO_KEYWORDS -o moc_hello.cc hello.h
g++ -o moc_hello.o -c -DQT_NO_KEYWORDS -I/usr/include/qt4 moc_hello.cc
g++ -o hello hello.os moc_hello.o -lQtGui -lQtCore
scons: done building targets.

I did have to modify SConstruct to fit my environment..

You should have

env_qt.Append(CPPPATH=[qt_include, gcc_include])

instead of

env_qt.Append(CCFLAGS = ['-I'+qt_include, '-I'+gcc_include])

btw. I installed qt4 via the instructions here: https://askubuntu.com/questions/1274134/cannot-install-qt-4-on-ubuntu-20-04-quite-universal-circuit-simulator-qucs

And just used the ubuntu 20.04 default gcc.

Try changing your SConstruct as above and report back?

jhdub23 commented 2 years ago

I changed to env_qt.Append(CPPPATH=[qt_include, gcc_include]) but still have the same problem. I'm on CentOS 7.6. I would suspect my Qt4 installation, but downgrading scons to 4.1.0.post1 fixes the problem. I also see similar reports in camotics and gentoo.

bdbaddog commented 2 years ago

Can you attach the full log of your reproducer running on your system excluding the stack trace?

jhdub23 commented 2 years ago

This is running on CentOS 7.6, python-3.10.2, qt-4.8.7 with everything built with gcc-10.2.0. For both of the below runs, I also set env_qt.Replace(QT4_DEBUG = 1). Downloaded a fresh clone of scons-contrib. I also get similar results with Qt5 (qt-5.15.8).

scons was installed by first downloading the source and then installing:

pip3 download --no-binary :all: -d pip_downloads scons==4.3.0
pip3 install scons==4.3.0 --no-binary :all --no-index --find-links pip_downloads

Updated example: example3.tar.gz for debug setting and to be able to test both Qt4 and Qt5.

Failed run with scons-4.3.0:

scons: Reading SConscript files ...
scons: qt4: Scanning 'hello.h' (header of 'hello.cpp')
scons: qt4: found Q_OBJECT macro in 'hello.h', moc'ing to '['moc_hello.cc']'
scons: qt4: compiling 'hello.cpp' to '['moc_hello.o']'
scons: qt4: found Q_OBJECT macro in 'hello.cpp', moc'ing to '['hello.moc']'
scons: done reading SConscript files.
scons: Building targets ...
g++ -o hello.os -c -fPIC -DUSE_QT_VERSION=4 -DQT_NO_KEYWORDS -Iqt4_link/include -Igcc_link/include hello.cpp
scons: *** [moc_hello.cc] TypeError `_defines() missing 2 required positional arguments: 'target' and 'source'' trying to evaluate `${_defines(QT4_MOCDEFPREFIX, CPPDEFINES, QT4_MOCDEFSUFFIX, __env__)}'
scons: building terminated because of errors.

Good run with scons-4.1.0.post1:

scons: Reading SConscript files ...
scons: qt4: Scanning 'hello.h' (header of 'hello.cpp')
scons: qt4: found Q_OBJECT macro in 'hello.h', moc'ing to '['moc_hello.cc']'
scons: qt4: compiling 'hello.cpp' to '['moc_hello.o']'
scons: qt4: found Q_OBJECT macro in 'hello.cpp', moc'ing to '['hello.moc']'
scons: done reading SConscript files.
scons: Building targets ...
g++ -o hello.os -c -fPIC -DUSE_QT_VERSION=4 -DQT_NO_KEYWORDS -Iqt4_link/include -Igcc_link/include hello.cpp
qt4_link/bin/moc -DUSE_QT_VERSION=4 -DQT_NO_KEYWORDS -o moc_hello.cc hello.h
g++ -o moc_hello.o -c -DUSE_QT_VERSION=4 -DQT_NO_KEYWORDS -Iqt4_link/include -Igcc_link/include moc_hello.cc
g++ -o hello hello.os moc_hello.o -Lqt4_link/lib -Lgcc_link/lib64 -Lgcc_link/lib -lQtGui -lQtCore
scons: done building targets.
bdbaddog commented 2 years ago

Try commenting this line out from the q4/init.py

    QT4_MOCDEFINES = '${_defines(QT4_MOCDEFPREFIX, CPPDEFINES, QT4_MOCDEFSUFFIX, __env__)}',

See if the error goes away.

bdbaddog commented 2 years ago

And/or try changing it to

QT4_MOCDEFINES = '${_defines(QT4_MOCDEFPREFIX, CPPDEFINES, QT4_MOCDEFSUFFIX, __env__, TARGET, SOURCE)}',

jhdub23 commented 2 years ago

Both suggestions worked! Is one recommended over the other? Is there a reason the problem appeared on my system but not yours, without the change?

bdbaddog commented 2 years ago

The latter is more correct as we added SOURCES and TARGETS as arguments to _defines() to allow the logic to use those values when expanding defines lists.

bdbaddog commented 2 years ago

Likewise we should probably add a default value for _defines() in scons to avoid such failures, but that is proper calling signature going forward (with TARGET, SOURCE)

jhdub23 commented 2 years ago

Thanks. Will you be making the fixes in the code, or should I submit the code fix/pull request?

bdbaddog commented 2 years ago

I'd do it. I'd like to fix both SCons to have a reasonable default values for such or maybe simpler error messaging if SOURCE and TARGET aren't specified..

mwichmann commented 2 years ago

See scons/scons#3790 and scons/scons#3949

bdbaddog commented 2 years ago

Should be fixed by: https://github.com/SCons/scons-contrib/commit/b716f708ab2bd5e537d041c80bad8a98b3f67fc0

Marking closed. @jhdub23 - please reopen if this doesn't fix. Note the "old" _defines() usage is in comments should someone be running with scons < 4.2.0

bdbaddog commented 2 years ago

Closing