mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 09:57:15 +01:00
eclipse: added a playground area for testing the eclipse extra (#1968)
* eclipse: added a playground area for testing the eclipse extra * eclipse: try to clean up a bit the playground by collapsing some wscripts
This commit is contained in:
parent
003f9dd5a8
commit
b0eb986e9a
13
playground/eclipse/c/exLibC/src/exLibC.cpp
Normal file
13
playground/eclipse/c/exLibC/src/exLibC.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <pkg1/exLibC/exLibC.hpp>
|
||||
|
||||
int check_smaller(int value) {
|
||||
if (value < HELLO_LIMIT) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
|
||||
#define HELLO_LIMIT 5
|
||||
|
||||
int check_smaller(int value);
|
16
playground/eclipse/c/exProgLinkedC/src/exProgLinkedC.cpp
Normal file
16
playground/eclipse/c/exProgLinkedC/src/exProgLinkedC.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <pkg1/exLibC/exLibC.hpp>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("Hello world!\n");
|
||||
if (argc < 2) {
|
||||
printf("Too few parameters passed!\n");
|
||||
} else {
|
||||
int val=atoi(argv[1]);
|
||||
printf("Result is: %d\n",check_smaller(val));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
16
playground/eclipse/c/wscript
Normal file
16
playground/eclipse/c/wscript
Normal file
@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
def options(opt):
|
||||
# We are using C++
|
||||
opt.load('compiler_cxx')
|
||||
|
||||
def configure(conf):
|
||||
# We are using C++
|
||||
conf.load('compiler_cxx')
|
||||
|
||||
def build(bld):
|
||||
bld.shlib(source='exLibC/src/exLibC.cpp', includes='exLibC/src/include', target='exampleLibC', export_includes='exLibC/src/include/')
|
||||
bld.program(source=bld.path.ant_glob('exProgLinkedC/src/*.cpp'), target='exampleProgLinkedC', use='exampleLibC')
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package org.example;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class AnimalTest extends TestCase {
|
||||
public AnimalTest() {
|
||||
}
|
||||
|
||||
public void testAnimal() {
|
||||
System.out.println("Test run successfully!");
|
||||
}
|
||||
}
|
||||
|
3
playground/eclipse/java/animals/manifest
Normal file
3
playground/eclipse/java/animals/manifest
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Created-By: Waf 1.6.2 (rev >= 10780)
|
||||
|
@ -0,0 +1,9 @@
|
||||
package org.example;
|
||||
|
||||
class Animal {
|
||||
|
||||
public String sound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
28
playground/eclipse/java/animals/wscript
Normal file
28
playground/eclipse/java/animals/wscript
Normal file
@ -0,0 +1,28 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
def build(bld):
|
||||
|
||||
t = bld(
|
||||
features = 'javac jar',
|
||||
name = 'animals',
|
||||
|
||||
# javac
|
||||
srcdir = 'src',
|
||||
compat = '1.7',
|
||||
|
||||
# jar
|
||||
basedir = '.',
|
||||
destfile = '../animals.jar',
|
||||
manifest = 'manifest',
|
||||
use = 'NNN',
|
||||
)
|
||||
t.env.JAVACFLAGS = ['-Xlint:unchecked']
|
||||
|
||||
if bld.env.DO_JUNIT:
|
||||
t.features += ' junit'
|
||||
t.srcdir = 'src junit'
|
||||
t.junitsrc = 'junit'
|
||||
t.junitclasspath = '.'
|
||||
t.use += ' JUNIT'
|
||||
t.env.JUNIT_EXEC_FLAGS = ['-ea']
|
||||
|
14
playground/eclipse/java/cats/src/org/example/Cat.java
Normal file
14
playground/eclipse/java/cats/src/org/example/Cat.java
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
package org.example;
|
||||
|
||||
import org.example.Animal;
|
||||
|
||||
class Cat extends Animal {
|
||||
|
||||
public String sound() {
|
||||
return "Meow!";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
18
playground/eclipse/java/cats/wscript
Normal file
18
playground/eclipse/java/cats/wscript
Normal file
@ -0,0 +1,18 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
def build(bld):
|
||||
|
||||
bld(features = 'javac',
|
||||
srcdir = 'src',
|
||||
compat = '1.7',
|
||||
use = 'animals',
|
||||
name = 'cats-src',
|
||||
)
|
||||
|
||||
bld(features = 'jar',
|
||||
basedir = '.',
|
||||
destfile = '../cats.jar',
|
||||
name = 'cats',
|
||||
use = 'cats-src'
|
||||
)
|
||||
|
85
playground/eclipse/java/junit.py
Normal file
85
playground/eclipse/java/junit.py
Normal file
@ -0,0 +1,85 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
"""
|
||||
JUnit test system
|
||||
|
||||
- executes all junit tests in the specified subtree (junitsrc)
|
||||
- only if --junit is given on the commandline
|
||||
- method:
|
||||
- add task to compile junitsrc after compiling srcdir
|
||||
- additional junit_classpath specifiable
|
||||
- defaults to classpath + destdir
|
||||
- add task to run junit tests after they're compiled.
|
||||
"""
|
||||
|
||||
import os
|
||||
from waflib import Task, TaskGen, Utils, Options
|
||||
from waflib.TaskGen import feature, before, after
|
||||
from waflib.Configure import conf
|
||||
|
||||
JUNIT_RUNNER = 'org.junit.runner.JUnitCore'
|
||||
|
||||
def options(opt):
|
||||
opt.add_option('--junit', action='store_true', default=False,
|
||||
help='Run all junit tests', dest='junit')
|
||||
opt.add_option('--junitpath', action='store', default='',
|
||||
help='Give a path to the junit jar')
|
||||
|
||||
def configure(ctx):
|
||||
cp = ctx.options.junitpath
|
||||
val = ctx.env.JUNIT_RUNNER = ctx.env.JUNIT_RUNNER or JUNIT_RUNNER
|
||||
if ctx.check_java_class(val, with_classpath=cp):
|
||||
ctx.fatal('Could not run junit from %r' % val)
|
||||
ctx.env.CLASSPATH_JUNIT = cp
|
||||
|
||||
#@feature('junit')
|
||||
#@after('apply_java', 'use_javac_files')
|
||||
def make_test(self):
|
||||
"""make the unit test task"""
|
||||
if not getattr(self, 'junitsrc', None):
|
||||
return
|
||||
junit_task = self.create_task('junit_test')
|
||||
try:
|
||||
junit_task.set_run_after(self.javac_task)
|
||||
except AttributeError:
|
||||
pass
|
||||
feature('junit')(make_test)
|
||||
after('apply_java', 'use_javac_files')(make_test)
|
||||
|
||||
class junit_test(Task.Task):
|
||||
color = 'YELLOW'
|
||||
vars = ['JUNIT_EXEC_FLAGS', 'JUNIT_RUNNER']
|
||||
|
||||
def runnable_status(self):
|
||||
"""
|
||||
Only run if --junit was set as an option
|
||||
"""
|
||||
for t in self.run_after:
|
||||
if not t.hasrun:
|
||||
return Task.ASK_LATER
|
||||
|
||||
n = self.generator.path.find_dir(self.generator.junitsrc)
|
||||
if not n:
|
||||
self.generator.bld.fatal('no such junit directory %r' % self.generator.junitsrc)
|
||||
self.base = n
|
||||
|
||||
# make sure the tests are executed whenever the .class files change
|
||||
self.inputs = n.ant_glob('**/*.java')
|
||||
|
||||
ret = super(junit_test, self).runnable_status()
|
||||
if ret == Task.SKIP_ME:
|
||||
if getattr(Options.options, 'junit', False):
|
||||
ret = Task.RUN_ME
|
||||
return ret
|
||||
|
||||
def run(self):
|
||||
cmd = []
|
||||
cmd.extend(self.env.JAVA)
|
||||
cmd.append('-classpath')
|
||||
cmd.append(self.generator.javac_task.env.CLASSPATH + os.pathsep + self.generator.javac_task.env.OUTDIR)
|
||||
cmd.extend(self.env.JUNIT_EXEC_FLAGS)
|
||||
cmd.append(self.env.JUNIT_RUNNER)
|
||||
cmd.extend([x.path_from(self.base).replace('.java', '').replace(os.sep, '.') for x in self.inputs])
|
||||
return self.exec_command(cmd)
|
||||
|
34
playground/eclipse/java/src/com/meow/Hello.java
Normal file
34
playground/eclipse/java/src/com/meow/Hello.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.meow; // obligatory
|
||||
|
||||
public class Hello
|
||||
{
|
||||
int m_var = 0;
|
||||
public Hello()
|
||||
{
|
||||
this.m_var = 2;
|
||||
}
|
||||
|
||||
class MyHelperClass
|
||||
{
|
||||
MyHelperClass() { }
|
||||
int someHelperMethod(int z, int q) { return 2; }
|
||||
}
|
||||
|
||||
public Object makeObj(String name)
|
||||
{
|
||||
final String objName = "My name is " + name;
|
||||
|
||||
return new Object() {
|
||||
public String toString()
|
||||
{
|
||||
return objName;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
System.out.println("Hello, world");
|
||||
}
|
||||
}
|
||||
|
2
playground/eclipse/java/src/com/meow/package-info.java
Normal file
2
playground/eclipse/java/src/com/meow/package-info.java
Normal file
@ -0,0 +1,2 @@
|
||||
package com.meow;
|
||||
|
34
playground/eclipse/java/src/com/meow/truc/bar/Hello.java
Normal file
34
playground/eclipse/java/src/com/meow/truc/bar/Hello.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.meow.truc.bar; // obligatory
|
||||
|
||||
public class Hello
|
||||
{
|
||||
int m_var = 0;
|
||||
public Hello()
|
||||
{
|
||||
this.m_var = 2;
|
||||
}
|
||||
|
||||
class MyHelperClass
|
||||
{
|
||||
MyHelperClass() { }
|
||||
int someHelperMethod(int z, int q) { return 2; }
|
||||
}
|
||||
|
||||
public Object makeObj(String name)
|
||||
{
|
||||
final String objName = "My name is " + name;
|
||||
|
||||
return new Object() {
|
||||
public String toString()
|
||||
{
|
||||
return objName;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
System.out.println("Hello, world");
|
||||
}
|
||||
}
|
||||
|
34
playground/eclipse/java/src/com/meow/truc/foo/Hello.java
Normal file
34
playground/eclipse/java/src/com/meow/truc/foo/Hello.java
Normal file
@ -0,0 +1,34 @@
|
||||
package com.meow.truc.foo; // obligatory
|
||||
|
||||
public class Hello
|
||||
{
|
||||
int m_var = 0;
|
||||
public Hello()
|
||||
{
|
||||
this.m_var = 2;
|
||||
}
|
||||
|
||||
class MyHelperClass
|
||||
{
|
||||
MyHelperClass() { }
|
||||
int someHelperMethod(int z, int q) { return 2; }
|
||||
}
|
||||
|
||||
public Object makeObj(String name)
|
||||
{
|
||||
final String objName = "My name is " + name;
|
||||
|
||||
return new Object() {
|
||||
public String toString()
|
||||
{
|
||||
return objName;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
System.out.println("Hello, world");
|
||||
}
|
||||
}
|
||||
|
10
playground/eclipse/java/sup/org/test/Hella.java
Normal file
10
playground/eclipse/java/sup/org/test/Hella.java
Normal file
@ -0,0 +1,10 @@
|
||||
package org.test; // obligatory
|
||||
|
||||
public class Hella
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
System.out.println("Hella, world");
|
||||
}
|
||||
}
|
||||
|
56
playground/eclipse/java/wscript
Normal file
56
playground/eclipse/java/wscript
Normal file
@ -0,0 +1,56 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Thomas Nagy, 2006-2010 (ita)
|
||||
|
||||
"""
|
||||
java example
|
||||
|
||||
The gcj compiler has a very different command-line - see playground/gcj
|
||||
"""
|
||||
|
||||
VERSION = '0.0.4'
|
||||
APPNAME = 'java_test'
|
||||
|
||||
top = '.'
|
||||
out = 'build'
|
||||
|
||||
def options(opt):
|
||||
try:
|
||||
opt.load('junit', tooldir='.')
|
||||
except:
|
||||
pass
|
||||
|
||||
def configure(conf):
|
||||
conf.load('java')
|
||||
|
||||
try:
|
||||
ret = conf.load('junit', tooldir='.')
|
||||
conf.env.DO_JUNIT = True
|
||||
except:
|
||||
pass
|
||||
|
||||
conf.check_java_class('java.io.FileOutputStream')
|
||||
conf.check_java_class('FakeClass')
|
||||
|
||||
conf.env.CLASSPATH_NNN = ['aaaa.jar', 'bbbb.jar']
|
||||
|
||||
def build(bld):
|
||||
|
||||
bld(features = 'javac jar javadoc',
|
||||
srcdir = 'src/', # folder containing the sources to compile
|
||||
outdir = 'src', # folder where to output the classes (in the build directory)
|
||||
compat = '1.6', # java compatibility version number
|
||||
sourcepath = ['src', 'sup'],
|
||||
classpath = ['.', '..'],
|
||||
#jaropts = '-C default/src/ .', # can be used to give files
|
||||
basedir = 'src', # folder containing the classes and other files to package (must match outdir)
|
||||
destfile = 'foo.jar', # do not put the destfile in the folder of the java classes!
|
||||
use = 'NNN',
|
||||
|
||||
# javadoc
|
||||
javadoc_package = ['com.meow' , 'com.meow.truc.bar', 'com.meow.truc.foo'],
|
||||
javadoc_output = 'javadoc',
|
||||
)
|
||||
|
||||
bld.recurse('animals cats')
|
||||
|
30
playground/eclipse/python/mod1/src/mod1/Mod1ObjOri.py
Normal file
30
playground/eclipse/python/mod1/src/mod1/Mod1ObjOri.py
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
"""
|
||||
Class mod1 for tests
|
||||
|
||||
Doctest examples:
|
||||
|
||||
>>> a = Mod1Class("pippo")
|
||||
>>> a.getMyName()
|
||||
'pippo from obj1 _init_'
|
||||
|
||||
>>> a = Mod1Class("pLuTo")
|
||||
>>> a.getMyName()
|
||||
'pLuTo from obj1 _init_'
|
||||
|
||||
"""
|
||||
|
||||
class Mod1Class(object):
|
||||
|
||||
def __init__(self, pName):
|
||||
"""
|
||||
Constructor stores pName in myName and appends the class string marker
|
||||
"""
|
||||
self.val = 1
|
||||
self.myName = pName + " from obj1 _init_"
|
||||
|
||||
def getMyName(self):
|
||||
"""
|
||||
getMyName in Mod1Class returns the name as is
|
||||
"""
|
||||
return self.myName
|
0
playground/eclipse/python/mod1/src/mod1/__init__.py
Normal file
0
playground/eclipse/python/mod1/src/mod1/__init__.py
Normal file
13
playground/eclipse/python/mod2/src/mod2/Mod2ObjOri.py
Normal file
13
playground/eclipse/python/mod2/src/mod2/Mod2ObjOri.py
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
class Mod2Class(object):
|
||||
def __init__(self, pName):
|
||||
self.myName = pName + " from obj2 _init_"
|
||||
self.testVal = 2
|
||||
|
||||
def getMyName(self):
|
||||
"""
|
||||
getMyName in Mod2Class returns the name all uppercase
|
||||
"""
|
||||
|
||||
return self.myName.upper()
|
0
playground/eclipse/python/mod2/src/mod2/__init__.py
Normal file
0
playground/eclipse/python/mod2/src/mod2/__init__.py
Normal file
11
playground/eclipse/python/mod3/src/mod3/Mod3ObjOri.py
Normal file
11
playground/eclipse/python/mod3/src/mod3/Mod3ObjOri.py
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
import mod2.Mod2ObjOri
|
||||
|
||||
class Mod3Class(mod2.Mod2ObjOri.Mod2Class):
|
||||
|
||||
def getMyName(self):
|
||||
"""
|
||||
getMyName in Mod3Class returns the name all lowercase
|
||||
"""
|
||||
return self.myName.lower()
|
0
playground/eclipse/python/mod3/src/mod3/__init__.py
Normal file
0
playground/eclipse/python/mod3/src/mod3/__init__.py
Normal file
24
playground/eclipse/python/prg/src/prg1.py
Normal file
24
playground/eclipse/python/prg/src/prg1.py
Normal file
@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import mod1.Mod1ObjOri
|
||||
import mod2.Mod2ObjOri
|
||||
import mod3.Mod3ObjOri
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Creating obj1 with string pippo")
|
||||
obj1 = mod1.Mod1ObjOri.Mod1Class("pippo")
|
||||
|
||||
a = 1
|
||||
|
||||
print("Creating obj1 with string pLUto")
|
||||
obj2 = mod2.Mod2ObjOri.Mod2Class("pLUto")
|
||||
|
||||
print("Creating obj3 with string pLUto")
|
||||
obj3 = mod3.Mod3ObjOri.Mod3Class("pLUto")
|
||||
|
||||
print("Hello World, this are my results:")
|
||||
print(obj1.getMyName())
|
||||
print(obj2.getMyName())
|
||||
print(obj3.getMyName())
|
19
playground/eclipse/python/wscript
Normal file
19
playground/eclipse/python/wscript
Normal file
@ -0,0 +1,19 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
def options(opt):
|
||||
opt.load('python')
|
||||
|
||||
def configure(conf):
|
||||
conf.load('python')
|
||||
conf.check_python_version(minver=(2, 7, 0))
|
||||
|
||||
|
||||
def build(bld):
|
||||
bld(name='mod1', features='py', source=bld.path.ant_glob('mod1/src/**/*.py'), install_from='mod1/src')
|
||||
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')
|
||||
|
||||
# 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')
|
56
playground/eclipse/wscript
Normal file
56
playground/eclipse/wscript
Normal file
@ -0,0 +1,56 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Federico Pellegrin 2017 (fedepell)
|
||||
|
||||
"""
|
||||
Example source tree to be used with eclipse extra.
|
||||
|
||||
First of all load the extra:
|
||||
|
||||
...
|
||||
def options(opt):
|
||||
opt.load('eclipse')
|
||||
|
||||
def configure(conf):
|
||||
conf.load('eclipse')
|
||||
...
|
||||
|
||||
Then after configuring the project you can anytime run:
|
||||
|
||||
waf eclipse
|
||||
|
||||
This will generate the needed configuration files for Eclipse:
|
||||
-) .project is generic Eclipse project file
|
||||
-) .cproject for C/C++ CDT
|
||||
-) .classpath for Java JDT
|
||||
-) .pydevproject for Pydev)
|
||||
|
||||
The example contains three directories with different supported languages
|
||||
to demonstrate the features working for each of them, most importantly the
|
||||
automatic addition of search paths for each language so referencing objects
|
||||
or files in the IDE is done correctly. This is equivalent to configure
|
||||
Eclipse by hand using Project->Properties and then each language menu.
|
||||
|
||||
Also the generic invocation for building and cleaning are redefined so
|
||||
waf is called correctly when the respective actions are requested.
|
||||
"""
|
||||
|
||||
|
||||
module_list = 'c java python'
|
||||
out = 'build'
|
||||
|
||||
def options(opt):
|
||||
opt.load('eclipse')
|
||||
# We recurse options in our submodules
|
||||
opt.recurse(module_list)
|
||||
|
||||
|
||||
def configure(conf):
|
||||
conf.load('eclipse')
|
||||
# We recurse configurations in our submodules
|
||||
conf.recurse(module_list)
|
||||
|
||||
|
||||
def build(bld):
|
||||
bld.recurse(module_list)
|
||||
|
Loading…
Reference in New Issue
Block a user