Fixed ninja binary location logic to use ninja.BIN_DIR. Previous logic no longer...
[scons.git] / SCons / Tool / rmic.py
bloba5d8063697d4bb4e1101667c5d0e2ada8d5807f5
1 # MIT License
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()
28 selection method.
29 """
31 import os.path
33 import SCons.Action
34 import SCons.Builder
35 import SCons.Node.FS
36 import SCons.Util
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.
44 """
45 class_suffix = env.get('JAVACLASSSUFFIX', '.class')
46 classdir = env.get('JAVACLASSDIR')
48 if not classdir:
49 try:
50 s = source[0]
51 except IndexError:
52 classdir = '.'
53 else:
54 try:
55 classdir = s.attributes.java_classdir
56 except AttributeError:
57 classdir = '.'
58 classdir = env.Dir(classdir).rdir()
59 if str(classdir) == '.':
60 c_ = None
61 else:
62 c_ = str(classdir) + os.sep
64 slist = []
65 for src in source:
66 try:
67 classname = src.attributes.java_classname
68 except AttributeError:
69 classname = str(src)
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):]
74 s = src.rfile()
75 s.attributes.java_classdir = classdir
76 s.attributes.java_classname = classname
77 slist.append(s)
79 stub_suffixes = ['_Stub']
80 if env.get('JAVAVERSION') == '1.4':
81 stub_suffixes.append('_Skel')
83 tlist = []
84 for s in source:
85 for suff in stub_suffixes:
86 fname = s.attributes.java_classname.replace('.', os.sep) + \
87 suff + class_suffix
88 t = target[0].File(fname)
89 t.attributes.java_lookupdir = target[0]
90 tlist.append(t)
92 return tlist, source
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)
112 if rmic:
113 rmic_bin_dir = os.path.dirname(rmic)
114 env.AppendENVPath('PATH', rmic_bin_dir)
116 env['RMIC'] = 'rmic'
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
126 # javac Builder).
127 # TODO: Come up with a proper detect() routine...and enable it.
128 return True
130 # Local Variables:
131 # tab-width:4
132 # indent-tabs-mode:nil
133 # End:
134 # vim: set expandtab tabstop=4 shiftwidth=4: