[build] Fix handling of cog header deps

The last commit was a bandaid, but this needed a real fix. Now we create
a .parse_deps.phony file in every module build dir that implicitly
depends on that module's dependencies' .parse_deps.phony files, as well
as order-only depends on any cog-parsed output for that module. This
causes the cog files to get generated first if they never have been, but
still leaves real header dependency tracking to clang's depfile
generation.
This commit is contained in:
Justin C. Miller
2022-01-08 15:34:47 -08:00
parent 488f2df869
commit 2ff7a0864b
5 changed files with 33 additions and 44 deletions

View File

@@ -73,3 +73,6 @@ rule strip
objcopy --only-keep-debug $out $debug; $
strip -g $out; $
objcopy --add-gnu-debuglink=$debug $out
rule touch
command = touch $out

View File

@@ -113,14 +113,19 @@ class Module:
includes.append(f"${{module_dir}}/{p}")
libs = []
child_deps = []
order_only = []
closed = set()
children = set(self.depmods)
while children:
child = children.pop()
closed.add(child)
includes += [f"${{target_dir}}/{child.name}.dir/{i}" for i in child.includes]
includes += [f"{child.root}/{i}" for i in child.includes]
child_deps.append(f"${{target_dir}}/{child.name}.dir/.parse_dep.phony")
if child.kind == "lib":
libs.append(f"${{target_dir}}/{child.output}")
else:
@@ -135,7 +140,7 @@ class Module:
build.variable("libs", ["${libs}"] + libs)
inputs = []
implicits = []
parse_deps = []
for start in self.sources:
source = start
@@ -144,30 +149,41 @@ class Module:
output = source.output
if source.action.rule:
build.newline()
build.build(
rule = source.action.rule,
outputs = output.input,
inputs = source.input,
implicit = list(map(resolve, source.deps)),
implicit = list(map(resolve, source.deps)) +
list(source.action.deps),
variables = {"name": source.name},
)
elif source.action.implicit:
implicits.append(source.input)
parse_deps.append(source.input)
else:
inputs.append(source.input)
source = output
parse_dep = "${module_dir}/.parse_dep.phony"
build.newline()
build.build(
rule = "touch",
outputs = [parse_dep],
implicit = child_deps,
order_only = parse_deps,
)
output = f"${{target_dir}}/{self.output}"
dump = f"${{target_dir}}/{self.output}.dump"
build.newline()
build.build(
rule = self.kind,
outputs = output,
inputs = inputs,
implicit = implicits + libs,
implicit = [parse_dep] + libs,
order_only = order_only,
)

View File

@@ -2,6 +2,7 @@ class Action:
name = property(lambda self: self.__name)
implicit = property(lambda self: False)
rule = property(lambda self: None)
deps = property(lambda self: tuple())
def __init__(self, name):
self.__name = name
@@ -12,6 +13,7 @@ class Action:
class Compile(Action):
rule = property(lambda self: f'compile_{self.name}')
deps = property(lambda self: ("${module_dir}/.parse_dep.phony",))
def __init__(self, name, suffix = ".o"):
super().__init__(name)
@@ -46,6 +48,7 @@ class Source:
'.cog': Parse('cog'),
'.o': Link('o'),
'.h': Header('h'),
'.inc': Header('inc'),
}
def __init__(self, root, path, output=None, deps=tuple()):

View File

@@ -21,11 +21,3 @@ boot = module("boot",
"support.cpp",
"video.cpp",
])
boot.add_depends([
"main.cpp",
"memory_map.cpp",
"paging.cpp",
], [
"${target_dir}/bootproto.dir/include/bootproto/memory.h",
])

View File

@@ -33,6 +33,7 @@ kernel = module("kernel",
"logger.cpp",
"main.cpp",
"memory.cpp",
"memory.h.cog",
"memory_bootstrap.cpp",
"msr.cpp",
"objects/channel.cpp",
@@ -48,7 +49,10 @@ kernel = module("kernel",
"printf/printf.c",
"scheduler.cpp",
"serial.cpp",
"syscall.cpp.cog",
"syscall.h.cog",
"syscall.s",
"syscalls.inc.cog",
"syscalls/channel.cpp",
"syscalls/endpoint.cpp",
"syscalls/object.cpp",
@@ -67,36 +71,7 @@ from os.path import join
layout = join(source_root, "definitions/memory_layout.csv")
definitions = glob('definitions/**/*.def', recursive=True)
sysinc = kernel.add_input("syscalls.inc.cog", deps=definitions)
memh = kernel.add_input("memory.h.cog", deps=[layout])
sysh = kernel.add_input("syscall.h.cog", deps=definitions)
sysc = kernel.add_input("syscall.cpp.cog", deps=definitions + [sysh])
kernel.add_depends(["syscall.s"], [sysinc])
kernel.add_depends(["main.cpp", "cpu.cpp"], [sysh])
kernel.add_depends(["main.cpp", "cpu.cpp"], [sysh])
kernel.add_depends([
"apic.cpp",
"device_manager.cpp",
"frame_allocator.cpp",
"heap_allocator.cpp",
"heap_allocator.h",
"interrupts.cpp",
"log.cpp",
"main.cpp",
"memory_bootstrap.cpp",
"memory.cpp",
"objects/channel.cpp",
"objects/thread.cpp",
"objects/vm_area.cpp",
"page_table.cpp",
"page_tree.cpp",
"syscalls/system.cpp",
"tss.cpp",
"vm_space.cpp",
],
[memh])
kernel.add_depends(["memory.h.cog"], [layout])
kernel.add_depends(["syscall.cpp.cog", "syscall.h.cog", "syscalls.inc.cog"], definitions)
kernel.variables['ldflags'] = ["${ldflags}", "-T", "${source_root}/src/kernel/kernel.ld"]