3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """Tool-specific initialization for rmic.
26 There normally shouldn't be any need to import this module directly.
27 It will usually be imported through the generic SCons.Tool.Tool()
38 from SCons
.Tool
.JavaCommon
import get_java_install_dirs
41 def emit_rmic_classes(target
, source
, env
):
42 """Create and return lists of Java RMI stub and skeleton
43 class files to be created from a set of class files.
45 class_suffix
= env
.get('JAVACLASSSUFFIX', '.class')
46 classdir
= env
.get('JAVACLASSDIR')
55 classdir
= s
.attributes
.java_classdir
56 except AttributeError:
58 classdir
= env
.Dir(classdir
).rdir()
59 if str(classdir
) == '.':
62 c_
= str(classdir
) + os
.sep
67 classname
= src
.attributes
.java_classname
68 except AttributeError:
70 if c_
and classname
[:len(c_
)] == c_
:
71 classname
= classname
[len(c_
):]
72 if class_suffix
and classname
[:-len(class_suffix
)] == class_suffix
:
73 classname
= classname
[-len(class_suffix
):]
75 s
.attributes
.java_classdir
= classdir
76 s
.attributes
.java_classname
= classname
79 stub_suffixes
= ['_Stub']
80 if env
.get('JAVAVERSION') == '1.4':
81 stub_suffixes
.append('_Skel')
85 for suff
in stub_suffixes
:
86 fname
= s
.attributes
.java_classname
.replace('.', os
.sep
) + \
88 t
= target
[0].File(fname
)
89 t
.attributes
.java_lookupdir
= target
[0]
94 RMICAction
= SCons
.Action
.Action('$RMICCOM', '$RMICCOMSTR')
96 RMICBuilder
= SCons
.Builder
.Builder(action
= RMICAction
,
97 emitter
= emit_rmic_classes
,
98 src_suffix
= '$JAVACLASSSUFFIX',
99 target_factory
= SCons
.Node
.FS
.Dir
,
100 source_factory
= SCons
.Node
.FS
.File
)
102 def generate(env
) -> None:
103 """Add Builders and construction variables for rmic to an Environment."""
104 env
['BUILDERS']['RMIC'] = RMICBuilder
106 if env
['PLATFORM'] == 'win32':
107 version
= env
.get('JAVAVERSION', None)
108 # Ensure that we have a proper path for rmic
109 paths
= get_java_install_dirs('win32', version
=version
)
110 rmic
= SCons
.Tool
.find_program_path(env
, 'rmic', default_paths
=paths
)
111 # print("RMIC: %s"%rmic)
113 rmic_bin_dir
= os
.path
.dirname(rmic
)
114 env
.AppendENVPath('PATH', rmic_bin_dir
)
117 env
['RMICFLAGS'] = SCons
.Util
.CLVar('')
118 env
['RMICCOM'] = '$RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} -classpath ${SOURCE.attributes.java_classdir} ${SOURCES.attributes.java_classname}'
119 env
['JAVACLASSSUFFIX'] = '.class'
121 def exists(env
) -> bool:
122 # As reported by Jan Nijtmans in issue #2730, the simple
123 # return env.Detect('rmic')
124 # doesn't always work during initialization. For now, we
125 # stop trying to detect an executable (analogous to the
127 # TODO: Come up with a proper detect() routine...and enable it.
132 # indent-tabs-mode:nil
134 # vim: set expandtab tabstop=4 shiftwidth=4: