backends: Make object_filename_from_source() backend-agnostic

Some backends may need to use its own target directories instead of
our default one. For this, introduce an optional argument "targetdir"
that will still use our default one when not specified.
pull/12784/head
Albert Tang 1 year ago committed by Eli Schwartz
parent d2740cf0d1
commit df6926250d
  1. 14
      mesonbuild/backend/backends.py
  2. 4
      mesonbuild/backend/vs2010backend.py
  3. 2
      mesonbuild/backend/xcodebackend.py

@ -834,7 +834,7 @@ class Backend:
fname = fname.replace(ch, '_')
return hashed + fname
def object_filename_from_source(self, target: build.BuildTarget, source: 'FileOrString') -> str:
def object_filename_from_source(self, target: build.BuildTarget, source: 'FileOrString', targetdir: T.Optional[str] = None) -> str:
assert isinstance(source, mesonlib.File)
if isinstance(target, build.CompileTarget):
return target.sources_map[source]
@ -855,9 +855,8 @@ class Backend:
elif source.is_built:
if os.path.isabs(rel_src):
rel_src = rel_src[len(build_dir) + 1:]
targetdir = self.get_target_private_dir(target)
# A meson- prefixed directory is reserved; hopefully no-one creates a file name with such a weird prefix.
gen_source = 'meson-generated_' + os.path.relpath(rel_src, targetdir)
gen_source = 'meson-generated_' + os.path.relpath(rel_src, self.get_target_private_dir(target))
else:
if os.path.isabs(rel_src):
# Use the absolute path directly to avoid file name conflicts
@ -866,7 +865,10 @@ class Backend:
gen_source = os.path.relpath(os.path.join(build_dir, rel_src),
os.path.join(self.environment.get_source_dir(), target.get_subdir()))
machine = self.environment.machines[target.for_machine]
return self.canonicalize_filename(gen_source) + '.' + machine.get_object_suffix()
ret = self.canonicalize_filename(gen_source) + '.' + machine.get_object_suffix()
if targetdir is not None:
return os.path.join(targetdir, ret)
return ret
def _determine_ext_objs(self, extobj: 'build.ExtractedObjects', proj_dir_to_build_root: str) -> T.List[str]:
result: T.List[str] = []
@ -920,8 +922,8 @@ class Backend:
sources.append(_src)
for osrc in sources:
objname = self.object_filename_from_source(extobj.target, osrc)
objpath = os.path.join(proj_dir_to_build_root, targetdir, objname)
objname = self.object_filename_from_source(extobj.target, osrc, targetdir)
objpath = os.path.join(proj_dir_to_build_root, objname)
result.append(objpath)
return result

@ -1448,12 +1448,10 @@ class Vs2010Backend(backends.Backend):
extra_link_args.append(path[:-len(gen_src_ext)] + '.obj')
for src in l.srclist:
obj_basename = None
if self.environment.is_source(src):
obj_basename = self.object_filename_from_source(t, src)
target_private_dir = self.relpath(self.get_target_private_dir(t),
self.get_target_dir(t))
rel_obj = os.path.join(target_private_dir, obj_basename)
rel_obj = self.object_filename_from_source(t, src, target_private_dir)
extra_link_args.append(rel_obj)
extra_link_args.extend(self.flatten_object_list(t))

@ -230,7 +230,7 @@ class XCodeBackend(backends.Backend):
os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True)
return dirname
def object_filename_from_source(self, target: build.BuildTarget, source: mesonlib.FileOrString) -> str:
def object_filename_from_source(self, target: build.BuildTarget, source: mesonlib.FileOrString, targetdir: T.Optional[str] = None) -> str:
# Xcode has the following naming scheme:
# projectname.build/debug/prog@exe.build/Objects-normal/x86_64/func.o
project = self.build.project_name

Loading…
Cancel
Save