Generate target id based on subdirectory instead of subproject

Allows creation of targets with same name in different subdirectories.
Closes #2861 and closes #1867
pull/3246/head
Aleksey Filippov 7 years ago
parent c58dd64f8e
commit cb761718f0
  1. 15
      mesonbuild/build.py
  2. 6
      run_unittests.py
  3. 0
      test cases/common/183 same target name/file.c
  4. 0
      test cases/common/183 same target name/meson.build
  5. 0
      test cases/common/183 same target name/sub/file2.c
  6. 0
      test cases/common/183 same target name/sub/meson.build

@ -310,11 +310,16 @@ a hard error in the future.''' % name)
def get_id(self):
# This ID must also be a valid file name on all OSs.
# It should also avoid shell metacharacters for obvious
# reasons.
base = self.name + self.type_suffix()
if self.subproject == '':
return base
return self.subproject + '@@' + base
# reasons. '@' is not used as often as '_' in source code names.
# In case of collisions consider using checksums.
# FIXME replace with assert when slash in names is prohibited
name_part = self.name.replace('/', '@').replace('\\', '@')
assert not has_path_sep(self.type_suffix())
myid = name_part + self.type_suffix()
if self.subdir:
subdir_part = self.subdir.replace('/', '@').replace('\\', '@')
myid = subdir_part + '@@' + myid
return myid
def process_kwargs(self, kwargs):
if 'build_by_default' in kwargs:

@ -1117,7 +1117,7 @@ class AllPlatformTests(BasePlatformTests):
incs = [a for a in shlex.split(execmd) if a.startswith("-I")]
self.assertEqual(len(incs), 9)
# target private dir
self.assertPathEqual(incs[0], "-Isub4/someexe@exe")
self.assertPathEqual(incs[0], "-Isub4/sub4@@someexe@exe")
# target build subdir
self.assertPathEqual(incs[1], "-Isub4")
# target source subdir
@ -2601,8 +2601,8 @@ class LinuxlikeTests(BasePlatformTests):
def test_unity_subproj(self):
testdir = os.path.join(self.common_test_dir, '49 subproject')
self.init(testdir, extra_args='--unity=subprojects')
self.assertPathExists(os.path.join(self.builddir, 'subprojects/sublib/sublib@@simpletest@exe/simpletest-unity.c'))
self.assertPathExists(os.path.join(self.builddir, 'subprojects/sublib/sublib@@sublib@sha/sublib-unity.c'))
self.assertPathExists(os.path.join(self.builddir, 'subprojects/sublib/subprojects@sublib@@simpletest@exe/simpletest-unity.c'))
self.assertPathExists(os.path.join(self.builddir, 'subprojects/sublib/subprojects@sublib@@sublib@sha/sublib-unity.c'))
self.assertPathDoesNotExist(os.path.join(self.builddir, 'user@exe/user-unity.c'))
self.build()

Loading…
Cancel
Save