From 035602430034325c8f56f369fae401049eb4f867 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 5 Jul 2015 12:46:23 +0300 Subject: [PATCH] Give top level targets unique private directories even if they share a basename with some other top level target. --- backends.py | 2 +- ninjabackend.py | 16 ++++++++-------- test cases/common/86 same basename/lib.c | 12 ++++++++++++ test cases/common/86 same basename/meson.build | 7 +++++-- test cases/common/86 same basename/shar.c | 3 --- test cases/common/86 same basename/stat.c | 3 --- 6 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 test cases/common/86 same basename/lib.c delete mode 100644 test cases/common/86 same basename/shar.c delete mode 100644 test cases/common/86 same basename/stat.c diff --git a/backends.py b/backends.py index 8ce73a543..851ed51fe 100644 --- a/backends.py +++ b/backends.py @@ -71,7 +71,7 @@ class Backend(): return dirname def get_target_private_dir(self, target): - dirname = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir') + dirname = os.path.join(self.get_target_dir(target), target.get_basename() + target.type_suffix()) os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True) return dirname diff --git a/ninjabackend.py b/ninjabackend.py index f00cc5b28..e3bb90c5b 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -217,7 +217,7 @@ class NinjaBackend(backends.Backend): else: for src in gensource.get_outfilelist(): if self.environment.is_object(src): - obj_list.append(os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', src)) + obj_list.append(os.path.join(self.get_target_private_dir(target), src)) elif not self.environment.is_header(src): if is_unity: if '/' in src: @@ -590,7 +590,7 @@ class NinjaBackend(backends.Backend): a = '-resource:' + rel_sourcefile elif r.endswith('.txt') or r.endswith('.resx'): ofilebase = os.path.splitext(os.path.basename(r))[0] + '.resources' - ofilename = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', ofilebase) + ofilename = os.path.join(self.get_target_private_dir(target), ofilebase) elem = NinjaBuildElement(ofilename, "CUSTOM_COMMAND", rel_sourcefile) elem.add_item('COMMAND', ['resgen', rel_sourcefile, ofilename]) elem.add_item('DESC', 'Compiling resource %s.' % rel_sourcefile) @@ -663,7 +663,7 @@ class NinjaBackend(backends.Backend): if not s.endswith('.vala'): continue vapibase = os.path.basename(s.fname)[:-4] + 'vapi' - rel_vapi = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', vapibase) + rel_vapi = os.path.join(self.get_target_private_dir(target), vapibase) args = ['--fast-vapi=' + rel_vapi] rel_s = s.rel_to_builddir(self.build_to_src) element = NinjaBuildElement(rel_vapi, valac.get_language() + '_COMPILER', rel_s) @@ -703,7 +703,7 @@ class NinjaBackend(backends.Backend): (vapibase, rel_vapi) = vapi_info args += ['--use-fast-vapi=' + rel_vapi] vapi_order_deps.append(rel_vapi) - relsc = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', sc) + relsc = os.path.join(self.get_target_private_dir(target), sc) rel_s = s.rel_to_builddir(self.build_to_src) args += ['--deps', relsc + '.d'] if self.environment.coredata.werror: @@ -815,7 +815,7 @@ class NinjaBackend(backends.Backend): scriptdir = self.environment.get_script_dir() outfile.write('\n') symrule = 'rule SHSYM\n' - symcmd = ' command = "%s" "%s" "%s" "%s" $CROSS\n' % (ninja_quote(sys.executable), + symcmd = ' command = "%s" "%s" %s %s $CROSS\n' % (ninja_quote(sys.executable), ninja_quote(os.path.join(scriptdir, 'symbolextractor.py')), '$in', '$out') synstat = ' restat = 1\n' @@ -1080,7 +1080,7 @@ rule FORTRAN_DEP_HACK def get_fortran_deps(self, compiler, src, target): mod_files = [] usere = re.compile(r"\s*use\s+(\w+)", re.IGNORECASE) - dirname = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir') + dirname = self.get_target_private_dir(target) tdeps= self.fortran_deps[target.get_basename()] for line in open(src): usematch = usere.match(line) @@ -1182,12 +1182,12 @@ rule FORTRAN_DEP_HACK # Dependency hack. Remove once multiple outputs in Ninja is fixed: # https://groups.google.com/forum/#!topic/ninja-build/j-2RfBIOd_8 for modname, srcfile in self.fortran_deps[target.get_basename()].items(): - modfile = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', + modfile = os.path.join(self.get_target_private_dir(target), compiler.module_name_to_filename(modname)) if srcfile == src: depelem = NinjaBuildElement(modfile, 'FORTRAN_DEP_HACK', rel_obj) depelem.write(outfile) - commands += compiler.get_module_outdir_args(os.path.join(self.get_target_dir(target), target.get_basename() + '.dir')) + commands += compiler.get_module_outdir_args(self.get_target_private_dir(target)) element = NinjaBuildElement(rel_obj, compiler_name, rel_src) for d in header_deps: diff --git a/test cases/common/86 same basename/lib.c b/test cases/common/86 same basename/lib.c new file mode 100644 index 000000000..11ce3b3f9 --- /dev/null +++ b/test cases/common/86 same basename/lib.c @@ -0,0 +1,12 @@ +#if defined SHAR +int func() { + return 1; +} +#elif defined STAT +int func() { + return 0; +} +#else +#error "Missing type definition." +#endif + diff --git a/test cases/common/86 same basename/meson.build b/test cases/common/86 same basename/meson.build index 5d9cb723c..ba88dfdc9 100644 --- a/test cases/common/86 same basename/meson.build +++ b/test cases/common/86 same basename/meson.build @@ -1,7 +1,10 @@ project('same basename', 'c') -stlib = static_library('name', 'stat.c') -shlib = shared_library('name', 'shar.c') +# Use the same source file to check that each top level target +# has its own unique working directory. If they don't +# then the .o files will clobber each other. +stlib = static_library('name', 'lib.c', c_args : '-DSTAT') +shlib = shared_library('name', 'lib.c', c_args : '-DSHAR') exe1 = executable('name', 'exe1.c', link_with : stlib) exe2 = executable('name2', 'exe2.c', link_with : shlib) diff --git a/test cases/common/86 same basename/shar.c b/test cases/common/86 same basename/shar.c deleted file mode 100644 index bc1e7b0a1..000000000 --- a/test cases/common/86 same basename/shar.c +++ /dev/null @@ -1,3 +0,0 @@ -int func() { - return 1; -} diff --git a/test cases/common/86 same basename/stat.c b/test cases/common/86 same basename/stat.c deleted file mode 100644 index 6f1c172d6..000000000 --- a/test cases/common/86 same basename/stat.c +++ /dev/null @@ -1,3 +0,0 @@ -int func() { - return 0; -}