Skip to content

Commit e2474cd

Browse files
committed
CMake uses adjusted output dir
#fix
1 parent fd2709b commit e2474cd

File tree

6 files changed

+104
-13
lines changed

6 files changed

+104
-13
lines changed

include/mrdocs/Config.hpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ class MRDOCS_DECL
111111

112112
/** Full path to the config file directory
113113
114-
The working directory is the directory
115-
of the mrdocs.yml file.
114+
The reference directory for most MrDocs
115+
options is the directory of the
116+
mrdocs.yml file.
116117
117118
It is used to calculate full paths
118119
from relative paths.
@@ -123,6 +124,29 @@ class MRDOCS_DECL
123124
std::string
124125
configDir() const;
125126

127+
/** Full path to the output directory
128+
129+
The reference directory for MrDocs
130+
output and temporary files is the
131+
output directory.
132+
133+
This is either the output option
134+
(if already a directory) or
135+
the parent directory of the output
136+
option (if it is a file).
137+
138+
When the output option is a path
139+
that does not exist, we determine
140+
if it's a file or directory by
141+
checking if the filename contains
142+
a period.
143+
144+
This string will always be native style
145+
and have a trailing directory separator.
146+
*/
147+
std::string
148+
outputDir() const;
149+
126150
/** Full path to the mrdocs root directory
127151
128152
This is the directory containing the

include/mrdocs/Support/Algorithm.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#ifndef MRDOCS_API_SUPPORT_ALGORITHM_HPP
1212
#define MRDOCS_API_SUPPORT_ALGORITHM_HPP
1313

14-
#include <cstdint>
1514
#include <mrdocs/Support/Concepts.hpp>
15+
#include <cstdint>
16+
#include <algorithm>
1617

1718
namespace clang::mrdocs {
1819

include/mrdocs/Support/Path.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ bool
307307
isDirectory(
308308
std::string_view pathName);
309309

310+
/** Determine lexically if a path is a directory.
311+
312+
This function determines if a path is a directory.
313+
314+
If the path does not exist, the function
315+
determines lexically if the path represents
316+
a directory. In this case, the function
317+
returns true if the last path segment
318+
contains a period, otherwise false.
319+
*/
320+
MRDOCS_DECL
321+
bool
322+
isLexicalDirectory(
323+
std::string_view pathName);
324+
310325
/** Determine if a path is a directory.
311326
*/
312327
MRDOCS_DECL

src/lib/Lib/Config.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
// Official repository: https://github.com/cppalliance/mrdocs
1010
//
1111

12-
#include "mrdocs/Config.hpp"
13-
#include <mrdocs/Support/Report.hpp>
14-
#include <mrdocs/Support/Path.hpp>
15-
#include <llvm/Support/FileSystem.h>
12+
#include <mrdocs/Config.hpp>
13+
#include <mrdocs/Support/Algorithm.hpp>
1614
#include <ranges>
1715
#include <thread>
16+
#include <llvm/Support/FileSystem.h>
17+
#include <mrdocs/Support/Path.hpp>
18+
#include <mrdocs/Support/Report.hpp>
1819

1920
namespace clang {
2021
namespace mrdocs {
@@ -534,5 +535,36 @@ configDir() const
534535
return files::getParentDir(config);
535536
}
536537

538+
/** Full path to the output directory
539+
540+
The reference directory for MrDocs
541+
output and temporary files is the
542+
output directory.
543+
544+
This is either the output option
545+
(if already a directory) or
546+
the parent directory of the output
547+
option (if it is a file).
548+
549+
When the output option is a path
550+
that does not exist, we determine
551+
if it's a file or directory by
552+
checking if the filename contains
553+
a period.
554+
555+
This string will always be native style
556+
and have a trailing directory separator.
557+
*/
558+
std::string
559+
Config::Settings::
560+
outputDir() const
561+
{
562+
if (files::isLexicalDirectory(output))
563+
{
564+
return output;
565+
}
566+
return files::getParentDir(output);
567+
}
568+
537569
} // mrdocs
538570
} // clang

src/lib/Support/Path.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
//
1111

1212
#include "Path.hpp"
13+
#include <mrdocs/Support/Algorithm.hpp>
1314
#include <mrdocs/Support/Report.hpp>
1415
#include <llvm/Support/FileSystem.h>
15-
#include <llvm/Support/Path.h>
1616
#include <llvm/Support/MemoryBuffer.h>
17+
#include <llvm/Support/Path.h>
1718
#include <fstream>
1819

1920
namespace clang {
@@ -378,11 +379,27 @@ isDirectory(
378379
{
379380
namespace fs = llvm::sys::fs;
380381
fs::file_status fileStatus;
381-
if(auto ec = fs::status(pathName, fileStatus))
382-
return false;
383-
if(fileStatus.type() != fs::file_type::directory_file)
382+
if (auto ec = fs::status(pathName, fileStatus))
383+
{
384384
return false;
385-
return true;
385+
}
386+
return fileStatus.type() == fs::file_type::directory_file;
387+
}
388+
389+
bool
390+
isLexicalDirectory(
391+
std::string_view pathName)
392+
{
393+
namespace fs = llvm::sys::fs;
394+
fs::file_status fileStatus;
395+
if (auto const ec = fs::status(pathName, fileStatus);
396+
ec ||
397+
fileStatus.type() == fs::file_type::file_not_found)
398+
{
399+
auto const filename = getFileName(pathName);
400+
return !contains(filename, '.');
401+
}
402+
return fileStatus.type() == fs::file_type::directory_file;
386403
}
387404

388405
bool

src/tool/GenerateAction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ DoGenerateAction(
137137
MRDOCS_CHECK(
138138
compilationDatabasePath,
139139
"The compilation database path argument is missing");
140-
ScopedTempDirectory tempDir(config->settings().output, ".temp");
140+
ScopedTempDirectory tempDir(
141+
config->settings().outputDir(),
142+
".temp");
141143
if (tempDir.failed())
142144
{
143145
report::error("Failed to create temporary directory: {}", tempDir.error());

0 commit comments

Comments
 (0)