2
0
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:
Federico Pellegrin 2017-05-18 22:16:43 +02:00 committed by ita1024
parent 003f9dd5a8
commit b0eb986e9a
26 changed files with 542 additions and 0 deletions

View 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;
}
}

View File

@ -0,0 +1,4 @@
#define HELLO_LIMIT 5
int check_smaller(int value);

View 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;
}

View 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')

View File

@ -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!");
}
}

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Created-By: Waf 1.6.2 (rev >= 10780)

View File

@ -0,0 +1,9 @@
package org.example;
class Animal {
public String sound() {
return null;
}
}

View 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']

View File

@ -0,0 +1,14 @@
package org.example;
import org.example.Animal;
class Cat extends Animal {
public String sound() {
return "Meow!";
}
}

View 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'
)

View 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)

View 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");
}
}

View File

@ -0,0 +1,2 @@
package com.meow;

View 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");
}
}

View 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");
}
}

View File

@ -0,0 +1,10 @@
package org.test; // obligatory
public class Hella
{
public static void main(String args[])
{
System.out.println("Hella, world");
}
}

View 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')

View 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

View 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()

View 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()

View 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())

View 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')

View 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)