Exemplo n.º 1
0
def java_module(bld, **modArgs):
    """
    Builds a module, along with optional tests.
    It makes assumptions, but most can be overridden by passing in args.
    """
    if 'env' in modArgs:
        env = modArgs['env']
    else:
        variant = modArgs.get('variant', bld.env['VARIANT'] or 'default')
        env = bld.all_envs[variant]

    # Basically, if this Java target depends on a JNI target, and for whatever
    # reason we don't have JNI, we don't want to even add the Java target onto
    # the build queue since we won't be able to build it
    native_sourcedir = modArgs.get('native_sourcedir', 'src/jni')
    have_native_sourcedir = bld.path.find_dir(native_sourcedir) is not None
    jni_ok = bld.is_defined('HAVE_JNI_H') or not have_native_sourcedir

    if env['JAVAC'] and env['JAR'] and jni_ok:
       modArgs = dict((k.lower(), v) for k, v in modArgs.iteritems())

       lang = modArgs.get('lang', 'java')
       nlang = modArgs.get('native_lang', 'c')
       libExeType = {'java':'javac'}.get(lang, 'java')
       nsourceExt = {'cxx':'.cpp','c':'.c'}.get(nlang, 'c')
       libName = '%s.jar' % (modArgs['name'])

       path = modArgs.get('path',
                          'dir' in modArgs and bld.path.find_dir(modArgs['dir']) or bld.path)

       module_deps = map(lambda x: '%s-%s' % (x, lang), listify(modArgs.get('module_deps', '')))
       uselib_local = module_deps + listify(modArgs.get('uselib_local', '')) + listify(modArgs.get('use',''))
       uselib = listify(modArgs.get('uselib', '')) + ['JAVA']
       targets_to_add = listify(modArgs.get('targets_to_add', ''))
       classpath = listify(modArgs.get('classpath', ''))
       compat = modArgs.get('compat', '1.5')
       libVersion = modArgs.get('version', None)
       installPath = modArgs.get('install_path', None)
       libInstallPath = modArgs.get('lib_install_path', None)
       manifest = modArgs.get('manifest', None)
       jarcreate = modArgs.get('jarcreate', None)

       if modArgs.get('nosuffix', False) :
           targetName = modArgs['name']
       else :
           targetName = '%s-%s' % (modArgs['name'], lang)

       sourcedir = modArgs.get('sourcedir', 'src/java')

       cp_targets = []
       real_classpath = []
       classpathDirs = [bld.path.find_dir('lib'), bld.path.find_dir('libs'), bld.path.find_dir('../libs')]

       # TODO: There must be a better way in waf to do this - JARS_DIR contains an absolute path
       classpathDirs += [bld.path.find_dir(os.path.relpath(bld.env['JARS_DIR'], bld.path.find_dir('.').abspath()))]
       
       for cp in classpath:
           for dir in classpathDirs:
               if dir is not None and os.path.exists(join(dir.abspath(), cp)):
                   real_classpath.append(join(dir.abspath(), cp))
                   cp_targets.append(bld(name=cp, features='install_tgt', install_path=libInstallPath or '${PREFIX}/lib', dir=dir, files=[cp]))
           if os.path.exists(cp):
               real_classpath.append(cp)

       # We need a try/catch here for the rare case where we have javac but
       # not JNI, we're a module that doesn't depend on JNI, but we depend on
       # another module that DOES depend on JNI.  In that case, the module we
       # depend on won't exist so get_tgen_by_name() will throw.  There's no
       # way to build this module, which is fine - we're just trying not to
       # stop the whole build when something else is targeted.
       for dep in module_deps:
           try:
               tsk = bld.get_tgen_by_name(dep)
               for cp in tsk.classpath:
                   real_classpath.append(cp)
           except:
               return

       #build the jar
       jar = bld(features='javac jar add_targets install_tgt', manifest=manifest, jarcreate=jarcreate, srcdir=sourcedir, classpath=real_classpath, targets_to_add=targets_to_add + cp_targets, 
               use=module_deps, name=targetName, target=targetName, basedir='classes', outdir='classes', destfile=libName, compat=compat, dir=bld.path.get_bld(), files=[libName])

       jar.install_path = installPath or '${PREFIX}/lib'


       if have_native_sourcedir:
           lib = bld(features='%s %sshlib' % (nlang, nlang), includes='%s/include' % native_sourcedir,
                                  target='%s.jni-%s' % (modArgs['name'], nlang), env=env.derive(),
                                  uselib=uselib, use=uselib_local,
                           source=bld.path.find_dir(native_sourcedir).ant_glob('source/*%s' % nsourceExt))

           jar.targets_to_add.append(lib)

           lib.install_path = installPath or '${PREFIX}/lib'

       return jar
