77#include < clang/Tooling/CompilationDatabase.h>
88#include < clang/Tooling/Tooling.h>
99
10+ #include < filesystem>
11+
1012#include " compat/platform_flags.h"
1113#include " frontend_action.h"
1214
@@ -24,7 +26,7 @@ std::string TranspileSrc(std::string_view cc_code, Model model,
2426 std::string rs_code;
2527 clang::tooling::runToolOnCodeWithArgs (
2628 std::make_unique<FrontendAction>(rs_code, model, true , rules_dir),
27- cc_code, tool_args, filename. ends_with ( " .c " ) ? " input.c " : " input.cpp " ,
29+ cc_code, tool_args, filename,
2830 filename.ends_with (" .c" ) ? CLANG_C_COMPILER : CLANG_CXX_COMPILER);
2931 return rs_code;
3032}
@@ -49,6 +51,18 @@ std::string TranspileDir(std::string_view build_dir, Model model,
4951 clang::tooling::ArgumentInsertPosition::BEGIN));
5052 Tool.appendArgumentsAdjuster (clang::tooling::getInsertArgumentAdjuster (
5153 getPlatformClangEndFlags (), clang::tooling::ArgumentInsertPosition::END));
54+ // Redefine __FILE__ to use just the basename, so the generated code
55+ // doesn't contain system-specific absolute paths.
56+ Tool.appendArgumentsAdjuster (
57+ [](const clang::tooling::CommandLineArguments &args,
58+ llvm::StringRef filename) {
59+ auto result = args;
60+ auto basename =
61+ std::filesystem::path (filename.str ()).filename ().string ();
62+ result.push_back (" -Wno-builtin-macro-redefined" );
63+ result.push_back (" -D__FILE__=\" " + basename + " \" " );
64+ return result;
65+ });
5266
5367 std::string rs_code;
5468 FrontendActionFactory factory (rs_code, model, rules_dir);
0 commit comments