Can create top level targets that have the same name but different type.

pull/197/head
Jussi Pakkanen 10 years ago
parent f03be73f02
commit 833cb56f5c
  1. 17
      build.py
  2. 36
      interpreter.py
  3. 8
      ninjabackend.py
  4. 5
      test cases/common/86 same basename/exe1.c
  5. 5
      test cases/common/86 same basename/exe2.c
  6. 10
      test cases/common/86 same basename/meson.build
  7. 3
      test cases/common/86 same basename/shar.c
  8. 3
      test cases/common/86 same basename/stat.c
  9. 3
      test cases/failing/17 same name/file.c
  10. 4
      test cases/failing/17 same name/meson.build
  11. 3
      test cases/failing/17 same name/sub/file2.c
  12. 1
      test cases/failing/17 same name/sub/meson.build

@ -585,6 +585,8 @@ class Executable(BuildTarget):
else:
self.filename = self.name
def type_suffix(self):
return "@exe"
class StaticLibrary(BuildTarget):
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
@ -601,6 +603,9 @@ class StaticLibrary(BuildTarget):
def get_osx_filename(self):
return self.get_filename()
def type_suffix(self):
return "@sta"
class SharedLibrary(BuildTarget):
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
self.version = None
@ -666,6 +671,9 @@ class SharedLibrary(BuildTarget):
aliases.append(self.get_shbase())
return aliases
def type_suffix(self):
return "@sha"
class CustomTarget:
known_kwargs = {'input' : True,
'output' : True,
@ -788,6 +796,9 @@ class CustomTarget:
def get_generated_sources(self):
return []
def type_suffix(self):
return "@cus"
class RunTarget:
def __init__(self, name, command, args, subdir):
self.name = name
@ -816,6 +827,9 @@ class RunTarget:
def get_filename(self):
return self.name
def type_suffix(self):
return "@run"
class Jar(BuildTarget):
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
super().__init__(name, subdir, is_cross, sources, objects, environment, kwargs);
@ -827,6 +841,9 @@ class Jar(BuildTarget):
def get_main_class(self):
return self.main_class
def type_suffix(self):
return "@jar"
class ConfigureFile():
def __init__(self, subdir, sourcename, targetname, configuration_data):

@ -1373,13 +1373,8 @@ class Interpreter():
if len(args) != 1:
raise InterpreterException('Incorrect number of arguments')
name = args[0]
if name in coredata.forbidden_target_names:
raise InvalidArguments('Target name "%s" is reserved for Meson\'s internal use. Please rename.'\
% name)
if name in self.build.targets:
raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name)
tg = CustomTargetHolder(build.CustomTarget(name, self.subdir, kwargs))
self.build.targets[name] = tg.held_object
self.add_target(name, tg.held_object)
return tg
@stringArgs
@ -1388,15 +1383,10 @@ class Interpreter():
if len(args) < 2:
raise InterpreterException('Incorrect number of arguments')
name = args[0]
if name in coredata.forbidden_target_names:
raise InvalidArguments('Target name "%s" is reserved for Meson\'s internal use. Please rename.'\
% name)
if name in self.build.targets:
raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name)
command = args[1]
cmd_args = args[2:]
tg = RunTargetHolder(name, command, cmd_args, self.subdir)
self.build.targets[name] = tg.held_object
self.add_target(name, tg.held_object)
return tg
def func_generator(self, node, args, kwargs):
@ -1609,6 +1599,19 @@ class Interpreter():
results.append(s)
return results
def add_target(self, name, tobj):
if name in coredata.forbidden_target_names:
raise InvalidArguments('Target name "%s" is reserved for Meson\'s internal use. Please rename.'\
% name)
# To permit an executable and a shared library to have the
# same name, such as "foo.exe" and "libfoo.a".
idname = name + tobj.type_suffix()
if idname in self.build.targets:
raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name)
self.build.targets[idname] = tobj
if idname not in self.coredata.target_guids:
self.coredata.target_guids[idname] = str(uuid.uuid4()).upper()
def build_target(self, node, args, kwargs, targetholder):
name = args[0]
sources = args[1:]
@ -1619,9 +1622,6 @@ class Interpreter():
is_cross = True
else:
is_cross = False
if name in coredata.forbidden_target_names:
raise InvalidArguments('Target name "%s" is reserved for Meson\'s internal use. Please rename.'\
% name)
try:
kw_src = self.flatten(kwargs['sources'])
if not isinstance(kw_src, list):
@ -1634,8 +1634,6 @@ class Interpreter():
kwargs['dependencies'] = self.flatten(kwargs.get('dependencies', []))
if not isinstance(objs, list):
objs = [objs]
if name in self.build.targets:
raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name)
self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources)
if targetholder is ExecutableHolder:
targetclass = build.Executable
@ -1650,9 +1648,7 @@ class Interpreter():
raise RuntimeError('Unreachable code')
target = targetclass(name, self.subdir, is_cross, sources, objs, self.environment, kwargs)
l = targetholder(target)
self.build.targets[name] = l.held_object
if name not in self.coredata.target_guids:
self.coredata.target_guids[name] = str(uuid.uuid4()).upper()
self.add_target(name, l.held_object)
self.global_args_frozen = True
return l