Exemplo n.º 2
0
def java_module(bld, **modArgs):
    """
    Builds a module, along with optional tests.
    It makes assumptions, but most can be overridden by passing in args.
    """
    if 'env' in modArgs:
        env = modArgs['env']
    else:
        variant = modArgs.get('variant', bld.env['VARIANT'] or 'default')
        env = bld.all_envs[variant]

    # Basically, if this Java target depends on a JNI target, and for whatever
    # reason we don't have JNI, we don't want to even add the Java target onto
    # the build queue since we won't be able to build it
    native_sourcedir = modArgs.get('native_sourcedir', 'src/jni')
    have_native_sourcedir = bld.path.find_dir(native_sourcedir) is not None
    jni_ok = bld.is_defined('HAVE_JNI_H') or not have_native_sourcedir

    if env['JAVAC'] and env['JAR'] and jni_ok:
        modArgs = dict((k.lower(), v) for k, v in modArgs.iteritems())

        lang = modArgs.get('lang', 'java')
        nlang = modArgs.get('native_lang', 'c')
        libExeType = {'java': 'javac'}.get(lang, 'java')
        nsourceExt = {'cxx': '.cpp', 'c': '.c'}.get(nlang, 'c')
        libName = '%s.jar' % (modArgs['name'])

        path = modArgs.get(
            'path', 'dir' in modArgs and bld.path.find_dir(modArgs['dir'])
            or bld.path)

        module_deps = map(lambda x: '%s-%s' % (x, lang),
                          listify(modArgs.get('module_deps', '')))
        uselib_local = module_deps + listify(modArgs.get(
            'uselib_local', '')) + listify(modArgs.get('use', ''))
        uselib = listify(modArgs.get('uselib', '')) + ['JAVA']
        targets_to_add = listify(modArgs.get('targets_to_add', ''))
        classpath = listify(modArgs.get('classpath', ''))
        compat = modArgs.get('compat', '1.5')
        libVersion = modArgs.get('version', None)
        installPath = modArgs.get('install_path', None)
        libInstallPath = modArgs.get('lib_install_path', None)
        manifest = modArgs.get('manifest', None)
        jarcreate = modArgs.get('jarcreate', None)

        if modArgs.get('nosuffix', False):
            targetName = modArgs['name']
        else:
            targetName = '%s-%s' % (modArgs['name'], lang)

        sourcedir = modArgs.get('sourcedir', 'src/java')

        cp_targets = []
        real_classpath = []
        classpathDirs = [
            bld.path.find_dir('lib'),
            bld.path.find_dir('libs'),
            bld.path.find_dir('../libs')
        ]

        # TODO: There must be a better way in waf to do this - JARS_DIR contains an absolute path
        classpathDirs += [
            bld.path.find_dir(
                os.path.relpath(bld.env['JARS_DIR'],
                                bld.path.find_dir('.').abspath()))
        ]

        for cp in classpath:
            for dir in classpathDirs:
                if dir is not None and os.path.exists(join(dir.abspath(), cp)):
                    real_classpath.append(join(dir.abspath(), cp))
                    cp_targets.append(
                        bld(name=cp,
                            features='install_tgt',
                            install_path=libInstallPath or '${PREFIX}/lib',
                            dir=dir,
                            files=[cp]))
            if os.path.exists(cp):
                real_classpath.append(cp)

        # We need a try/catch here for the rare case where we have javac but
        # not JNI, we're a module that doesn't depend on JNI, but we depend on
        # another module that DOES depend on JNI.  In that case, the module we
        # depend on won't exist so get_tgen_by_name() will throw.  There's no
        # way to build this module, which is fine - we're just trying not to
        # stop the whole build when something else is targeted.
        for dep in module_deps:
            try:
                tsk = bld.get_tgen_by_name(dep)
                for cp in tsk.classpath:
                    real_classpath.append(cp)
            except:
                return

        #build the jar
        jar = bld(features='javac jar add_targets install_tgt',
                  manifest=manifest,
                  jarcreate=jarcreate,
                  srcdir=sourcedir,
                  classpath=real_classpath,
                  targets_to_add=targets_to_add + cp_targets,
                  use=module_deps,
                  name=targetName,
                  target=targetName,
                  basedir='classes',
                  outdir='classes',
                  destfile=libName,
                  compat=compat,
                  dir=bld.path.get_bld(),
                  files=[libName])

        jar.install_path = installPath or '${PREFIX}/lib'

        if have_native_sourcedir:
            lib = bld(features='%s %sshlib' % (nlang, nlang),
                      includes='%s/include' % native_sourcedir,
                      target='%s.jni-%s' % (modArgs['name'], nlang),
                      env=env.derive(),
                      uselib=uselib,
                      use=uselib_local,
                      source=bld.path.find_dir(native_sourcedir).ant_glob(
                          'source/*%s' % nsourceExt))

            jar.targets_to_add.append(lib)

            lib.install_path = installPath or '${PREFIX}/lib'

        return jar
Exemplo n.º 3
0
def java_module(bld, **modArgs):
    """
    Builds a module, along with optional tests.
    It makes assumptions, but most can be overridden by passing in args.
    """
    if 'env' in modArgs:
        env = modArgs['env']
    else:
        variant = modArgs.get('variant', bld.env['VARIANT'] or 'default')
        env = bld.all_envs[variant]

    if env['JAVAC'] and env['JAR']:
       modArgs = dict((k.lower(), v) for k, v in modArgs.iteritems())
           
       lang = modArgs.get('lang', 'java')
       nlang = modArgs.get('native_lang', 'c')
       libExeType = {'java':'javac'}.get(lang, 'java')
       nsourceExt = {'cxx':'.cpp','c':'.c'}.get(nlang, 'c')
       libName = '%s.jar' % (modArgs['name'])
   		
       path = modArgs.get('path',
                          'dir' in modArgs and bld.path.find_dir(modArgs['dir']) or bld.path)
   
       module_deps = map(lambda x: '%s-%s' % (x, lang), listify(modArgs.get('module_deps', '')))
       uselib_local = module_deps + listify(modArgs.get('uselib_local', '')) + listify(modArgs.get('use',''))
       uselib = listify(modArgs.get('uselib', '')) + ['JAVA']
       targets_to_add = listify(modArgs.get('targets_to_add', ''))
       classpath = listify(modArgs.get('classpath', ''))
       compat = modArgs.get('compat', '1.5')
       libVersion = modArgs.get('version', None)
       installPath = modArgs.get('install_path', None)
       libInstallPath = modArgs.get('lib_install_path', None)
       manifest = modArgs.get('manifest', None)
       jarcreate = modArgs.get('jarcreate', None)
   
       if modArgs.get('nosuffix', False) :
           targetName = modArgs['name']
       else :    
           targetName = '%s-%s' % (modArgs['name'], lang)
           
       sourcedir = modArgs.get('sourcedir', 'src/java')
       native_sourcedir = modArgs.get('native_sourcedir', 'src/jni')
   
       cp_targets = []
       real_classpath = []
       classpathDirs = [bld.path.find_dir('lib'), bld.path.find_dir('libs'), bld.path.find_dir('../libs')]
       for cp in classpath:
           for dir in classpathDirs:
               if dir is not None and os.path.exists(join(dir.abspath(), cp)):
                   real_classpath.append(join(dir.abspath(), cp))
                   cp_targets.append(bld(name=cp, features='install_tgt', install_path=libInstallPath or '${PREFIX}/lib', dir=dir, files=[cp]))
   
       for dep in module_deps:
           tsk = bld.get_tgen_by_name(dep)
           for cp in tsk.classpath:
               real_classpath.append(cp)
   		
       #build the jar
       jar = bld(features='javac jar add_targets install_tgt', manifest=manifest, jarcreate=jarcreate, srcdir=sourcedir, classpath=real_classpath, targets_to_add=targets_to_add + cp_targets, 
   		      use=module_deps, name=targetName, target=targetName, basedir='classes', outdir='classes', destfile=libName, compat=compat, dir=bld.path.get_bld(), files=[libName])
   
       jar.install_path = installPath or '${PREFIX}/lib'
           
   
       if bld.is_defined('HAVE_JNI_H') and bld.path.find_dir(native_sourcedir) is not None:
           lib = bld(features='%s %sshlib' % (nlang, nlang), includes='%s/include' % native_sourcedir,
                                  target='%s.jni-%s' % (modArgs['name'], nlang), env=env.derive(),
                                  uselib=uselib, use=uselib_local,
       						   source=bld.path.find_dir(native_sourcedir).ant_glob('source/*%s' % nsourceExt))
   
           jar.targets_to_add.append(lib)
   		
           lib.install_path = installPath or '${PREFIX}/lib'
   			
       return jar