File tree 3 files changed +47
-4
lines changed
3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -504,6 +504,28 @@ ScopedTempDirectory(
504
504
}
505
505
}
506
506
507
+ ScopedTempDirectory::
508
+ ScopedTempDirectory (
509
+ llvm::StringRef root,
510
+ llvm::StringRef dir)
511
+ {
512
+ llvm::SmallString<128 > tempPath (root);
513
+ llvm::sys::path::append (tempPath, dir);
514
+ bool const exists = llvm::sys::fs::exists (tempPath);
515
+ if (exists)
516
+ {
517
+ ok_ = !llvm::sys::fs::remove_directories (tempPath);
518
+ if (!ok_)
519
+ {
520
+ return ;
521
+ }
522
+ }
523
+ ok_ = !llvm::sys::fs::create_directory (tempPath);
524
+ if (ok_)
525
+ {
526
+ path_ = tempPath;
527
+ }
528
+ }
507
529
508
530
} // mrdocs
509
531
} // clang
Original file line number Diff line number Diff line change @@ -107,17 +107,37 @@ class ScopedTempDirectory
107
107
<tempdir>/<prefix><random>
108
108
@endcode
109
109
110
+ For instance, if the prefix is "mrdocs" and the operating system
111
+ is Unix, the directory might be created as: "/tmp/mrdocs-1234".
112
+
113
+ On Windows, the directory might be created as:
114
+ "C:\Users\user\AppData\Local\Temp\mrdocs-1234".
115
+
110
116
@param prefix The prefix for the temporary directory name.
111
117
*/
112
118
ScopedTempDirectory (llvm::StringRef prefix);
113
119
120
+ /* * Constructor with a specific path
121
+
122
+ Creates a temporary directory with the given path.
123
+ The directory is deleted when this object goes out of scope.
124
+
125
+ @param root The root directory for the temporary directory.
126
+ @param dir The name of the temporary directory.
127
+ */
128
+ ScopedTempDirectory (llvm::StringRef root, llvm::StringRef dir);
129
+
114
130
/* * Returns `true` if the directory was created successfully.
115
131
*/
116
132
operator bool () const { return ok_; }
117
133
118
134
/* * Returns the path to the temporary directory.
119
135
*/
120
- llvm::StringRef path () const { return path_; }
136
+ std::string_view path () const { return static_cast <llvm::StringRef>(path_); }
137
+
138
+ /* * Convert temp directory to a std::string_view
139
+ */
140
+ operator std::string_view () const { return path (); }
121
141
};
122
142
123
143
} // mrdocs
Original file line number Diff line number Diff line change @@ -127,15 +127,16 @@ DoGenerateAction(
127
127
if (compilationDatabasePath.empty ())
128
128
{
129
129
std::string c = files::appendPath (settings.sourceRoot , " CMakeLists.txt" );
130
- if (files::exists (c)) {
130
+ if (files::exists (c))
131
+ {
131
132
compilationDatabasePath = c;
132
133
}
133
134
}
134
135
MRDOCS_CHECK (
135
136
compilationDatabasePath,
136
137
" The compilation database path argument is missing" );
137
- ScopedTempDirectory tempDir (" mrdocs " );
138
- std::string buildPath = files::appendPath (tempDir. path () , " build" );
138
+ ScopedTempDirectory tempDir (config-> settings (). output , " .temp " );
139
+ std::string buildPath = files::appendPath (tempDir, " build" );
139
140
Expected<std::string> const compileCommandsPathExp =
140
141
generateCompileCommandsFile (
141
142
compilationDatabasePath, settings.cmake , buildPath);
You can’t perform that action at this time.
0 commit comments