| 113 | } |
| 114 | |
| 115 | bool recompile_single_function(const N64Recomp::Context& context, size_t func_index, const std::string& recomp_include, const std::filesystem::path& output_path, std::span<std::vector<uint32_t>> static_funcs_out) { |
| 116 | // Open the temporary output file |
| 117 | std::filesystem::path temp_path = output_path; |
| 118 | temp_path.replace_extension(".tmp"); |
| 119 | std::ofstream output_file{ temp_path }; |
| 120 | if (!output_file.good()) { |
| 121 | fmt::print(stderr, "Failed to open file for writing: {}\n", temp_path.string() ); |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | // Write the file header |
| 126 | fmt::print(output_file, |
| 127 | "{}\n" |
| 128 | "\n", |
| 129 | recomp_include); |
| 130 | |
| 131 | if (!N64Recomp::recompile_function(context, func_index, output_file, static_funcs_out, false)) { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | output_file.close(); |
| 136 | |
| 137 | // If a file of the target name exists and it's identical to the output file, delete the output file. |
| 138 | // This prevents updating the existing file so that it doesn't need to be rebuilt. |
| 139 | if (std::filesystem::exists(output_path) && compare_files(output_path, temp_path)) { |
| 140 | std::filesystem::remove(temp_path); |
| 141 | } |
| 142 | // Otherwise, rename the new file to the target path. |
| 143 | else { |
| 144 | std::filesystem::rename(temp_path, output_path); |
| 145 | } |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | std::vector<std::string> reloc_names { |
| 151 | "R_MIPS_NONE ", |
no test coverage detected