Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Mar 12, 2024
1 parent 9ca79d6 commit 5c71631
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
15 changes: 10 additions & 5 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,9 @@ def get_target_generated_dir(
# target that the GeneratedList is used in
return os.path.join(self.get_target_private_dir(target), src)

def compute_build_subdir(self, subdir: str, target: T.Union[build.Target, build.CustomTargetIndex]) -> str:
if target.is_native_cross():
assert subdir.startswith('subprojects')
return 'subprojects-native' + subdir[11:]
return subdir
@classmethod
def compute_build_subdir(cls, subdir: str, target: T.Union[build.Target, build.CustomTargetIndex]) -> str:
return compute_build_subdir(subdir, target.is_native_cross())

def get_unity_source_file(self, target: T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex],
suffix: str, number: int) -> mesonlib.File:
Expand Down Expand Up @@ -2052,3 +2050,10 @@ def compile_target_to_generator(self, target: build.CompileTarget) -> build.Gene
all_sources = T.cast('_ALL_SOURCES_TYPE', target.sources) + T.cast('_ALL_SOURCES_TYPE', target.generated)
return self.compiler_to_generator(target, target.compiler, all_sources,
target.output_templ, target.depends)


def compute_build_subdir(subdir: str, is_native_cross: bool) -> str:
if is_native_cross:
assert subdir.startswith('subprojects')
return 'subprojects-native' + subdir[11:]
return subdir
6 changes: 6 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,12 +1036,18 @@ def process_compilers(self) -> T.List[str]:
# are expected to be able to add arbitrary non-source files to the
# sources list
for s in sources:
print(">>>>>>>>")
for lang, compiler in self.all_compilers.items():
print("lang:", lang, "compiler:", compiler)
if compiler.can_compile(s):
print("\tcan_compile? yes")
if lang not in self.compilers:
self.compilers[lang] = compiler
break
else:
print("\tcan_compile? nope")
else:
print("<<<<<<<< nope!")
if is_known_suffix(s):
path = pathlib.Path(str(s)).as_posix()
m = f'No {self.for_machine.get_lower_case_name()} machine compiler for {path!r}'
Expand Down
27 changes: 22 additions & 5 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
FileMode, MachineChoice, OptionKey, listify,
extract_as_list, has_path_sep, path_is_in_root, PerMachine)
from ..programs import ExternalProgram, NonExistingExternalProgram
from ..backend.backends import compute_build_subdir
from ..dependencies import Dependency
from ..depfile import DepFile
from ..interpreterbase import ContainerTypeInfo, InterpreterBase, KwargInfo, typed_kwargs, typed_pos_args
Expand Down Expand Up @@ -853,7 +854,8 @@ def run_command_impl(self,

return RunProcess(cmd, expanded_args, env, srcdir, builddir, self.subdir,
self.environment.get_build_command() + ['introspect'],
in_builddir=in_builddir, check=check, capture=capture)
in_builddir=in_builddir, is_native_cross=self.coredata.is_native_clone,
check=check, capture=capture)

