@@ -47,7 +47,7 @@ Author: Leonardo de Moura
47
47
#include " util/path.h"
48
48
#include " stdlib_flags.h"
49
49
50
- namespace fs = std::filesystem;
50
+ namespace fs = std::__fs:: filesystem;
51
51
52
52
53
53
#ifdef LEAN_TRACY
@@ -847,23 +847,31 @@ extern "C" LEAN_EXPORT int lean_main(int argc, char ** argv) {
847
847
display_cumulative_profiling_times (std::cerr);
848
848
849
849
850
- fs::path profile_filename = std::string (fs::current_path () / *c_output);
850
+ // take the output C path, normalize it, and use the normalized path for dumping CSV info.
851
+ const fs::path canonical_c_outpath = [&]() {
852
+ fs::path c_outpath = fs::absolute (fs::current_path () / (std::string (*c_output)));
853
+ std::error_code ec;
854
+ fs::path out = fs::canonical (c_outpath, ec);
855
+ if (ec) { return c_outpath; }
856
+ return out;
857
+ }
858
+ std::string profile_filename (std::string (canonical_c_outpath) + " .profile.csv" );
851
859
// replace all '/' with '+' in filepath to avoid creating subdirectories
852
860
std::replace (profile_filename.begin (), profile_filename.end (), ' /' , ' +' );
853
- fs::path outdir = LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH;
861
+ const fs::path outdir ( LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH) ;
854
862
assert (outdir.is_directory () && " LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH must be a directory" );
855
863
assert (outdir.is_absolute () && " LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH must be an absolute path" );
856
864
// make outdir if necessary
857
865
if (!fs::exists (outdir)) { fs::create_directories (outdir); }
858
- fs::path profiling_path = outdir / profile_filename;
866
+ const fs::path profiling_path = outdir / profile_filename;
859
867
860
868
if (profiling_path == " " ) {
861
869
std::cerr << " WARN: LEAN_RESEARCH_COMPILER_PROFILE_CSV_PATH ('" << profiling_path << " ') is empty" ;
862
870
} else {
863
871
if (profiling_path == " -" ) {
864
872
profiler.write_profiling_times (mod_fn, profiling_path, std::cerr, c_output);
865
873
} else {
866
- std::ofstream profiler_out_file (profiling_path, std::ios::app );
874
+ std::ofstream profiler_out_file (profiling_path);
867
875
profiler.write_profiling_times (mod_fn, profiling_path, profiler_out_file, c_output);
868
876
}
869
877
}
0 commit comments