Skip to content

Commit

Permalink
modules: generates per-target modinfo
Browse files Browse the repository at this point in the history
This patch changes the way modinfo is generated and built. Instead of
one modinfo.c it generates one modinfo-<target>-softmmu.c per target. It
aims a fine-tune control of modules by configuring Kconfig.

Signed-off-by: Jose R. Ziviani <[email protected]>
Signed-off-by: Dario Faggioli <[email protected]>
Message-Id: <165369003038.5857.13084289285185196779.stgit@work>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Jose R. Ziviani authored and bonzini committed Jun 6, 2022
1 parent 24ce7aa commit 05d6814
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
25 changes: 17 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3175,14 +3175,23 @@ foreach d, list : target_modules
endforeach

if enable_modules
modinfo_src = custom_target('modinfo.c',
output: 'modinfo.c',
input: modinfo_files,
command: [modinfo_generate, '@INPUT@'],
capture: true)
modinfo_lib = static_library('modinfo', modinfo_src)
modinfo_dep = declare_dependency(link_whole: modinfo_lib)
softmmu_ss.add(modinfo_dep)
foreach target : target_dirs
if target.endswith('-softmmu')
config_target = config_target_mak[target]
config_devices_mak = target + '-config-devices.mak'
modinfo_src = custom_target('modinfo-' + target + '.c',
output: 'modinfo-' + target + '.c',
input: modinfo_files,
command: [modinfo_generate, '--devices', config_devices_mak, '@INPUT@'],
capture: true)

modinfo_lib = static_library('modinfo-' + target + '.c', modinfo_src)
modinfo_dep = declare_dependency(link_with: modinfo_lib)

arch = config_target['TARGET_NAME'] == 'sparc64' ? 'sparc64' : config_target['TARGET_BASE_ARCH']
hw_arch[arch].add(modinfo_dep)
endif
endforeach
endif

nm = find_program('nm')
Expand Down
49 changes: 35 additions & 14 deletions scripts/modinfo-generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def parse_line(line):
continue
return (kind, data)

def generate(name, lines):
def generate(name, lines, enabled):
arch = ""
objs = []
deps = []
Expand All @@ -49,7 +49,13 @@ def generate(name, lines):
elif kind == 'arch':
arch = data;
elif kind == 'kconfig':
pass # ignore
# don't add a module which dependency is not enabled
# in kconfig
if data.strip() not in enabled:
print(" /* module {} isn't enabled in Kconfig. */"
.format(data.strip()))
print("/* },{ */")
return None
else:
print("unknown:", kind)
exit(1)
Expand All @@ -60,8 +66,8 @@ def generate(name, lines):
print_array("objs", objs)
print_array("deps", deps)
print_array("opts", opts)
print("},{");
return deps
print("},{")
return {dep.strip('" ') for dep in deps}

def print_pre():
print("/* generated by scripts/modinfo-generate.py */")
Expand All @@ -74,23 +80,38 @@ def print_post():
print("}};")

def main(args):
deps = {}
if len(args) < 3 or args[0] != '--devices':
print('Expected: modinfo-generate.py --devices '
'config-device.mak [modinfo files]', file=sys.stderr)
exit(1)

# get all devices enabled in kconfig, from *-config-device.mak
enabled = set()
with open(args[1]) as file:
for line in file.readlines():
config = line.split('=')
if config[1].rstrip() == 'y':
enabled.add(config[0][7:]) # remove CONFIG_

deps = set()
modules = set()
print_pre()
for modinfo in args:
for modinfo in args[2:]:
with open(modinfo) as f:
lines = f.readlines()
print(" /* %s */" % modinfo)
(basename, ext) = os.path.splitext(modinfo)
deps[basename] = generate(basename, lines)
(basename, _) = os.path.splitext(modinfo)
moddeps = generate(basename, lines, enabled)
if moddeps is not None:
modules.add(basename)
deps.update(moddeps)
print_post()

flattened_deps = {flat.strip('" ') for dep in deps.values() for flat in dep}
error = False
for dep in flattened_deps:
if dep not in deps.keys():
print("Dependency {} cannot be satisfied".format(dep),
file=sys.stderr)
error = True
for dep in deps.difference(modules):
print("Dependency {} cannot be satisfied".format(dep),
file=sys.stderr)
error = True

if error:
exit(1)
Expand Down

0 comments on commit 05d6814

Please sign in to comment.