From 64a582ecc2b2005e07bc1b7229e4f7c254b2baef Mon Sep 17 00:00:00 2001 From: fedepell Date: Sat, 21 Apr 2018 15:44:13 +0200 Subject: [PATCH] eclipse: add support for generated files management for java and python added support to search and add into source path also generated source files for both java and python. this is useful when using generated code (ie. protoc and pyqt5) so browsing in eclipse works correclty adding also paths where generated code is done. extended example in playground demostrating generated code --- playground/eclipse/java/protoc/message.proto | 12 ++ playground/eclipse/java/wscript | 12 +- .../eclipse/python/withqt5/src/firstgui.ui | 130 ++++++++++++++++++ .../eclipse/python/withqt5/src/sample.py | 24 ++++ playground/eclipse/python/wscript | 6 +- waflib/extras/eclipse.py | 30 ++-- 6 files changed, 195 insertions(+), 19 deletions(-) create mode 100644 playground/eclipse/java/protoc/message.proto create mode 100644 playground/eclipse/python/withqt5/src/firstgui.ui create mode 100644 playground/eclipse/python/withqt5/src/sample.py diff --git a/playground/eclipse/java/protoc/message.proto b/playground/eclipse/java/protoc/message.proto new file mode 100644 index 00000000..2c73cee5 --- /dev/null +++ b/playground/eclipse/java/protoc/message.proto @@ -0,0 +1,12 @@ +package udp.tc.tests; + +option java_package ="com.udp.tc.tests"; +option java_outer_classname= "MessageProtos"; +option cc_generic_services = false; +option java_generic_services = false; +option py_generic_services = false; + +message Message { + required int32 test = 1; + optional uint32 blah = 2; +} diff --git a/playground/eclipse/java/wscript b/playground/eclipse/java/wscript index 701d1fd6..d517174e 100644 --- a/playground/eclipse/java/wscript +++ b/playground/eclipse/java/wscript @@ -21,7 +21,7 @@ def options(opt): pass def configure(conf): - conf.load('java') + conf.load('java protoc') try: ret = conf.load('junit', tooldir='.') @@ -33,6 +33,7 @@ def configure(conf): conf.check_java_class('FakeClass') conf.env.CLASSPATH_NNN = ['aaaa.jar', 'bbbb.jar'] + conf.env.CLASSPATH_PROTOBUF = ['/tmp/cp/protobuf-java-2.5.0.jar'] def build(bld): @@ -54,3 +55,12 @@ def build(bld): bld.recurse('animals cats') + + bld( + features = 'javac protoc', + name = 'pbjava', + srcdir = 'protoc/', + source = ['protoc/message.proto'], + use = 'PROTOBUF', + protoc_includes = ['protoc']) + diff --git a/playground/eclipse/python/withqt5/src/firstgui.ui b/playground/eclipse/python/withqt5/src/firstgui.ui new file mode 100644 index 00000000..cb7f9d30 --- /dev/null +++ b/playground/eclipse/python/withqt5/src/firstgui.ui @@ -0,0 +1,130 @@ + + + myfirstgui + + + + 0 + 0 + 411 + 247 + + + + My First Gui! + + + + + 20 + 210 + 381 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + 10 + 10 + 101 + 21 + + + + + + + 120 + 10 + 281 + 192 + + + + + + + 10 + 180 + 101 + 23 + + + + clear + + + + + + 10 + 40 + 101 + 23 + + + + add + + + + + + + buttonBox + accepted() + myfirstgui + accept() + + + 258 + 274 + + + 157 + 274 + + + + + buttonBox + rejected() + myfirstgui + reject() + + + 316 + 260 + + + 286 + 274 + + + + + clearBtn + clicked() + listWidget + clear() + + + 177 + 253 + + + 177 + 174 + + + + + diff --git a/playground/eclipse/python/withqt5/src/sample.py b/playground/eclipse/python/withqt5/src/sample.py new file mode 100644 index 00000000..8f5f2f5b --- /dev/null +++ b/playground/eclipse/python/withqt5/src/sample.py @@ -0,0 +1,24 @@ +import sys +from PySide2 import QtCore, QtGui, QtWidgets +from firstgui import Ui_myfirstgui + +class MyFirstGuiProgram(Ui_myfirstgui): + def __init__(self, dialog): + Ui_myfirstgui.__init__(self) + self.setupUi(dialog) + + # Connect "add" button with a custom function (addInputTextToListbox) + self.addBtn.clicked.connect(self.addInputTextToListbox) + + def addInputTextToListbox(self): + txt = self.myTextInput.text() + self.listWidget.addItem(txt) + +if __name__ == '__main__': + app = QtWidgets.QApplication(sys.argv) + dialog = QtWidgets.QDialog() + + prog = MyFirstGuiProgram(dialog) + + dialog.show() + sys.exit(app.exec_()) diff --git a/playground/eclipse/python/wscript b/playground/eclipse/python/wscript index 232fa756..7576137f 100644 --- a/playground/eclipse/python/wscript +++ b/playground/eclipse/python/wscript @@ -3,10 +3,10 @@ def options(opt): - opt.load('python') + opt.load('python pyqt5') def configure(conf): - conf.load('python') + conf.load('python pyqt5') conf.check_python_version(minver=(2, 7, 0)) @@ -15,5 +15,7 @@ def build(bld): bld(name='mod2', features='py', source=bld.path.ant_glob('mod2/src/**/*.py'), install_from='mod2/src') bld(name='mod3', features='py', source=bld.path.ant_glob('mod3/src/**/*.py'), install_from='mod3/src') + bld(name='withqt5', features='py pyqt5', source=bld.path.ant_glob('withqt5/src/**/*'), install_from='withqt5/src') + # Example program with module dependencies bld(name='prg', features='py', source=bld.path.ant_glob('prg/src/**/*.py'), install_from='prg/src', use='mod1 mod2 mod3') diff --git a/waflib/extras/eclipse.py b/waflib/extras/eclipse.py index adb38f5f..fca6cf35 100644 --- a/waflib/extras/eclipse.py +++ b/waflib/extras/eclipse.py @@ -75,38 +75,36 @@ class eclipse(Build.BuildContext): if not isinstance(tg, TaskGen.task_gen): continue + tg.post() + # Add local Python modules paths to configuration so object resolving will work in IDE + # This may also contain generated files (ie. pyqt5 or protoc) that get picked from build if 'py' in tg.features: pypath = tg.path.relpath() py_installfrom = getattr(tg, 'install_from', None) - if py_installfrom: - if isinstance(py_installfrom, Node.Node): - py_installfrom = py_installfrom.path_from(tg.path) - pypath += os.sep + py_installfrom - pythonpath.append(pypath) + if isinstance(py_installfrom, Node.Node): + pypath = py_installfrom.path_from(self.root.make_node(self.top_dir)) + if pypath not in pythonpath: + pythonpath.append(pypath) haspython = True - # Add Java source directories so object resolving works in IDE + # This may also contain generated files (ie. protoc) that get picked from build if 'javac' in tg.features: java_src = tg.path.relpath() - java_srcdir = getattr(tg, 'srcdir', None) + java_srcdir = getattr(tg.javac_task, 'srcdir', None) if java_srcdir: if isinstance(java_srcdir, Node.Node): java_srcdir = [java_srcdir] for x in Utils.to_list(java_srcdir): - if isinstance(x, Node.Node): - x = x.name - if java_src == '.': - this_src = x - else: - this_src = java_src + os.sep + x - javasrcpath.append(this_src) + x = x.path_from(self.root.make_node(self.top_dir)) + if x not in javasrcpath: + javasrcpath.append(x) else: - javasrcpath.append(java_src) + if java_src not in javasrcpath: + javasrcpath.append(java_src) hasjava = True - tg.post() if not getattr(tg, 'link_task', None): continue