@ -164,7 +164,7 @@ class NinjaBackend(backends.Backend):
self.generate_custom_target(target, outfile)
if isinstance(target, build.RunTarget):
self.generate_run_target(target, outfile)
name = target.get_basename()
name = target.get_basename() + target.type_suffix()
gen_src_deps = []
if name in self.processed_targets:
return
@ -266,7 +266,7 @@ class NinjaBackend(backends.Backend):
def process_target_dependencies(self, target, outfile):
for t in target.get_dependencies():
tname = t.get_basename()
tname = t.get_basename() + t.type_suffix()
if not tname in self.processed_targets:
self.generate_target(t, outfile)
@ -305,7 +305,7 @@ class NinjaBackend(backends.Backend):
elem.add_item('COMMAND', cmd)
elem.add_item('description', 'Generating %s with a custom command.' % target.name)
elem.write(outfile)
self.processed_targets[target.name] = True
self.processed_targets[target.name + target.type_suffix()] = True
def generate_run_target(self, target, outfile):
runnerscript = os.path.join(self.environment.get_script_dir(), 'commandrunner.py')
@ -316,7 +316,7 @@ class NinjaBackend(backends.Backend):
elem.add_item('description', 'Running external command %s.' % target.name)
elem.add_item('pool', 'console')
elem.write(outfile)
self.processed_targets[target.name] = True
self.processed_targets[target.name + target.type_suffix()] = True
def generate_po(self, outfile):
for p in self.build.pot:

@ -0,0 +1,5 @@
int func();
int main(int argc, char **argv) {
return func();
}

@ -0,0 +1,5 @@
int func();
int main(int argc, char **argv) {
return func() == 1 ? 0 : 1;
}

@ -0,0 +1,10 @@
project('same basename', 'c')
stlib = static_library('name', 'stat.c')
shlib = shared_library('name', 'shar.c')
exe1 = executable('name', 'exe1.c', link_with : stlib)
exe2 = executable('name2', 'exe2.c', link_with : shlib)
test('static', exe1)
test('shared', exe2)

@ -0,0 +1,3 @@
int func() {
return 1;
}

@ -0,0 +1,3 @@
int func() {
return 0;
}

@ -0,0 +1,3 @@
int func() {
return 0;
}

@ -0,0 +1,4 @@
project('same name', 'c')
static_library('foo', 'file.c')
subdir('sub')

@ -0,0 +1,3 @@
int func() {
return 5;
}

@ -0,0 +1 @@
static_library('foo', 'file2.c')
Loading…
Cancel
Save