"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "SCons/Tool/jar.py" between
SCons-4.3.0.tar.gz and SCons-4.4.0.tar.gz

About: SCons is a software construction tool (a Python script and a set of modules as a superior alternative to the classic "Make" build tool).

jar.py  (SCons-4.3.0):jar.py  (SCons-4.4.0)
skipping to change at line 32 skipping to change at line 32
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Tool-specific initialization for jar. """Tool-specific initialization for jar.
There normally shouldn't be any need to import this module directly. There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool() It will usually be imported through the generic SCons.Tool.Tool()
selection method. selection method.
""" """
import os import os
from typing import List
import SCons.Node
import SCons.Node.FS
import SCons.Subst import SCons.Subst
import SCons.Tool
import SCons.Util import SCons.Util
import SCons.Warnings import SCons.Warnings
from SCons.Node.FS import _my_normcase from SCons.Node.FS import _my_normcase
from SCons.Tool.JavaCommon import get_java_install_dirs from SCons.Tool.JavaCommon import get_java_install_dirs
def jarSources(target, source, env, for_signature): def jarSources(target, source, env, for_signature) -> List[str]:
"""Only include sources that are not a manifest file.""" """Only include sources that are not a manifest file."""
try: try:
env['JARCHDIR'] env['JARCHDIR']
except KeyError: except KeyError:
jarchdir_set = False jarchdir_set = False
else: else:
jarchdir_set = True jarchdir_set = True
jarchdir = env.subst('$JARCHDIR', target=target, source=source) jarchdir = env.subst('$JARCHDIR', target=target, source=source)
if jarchdir: if jarchdir:
jarchdir = env.fs.Dir(jarchdir) jarchdir = env.fs.Dir(jarchdir)
result = [] result = []
for src in source: for src in source:
contents = src.get_text_contents() contents = src.get_text_contents()
if not contents.startswith("Manifest-Version"): if contents.startswith("Manifest-Version"):
if jarchdir_set: continue
_chdir = jarchdir if jarchdir_set:
else: _chdir = jarchdir
try: else:
_chdir = src.attributes.java_classdir try:
except AttributeError: _chdir = src.attributes.java_classdir
_chdir = None except AttributeError:
if _chdir: _chdir = None
# If we are changing the dir with -C, then sources should if _chdir:
# be relative to that directory. # If we are changing the dir with -C, then sources should
src = SCons.Subst.Literal(src.get_path(_chdir)) # be relative to that directory.
result.append('-C') src = SCons.Subst.Literal(src.get_path(_chdir))
result.append(_chdir) result.append('-C')
result.append(src) result.append(_chdir)
result.append(src)
return result return result
def jarManifest(target, source, env, for_signature): def jarManifest(target, source, env, for_signature):
"""Look in sources for a manifest file, if any.""" """Look in sources for a manifest file, if any."""
for src in source: for src in source:
contents = src.get_text_contents() contents = src.get_text_contents()
if contents.startswith("Manifest-Version"): if contents.startswith("Manifest-Version"):
return src return src
return '' return ''
def jarFlags(target, source, env, for_signature): def jarFlags(target, source, env, for_signature) -> str:
"""If we have a manifest, make sure that the 'm' """If we have a manifest, make sure that the 'm'
flag is specified.""" flag is specified."""
jarflags = env.subst('$JARFLAGS', target=target, source=source) jarflags = env.subst('$JARFLAGS', target=target, source=source)
for src in source: for src in source:
contents = src.get_text_contents() contents = src.get_text_contents()
if contents.startswith("Manifest-Version"): if contents.startswith("Manifest-Version"):
if 'm' not in jarflags: if 'm' not in jarflags:
return jarflags + 'm' return jarflags + 'm'
break break
return jarflags return jarflags
def Jar(env, target = None, source = [], *args, **kw): def Jar(env, target=None, source=[], *args, **kw):
""" """The Jar Builder.
A pseudo-Builder wrapper around the separate Jar sources{File,Dir}
Builders. This is a pseudo-Builder wrapper around the separate jar builders
depending on whether the sources are a file list or a directory.
""" """
# TODO: W1113: Keyword argument before variable positional arguments list in
the definition of Jar function
# TODO: W0102: Dangerous default value [] as argument
# jar target should not be a list so assume they passed # jar target should not be a list so assume they passed
# no target and want implicit target to be made and the arg # no target and want implicit target to be made and the arg
# was actaully the list of sources # was actaully the list of sources
if SCons.Util.is_List(target) and source == []: if SCons.Util.is_List(target) and source == []:
SCons.Warnings.warn( SCons.Warnings.warn(
SCons.Warnings.SConsWarning, SCons.Warnings.SConsWarning,
"Making implicit target jar file, and treating the list as sources" "Making implicit target jar file, and treating the list as sources"
) )
source = target source = target
target = None target = None
# mutiple targets pass so build each target the same from the # mutiple targets passed so build each target the same from the
# same source # same source
#TODO Maybe this should only be done once, and the result copied #TODO Maybe this should only be done once, and the result copied
# for each target since it should result in the same? # for each target since it should result in the same?
if SCons.Util.is_List(target) and SCons.Util.is_List(source): if SCons.Util.is_List(target) and SCons.Util.is_List(source):
jars = [] jars = []
for single_target in target: for single_target in target:
jars += env.Jar( target = single_target, source = source, *args, **k w) jars += env.Jar(target=single_target, source=source, *args, **kw)
return jars return jars
# they passed no target so make a target implicitly # they passed no target so make a target implicitly
if target is None: if target is None:
try: try:
# make target from the first source file # make target from the first source file
target = os.path.splitext(str(source[0]))[0] + env.subst('$JARSUFFIX ') target = os.path.splitext(str(source[0]))[0] + env.subst('$JARSUFFIX ')
except: except:
# TODO: W0702: No exception type(s) specified
# something strange is happening but attempt anyways # something strange is happening but attempt anyways
SCons.Warnings.warn( SCons.Warnings.warn(
SCons.Warnings.SConsWarning, SCons.Warnings.SConsWarning,
"Could not make implicit target from sources, using directory" "Could not make implicit target from sources, using directory"
) )
target = os.path.basename(str(env.Dir('.'))) + env.subst('$JARSUFFIX ') target = os.path.basename(str(env.Dir('.'))) + env.subst('$JARSUFFIX ')
# make lists out of our target and sources # make lists out of our target and sources
if not SCons.Util.is_List(target): if not SCons.Util.is_List(target):
target = [target] target = [target]
skipping to change at line 145 skipping to change at line 154
# setup for checking through all the sources and handle accordingly # setup for checking through all the sources and handle accordingly
java_class_suffix = env.subst('$JAVACLASSSUFFIX') java_class_suffix = env.subst('$JAVACLASSSUFFIX')
java_suffix = env.subst('$JAVASUFFIX') java_suffix = env.subst('$JAVASUFFIX')
target_nodes = [] target_nodes = []
# function for determining what to do with a file and not a directory # function for determining what to do with a file and not a directory
# if its already a class file then it can be used as a # if its already a class file then it can be used as a
# source for jar, otherwise turn it into a class file then # source for jar, otherwise turn it into a class file then
# return the source # return the source
def file_to_class(s): def file_to_class(src):
if _my_normcase(str(s)).endswith(java_suffix): if _my_normcase(str(src)).endswith(java_suffix):
return env.JavaClassFile(source = s, *args, **kw) return env.JavaClassFile(source=src, *args, **kw)
else: return [env.fs.File(src)]
return [env.fs.File(s)]
# function for calling the JavaClassDir builder if a directory is # function for calling the JavaClassDir builder if a directory is
# passed as a source to Jar builder. The JavaClassDir builder will # passed as a source to Jar builder. The JavaClassDir builder will
# return an empty list if there were not target classes built from # return an empty list if there were no target classes built from
# the directory, in this case assume the user wanted the directory # the directory, in this case assume the user wanted the directory
# copied into the jar as is (it contains other files such as # copied into the jar as is (it contains other files such as
# resources or class files compiled from proir commands) # resources or class files compiled from prior commands)
# TODO: investigate the expexcted behavior for directories that # TODO: investigate the expexcted behavior for directories that
# have mixed content, such as Java files along side other files # have mixed content, such as Java files along side other files
# files. # files.
def dir_to_class(s): def dir_to_class(src):
dir_targets = env.JavaClassDir(source = s, *args, **kw) dir_targets = env.JavaClassDir(source=src, *args, **kw)
if dir_targets == []: if dir_targets == []:
# no classes files could be built from the source dir # no classes files could be built from the source dir
# so pass the dir as is. # so pass the dir as is.
return [env.fs.Dir(s)] return [env.fs.Dir(src)]
else: return dir_targets
return dir_targets
# loop through the sources and handle each accordingly # loop through the sources and handle each accordingly
# the goal here is to get all the source files into a class # the goal here is to get all the source files into a class
# file or a directory that contains class files # file or a directory that contains class files
for s in SCons.Util.flatten(source): for src in SCons.Util.flatten(source):
s = env.subst(s) src = env.subst(src)
if isinstance(s, SCons.Node.FS.Base): if isinstance(src, SCons.Node.FS.Base):
if isinstance(s, SCons.Node.FS.File): if isinstance(src, SCons.Node.FS.File):
# found a file so make sure its a class file # found a file so make sure its a class file
target_nodes.extend(file_to_class(s)) target_nodes.extend(file_to_class(src))
else: else:
# found a dir so get the class files out of it # found a dir so get the class files out of it
target_nodes.extend(dir_to_class(s)) target_nodes.extend(dir_to_class(src))
else: else:
try: try:
# source is string try to convert it to file # source is string try to convert it to file
target_nodes.extend(file_to_class(env.fs.File(s))) target_nodes.extend(file_to_class(env.fs.File(src)))
continue continue
except: except:
# TODO: W0702: No exception type(s) specified
pass pass
try: try:
# source is string try to covnert it to dir # source is string try to covnert it to dir
target_nodes.extend(dir_to_class(env.fs.Dir(s))) target_nodes.extend(dir_to_class(env.fs.Dir(src)))
continue continue
except: except:
# TODO: W0702: No exception type(s) specified
pass pass
SCons.Warnings.warn( SCons.Warnings.warn(
SCons.Warnings.SConsWarning, SCons.Warnings.SConsWarning,
("File: " + str(s) ("File: " + str(src)
+ " could not be identified as File or Directory, skipping.") + " could not be identified as File or Directory, skipping.")
) )
# at this point all our sources have been converted to classes or directorie # at this point all our sources have been converted to classes or
s of class # directories of class so pass it to the Jar builder
# so pass it to the Jar builder return env.JarFile(target=target, source=target_nodes, *args, **kw)
return env.JarFile(target = target, source = target_nodes, *args, **kw)
def generate(env): def generate(env) -> None:
"""Add Builders and construction variables for jar to an Environment.""" """Add Builders and construction variables for jar to an Environment."""
SCons.Tool.CreateJarBuilder(env) SCons.Tool.CreateJarBuilder(env)
SCons.Tool.CreateJavaFileBuilder(env) SCons.Tool.CreateJavaFileBuilder(env)
SCons.Tool.CreateJavaClassFileBuilder(env) SCons.Tool.CreateJavaClassFileBuilder(env)
SCons.Tool.CreateJavaClassDirBuilder(env) SCons.Tool.CreateJavaClassDirBuilder(env)
env.AddMethod(Jar) env.AddMethod(Jar)
if env['PLATFORM'] == 'win32': if env['PLATFORM'] == 'win32':
# Ensure that we have a proper path for jar # Ensure that we have a proper path for jar
paths = get_java_install_dirs('win32') paths = get_java_install_dirs('win32')
jar = SCons.Tool.find_program_path(env, 'jar', default_paths=paths) jar = SCons.Tool.find_program_path(env, 'jar', default_paths=paths)
if jar: if jar:
jar_bin_dir = os.path.dirname(jar) jar_bin_dir = os.path.dirname(jar)
env.AppendENVPath('PATH', jar_bin_dir) env.AppendENVPath('PATH', jar_bin_dir)
env['JAR'] = 'jar' env['JAR'] = 'jar'
env['JARFLAGS'] = SCons.Util.CLVar('cf') env['JARFLAGS'] = SCons.Util.CLVar('cf')
env['_JARFLAGS'] = jarFlags env['_JARFLAGS'] = jarFlags
env['_JARMANIFEST'] = jarManifest env['_JARMANIFEST'] = jarManifest
env['_JARSOURCES'] = jarSources env['_JARSOURCES'] = jarSources
env['_JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARSOURCES' env['_JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARSOURCES'
env['JARCOM'] = "${TEMPFILE('$_JARCOM','$JARCOMSTR')}" env['JARCOM'] = "${TEMPFILE('$_JARCOM','$JARCOMSTR')}"
env['JARSUFFIX'] = '.jar' env['JARSUFFIX'] = '.jar'
def exists(env): def exists(env):
# As reported by Jan Nijtmans in issue #2730, the simple # As reported by Jan Nijtmans in issue #2730, the simple
# return env.Detect('jar') # return env.Detect('jar')
# doesn't always work during initialization. For now, we # doesn't always work during initialization. For now, we
# stop trying to detect an executable (analogous to the # stop trying to detect an executable (analogous to the
# javac Builder). # javac Builder).
# TODO: Come up with a proper detect() routine...and enable it. # TODO: Come up with a proper detect() routine...and enable it.
return 1 return True
# Local Variables: # Local Variables:
# tab-width:4 # tab-width:4
# indent-tabs-mode:nil # indent-tabs-mode:nil
# End: # End:
# vim: set expandtab tabstop=4 shiftwidth=4: # vim: set expandtab tabstop=4 shiftwidth=4:
 End of changes. 29 change blocks. 
56 lines changed or deleted 65 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)