def func_option(self, nodes, args, kwargs):
raise InterpreterException('Tried to call option() in build description file. All options must be in the option file.')
Expand Down Expand Up @@ -886,7 +888,10 @@ def find_subproject(self, subp_name: str, native: bool) -> T.Optional[Subproject
return x

def _make_subproject_id(self, subp_name: str, native: bool) -> T.Tuple[str, MachineChoice]:
for_machine = MachineChoice.BUILD if native else MachineChoice.HOST
if self.coredata.is_native_clone:
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.BUILD if native else MachineChoice.HOST
return (subp_name, for_machine)

def disabled_subproject(self, subp_name: str, subp_id: str, disabled_feature: T.Optional[str] = None,
Expand Down Expand Up @@ -998,7 +1003,7 @@ def _do_subproject_meson(self, subp_name: str, subp_id: str, subdir: str,
mlog.log('Generated Meson AST:', meson_filename)
mlog.cmd_ci_include(meson_filename)

is_native_cross = native and self.coredata.is_cross_build()
is_native_cross = native and self.coredata.is_cross_build() and not self.coredata.is_native_clone
if is_native_cross:
new_build = self.build.copy_to_native()
default_options = {k.as_build(): v for k, v in default_options.items()}
Expand Down Expand Up @@ -1371,8 +1376,16 @@ def func_add_languages(self, node: mparser.FunctionNode, args: T.Tuple[T.List[st
mlog.log('Compiler for language', mlog.bold(lang), 'skipped: feature', mlog.bold(feature), 'disabled')
return False
if native is not None:
return self.add_languages(langs, required, self.machine_from_native_kwarg(kwargs))
print("add_langauges() A")
print("using machine:", self.machine_from_native_kwarg(kwargs))
for_machine = self.machine_from_native_kwarg(kwargs)
success = self.add_languages(langs, required, for_machine)
if self.coredata.is_native_clone:
other_machine = MachineChoice.BUILD if for_machine is MachineChoice.HOST else MachineChoice.HOST
success &= self.add_languages(langs, required, other_machine)
return success
else:
print("add_langauges() B")
# absent 'native' means 'both' for backwards compatibility
tv = FeatureNew.get_target_version(self.subproject)
if FeatureNew.check_version(tv, '0.54.0'):
Expand Down Expand Up @@ -2451,7 +2464,9 @@ def func_subdir(self, node: mparser.BaseNode, args: T.Tuple[str], kwargs: 'kwtyp
raise InvalidArguments(f'Tried to enter directory "{subdir}", which has already been visited.')
self.processed_buildfiles.add(build_file)
self.subdir = subdir
os.makedirs(os.path.join(self.environment.build_dir, subdir), exist_ok=True)
os.makedirs(os.path.join(self.environment.build_dir,
compute_build_subdir(subdir, self.coredata.is_native_clone)),
exist_ok=True)
buildfilename = os.path.join(self.subdir, environment.build_filename)
self.build_def_files.add(buildfilename)
absname = os.path.join(self.environment.get_source_dir(), buildfilename)
Expand Down Expand Up @@ -2691,6 +2706,8 @@ def func_configure_file(self, node: mparser.BaseNode, args: T.List[TYPE_var],
ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname)

output_subdir = self.environment.build_output_rpath(self.subdir)
print("=== configure_file()")
print("output_subdir:", output_subdir)

# Perform the appropriate action
if kwargs['configuration'] is not None:
Expand Down
13 changes: 10 additions & 3 deletions mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .. import mlog

from ..modules import ModuleReturnValue, ModuleObject, ModuleState, ExtensionModule
from ..backend.backends import TestProtocol
from ..backend.backends import TestProtocol, compute_build_subdir
from ..interpreterbase import (
ContainerTypeInfo, KwargInfo, MesonOperator,
MesonInterpreterObject, ObjectHolder, MutableInterpreterObject,
Expand Down Expand Up @@ -209,13 +209,16 @@ def __init__(self,
subdir: str,
mesonintrospect: T.List[str],
in_builddir: bool = False,
is_native_cross: bool = False,
check: bool = False,
capture: bool = True) -> None:
super().__init__()
if not isinstance(cmd, ExternalProgram):
raise AssertionError('BUG: RunProcess must be passed an ExternalProgram')
self.capture = capture
self.returncode, self.stdout, self.stderr = self.run_command(cmd, args, env, source_dir, build_dir, subdir, mesonintrospect, in_builddir, check)
self.returncode, self.stdout, self.stderr = self.run_command(cmd, args, env, source_dir, build_dir,
subdir, mesonintrospect, in_builddir,
is_native_cross, check)
self.methods.update({'returncode': self.returncode_method,
'stdout': self.stdout_method,
'stderr': self.stderr_method,
Expand All @@ -230,6 +233,7 @@ def run_command(self,
subdir: str,
mesonintrospect: T.List[str],
in_builddir: bool,
is_native_cross: bool,
check: bool = False) -> T.Tuple[int, str, str]:
command_array = cmd.get_command() + args
menv = {'MESON_SOURCE_ROOT': source_dir,
Expand All @@ -238,9 +242,12 @@ def run_command(self,
'MESONINTROSPECT': ' '.join([shlex.quote(x) for x in mesonintrospect]),
}
if in_builddir:
cwd = os.path.join(build_dir, subdir)
print("XXX: A, subdir:", subdir)
cwd = os.path.join(build_dir, compute_build_subdir(subdir, is_native_cross))
else:
print("XXX: B, subdir:", subdir)
cwd = os.path.join(source_dir, subdir)
print("XXX: cwd:", cwd)
child_env = os.environ.copy()
child_env.update(menv)
child_env = env.get_env(child_env)
Expand Down

0 comments on commit 5c71631

Please sign in to comment.