Skip to content

Commit

Permalink
selfhost: List dependencies of main output file in generated depfile
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpfard committed Oct 1, 2023
1 parent 33990ef commit d55eb2f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions selfhost/main.jakt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ fn find_with_extension(path: Path, extension: String) throws -> [Path] {
return files_found
}

fn escape_for_depfile(anon input: String) throws -> String {
// $ -> $$, # -> \#, <space> -> \<space>
return input.replace(replace: "$", with: "$$").replace(replace: "#", with: "\\#").replace(replace: " ", with: "\\ ")
}

fn compiler_main(anon args: [String]) throws -> c_int {
mut args_parser = ArgsParser::from_args(args)

Expand Down Expand Up @@ -873,6 +878,21 @@ fn compiler_main(anon args: [String]) throws -> c_int {

mut depfile_builder = StringBuilder::create()

if generate_depfile.has_value() {
if link_archive.has_value() {
depfile_builder.append(escape_for_depfile(binary_dir.join(link_archive!).to_string()))
} else {
depfile_builder.append(escape_for_depfile(output_filename))
}
depfile_builder.append(" : ")
for (file, _) in codegen_result {
let path = binary_dir.join(file)
depfile_builder.append(" \\\n ")
depfile_builder.append(escape_for_depfile(path.to_string()))
}
depfile_builder.append("\n")
}

if not binary_dir.exists() {
make_directory(path: binary_dir.to_string())
}
Expand All @@ -886,13 +906,14 @@ fn compiler_main(anon args: [String]) throws -> c_int {
return 1
}

if generate_depfile.has_value() and file.ends_with(".cpp") {
let escaped = file.replace(replace: " ", with: "\\ ")
let escaped_module_file_path = module_file_path.replace(replace: " ", with: "\\ ")
if generate_depfile.has_value() and file.ends_with(".cpp") and module_file_path != "__prelude__" {
let f = binary_dir.join(file).to_string()
let escaped = escape_for_depfile(f)
let escaped_module_file_path = escape_for_depfile(module_file_path)
depfile_builder.append_string(format(
"{} {}.h: {}"
escaped
escaped.substring(start: 0, length: file.length() - 4)
escaped.substring(start: 0, length: escaped.length() - 4)
escaped_module_file_path
))
depfile_builder.append(b'\n')
Expand Down

0 comments on commit d55eb2f

Please sign in to comment.