Skip to content

Commit 8c43405

Browse files
committed
Revert "Remove boost-filesystem fallback now that PEGTL depends on std::filesystem"
This reverts commit 8fc5053.
1 parent 3add6d3 commit 8c43405

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The easiest way to get all of these and to build `cppgraphqlgen` in one step is
4545
[microsoft/vcpkg](https://github.com/microsoft/vcpkg). To install with vcpkg, make sure you've pulled the latest version
4646
and then run `vcpkg install cppgraphqlgen` (or `cppgraphqlgen:x64-windows`, `cppgraphqlgen:x86-windows-static`, etc.
4747
depending on your platform). To install just the dependencies and work in a clone of this repo, you'll need some subset
48-
of `vcpkg install pegtl boost-program-options rapidjson gtest`. It works for Windows, Linux, and Mac,
48+
of `vcpkg install pegtl boost-program-options boost-filesystem rapidjson gtest`. It works for Windows, Linux, and Mac,
4949
but if you want to try building for another platform (e.g. Android or iOS), you'll need to do more of this manually.
5050

5151
Manual installation will work best if you clone the GitHub repos for each of the dependencies and follow the installation
@@ -85,6 +85,11 @@ do that.
8585

8686
I'm using [Boost](https://www.boost.org/doc/libs/1_69_0/more/getting_started/index.html) for `schemagen`:
8787

88+
- C++17 std::filesystem support on Unix:
89+
[Boost.Filesystem](https://www.boost.org/doc/libs/1_69_0/libs/filesystem/doc/index.htm). Most of the default C++
90+
compilers on Linux still have `std::filesystem` from C++17 in an experimental directory and require an extra
91+
library. The standard just adopted the Boost library, so on Unix systems I have an `#ifdef` which redirects back to
92+
it for the time being.
8893
- Command line handling: [Boost.Program_options](https://www.boost.org/doc/libs/1_69_0/doc/html/program_options.html).
8994
Run `schemagen -?` to get a list of options. Many of the files in the [samples](samples/) directory were generated
9095
with `schemagen`, you can look at [samples/CMakeLists.txt](samples/CMakeLists.txt) for a few examples of how to call it:

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ if(GRAPHQL_BUILD_SCHEMAGEN)
5151
set(BOOST_COMPONENTS program_options)
5252
set(BOOST_LIBRARIES Boost::program_options)
5353

54+
if(NOT MSVC)
55+
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} filesystem)
56+
set(BOOST_LIBRARIES ${BOOST_LIBRARIES} Boost::filesystem)
57+
target_compile_options(schemagen PRIVATE -DUSE_BOOST_FILESYSTEM)
58+
endif()
59+
5460
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
5561
target_link_libraries(schemagen PRIVATE ${BOOST_LIBRARIES})
5662

src/SchemaGenerator.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55

66
#include <boost/program_options.hpp>
77

8-
#include <cctype>
8+
#ifdef USE_BOOST_FILESYSTEM
9+
#include <boost/filesystem.hpp>
10+
namespace fs = boost::filesystem;
11+
#else
912
#include <filesystem>
13+
namespace fs = std::filesystem;
14+
#endif
15+
16+
#include <cctype>
1017
#include <fstream>
1118
#include <iostream>
1219
#include <regex>
@@ -297,11 +304,11 @@ std::string Generator::getHeaderDir() const noexcept
297304
{
298305
if (_isIntrospection)
299306
{
300-
return (std::filesystem::path { "include" } / "graphqlservice").string();
307+
return (fs::path { "include" } / "graphqlservice").string();
301308
}
302309
else if (_options.paths)
303310
{
304-
return std::filesystem::path { _options.paths->headerPath }.string();
311+
return fs::path { _options.paths->headerPath }.string();
305312
}
306313
else
307314
{
@@ -317,13 +324,13 @@ std::string Generator::getSourceDir() const noexcept
317324
}
318325
else
319326
{
320-
return std::filesystem::path(_options.paths->sourcePath).string();
327+
return fs::path(_options.paths->sourcePath).string();
321328
}
322329
}
323330

324331
std::string Generator::getHeaderPath() const noexcept
325332
{
326-
std::filesystem::path fullPath { _headerDir };
333+
fs::path fullPath { _headerDir };
327334

328335
if (_isIntrospection)
329336
{
@@ -341,7 +348,7 @@ std::string Generator::getObjectHeaderPath() const noexcept
341348
{
342349
if (_options.separateFiles)
343350
{
344-
std::filesystem::path fullPath { _headerDir };
351+
fs::path fullPath { _headerDir };
345352

346353
fullPath /= (_options.customSchema->filenamePrefix + "Objects.h");
347354
return fullPath.string();
@@ -352,7 +359,7 @@ std::string Generator::getObjectHeaderPath() const noexcept
352359

353360
std::string Generator::getSourcePath() const noexcept
354361
{
355-
std::filesystem::path fullPath { _sourceDir };
362+
fs::path fullPath { _sourceDir };
356363

357364
if (_isIntrospection)
358365
{
@@ -1659,8 +1666,7 @@ std::string Generator::getOutputCppType(const OutputField& field) const noexcept
16591666
bool Generator::outputHeader() const noexcept
16601667
{
16611668
std::ofstream headerFile(_headerPath, std::ios_base::trunc);
1662-
IncludeGuardScope includeGuard { headerFile,
1663-
std::filesystem::path(_headerPath).filename().string() };
1669+
IncludeGuardScope includeGuard { headerFile, fs::path(_headerPath).filename().string() };
16641670

16651671
headerFile << R"cpp(#include "graphqlservice/GraphQLService.h"
16661672
@@ -2042,8 +2048,8 @@ bool Generator::outputSource() const noexcept
20422048
)cpp";
20432049
if (!_isIntrospection)
20442050
{
2045-
sourceFile << R"cpp(#include ")cpp"
2046-
<< std::filesystem::path(_objectHeaderPath).filename().string() << R"cpp("
2051+
sourceFile << R"cpp(#include ")cpp" << fs::path(_objectHeaderPath).filename().string()
2052+
<< R"cpp("
20472053
20482054
)cpp";
20492055
}
@@ -3421,8 +3427,8 @@ std::string Generator::getIntrospectionType(
34213427
std::vector<std::string> Generator::outputSeparateFiles() const noexcept
34223428
{
34233429
std::vector<std::string> files;
3424-
const std::filesystem::path headerDir(_headerDir);
3425-
const std::filesystem::path sourceDir(_sourceDir);
3430+
const fs::path headerDir(_headerDir);
3431+
const fs::path sourceDir(_sourceDir);
34263432
std::string queryType;
34273433

34283434
for (const auto& operation : _operationTypes)
@@ -3437,10 +3443,10 @@ std::vector<std::string> Generator::outputSeparateFiles() const noexcept
34373443
// Output a convenience header
34383444
std::ofstream objectHeaderFile(_objectHeaderPath, std::ios_base::trunc);
34393445
IncludeGuardScope includeGuard { objectHeaderFile,
3440-
std::filesystem::path(_objectHeaderPath).filename().string() };
3446+
fs::path(_objectHeaderPath).filename().string() };
34413447

3442-
objectHeaderFile << R"cpp(#include ")cpp"
3443-
<< std::filesystem::path(_headerPath).filename().string() << R"cpp("
3448+
objectHeaderFile << R"cpp(#include ")cpp" << fs::path(_headerPath).filename().string()
3449+
<< R"cpp("
34443450
34453451
)cpp";
34463452

@@ -3474,8 +3480,7 @@ std::vector<std::string> Generator::outputSeparateFiles() const noexcept
34743480
std::ofstream headerFile(headerPath, std::ios_base::trunc);
34753481
IncludeGuardScope includeGuard { headerFile, headerFilename };
34763482

3477-
headerFile << R"cpp(#include ")cpp"
3478-
<< std::filesystem::path(_headerPath).filename().string() << R"cpp("
3483+
headerFile << R"cpp(#include ")cpp" << fs::path(_headerPath).filename().string() << R"cpp("
34793484
34803485
)cpp";
34813486

@@ -3498,7 +3503,7 @@ std::vector<std::string> Generator::outputSeparateFiles() const noexcept
34983503
sourceFile << R"cpp(// Copyright (c) Microsoft Corporation. All rights reserved.
34993504
// Licensed under the MIT License.
35003505
3501-
#include ")cpp" << std::filesystem::path(_objectHeaderPath).filename().string()
3506+
#include ")cpp" << fs::path(_objectHeaderPath).filename().string()
35023507
<< R"cpp("
35033508
35043509
#include "graphqlservice/Introspection.h"

0 commit comments

Comments
 (0)