-
-
Notifications
You must be signed in to change notification settings - Fork 12
Move the SchemaConfig module to this project #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| sourcemeta_library(NAMESPACE sourcemeta PROJECT blaze NAME configuration | ||
| PRIVATE_HEADERS error.h SOURCES parse.cc configuration.cc) | ||
|
|
||
| if(BLAZE_INSTALL) | ||
| sourcemeta_library_install(NAMESPACE sourcemeta PROJECT blaze NAME configuration) | ||
| endif() | ||
|
|
||
| target_link_libraries(sourcemeta_blaze_configuration PUBLIC sourcemeta::core::json) | ||
| target_link_libraries(sourcemeta_blaze_configuration PUBLIC sourcemeta::core::jsonpointer) | ||
| target_link_libraries(sourcemeta_blaze_configuration PRIVATE sourcemeta::core::uri) | ||
| target_link_libraries(sourcemeta_blaze_configuration PRIVATE sourcemeta::core::io) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include <sourcemeta/blaze/configuration.h> | ||
| #include <sourcemeta/core/io.h> | ||
|
|
||
| #include <algorithm> // std::ranges::any_of | ||
| #include <cassert> // assert | ||
| #include <string> // std::string | ||
|
|
||
| namespace sourcemeta::blaze { | ||
|
|
||
| auto Configuration::find(const std::filesystem::path &path) | ||
| -> std::optional<std::filesystem::path> { | ||
| const auto canonical{sourcemeta::core::weakly_canonical(path)}; | ||
| assert(canonical.is_absolute()); | ||
| auto current = std::filesystem::is_directory(canonical) | ||
| ? canonical | ||
| : canonical.parent_path(); | ||
|
|
||
| while (!current.empty()) { | ||
| auto candidate = current / "jsonschema.json"; | ||
| if (std::filesystem::exists(candidate) && | ||
| std::filesystem::is_regular_file(candidate)) { | ||
| return candidate; | ||
| } | ||
|
|
||
| auto parent = current.parent_path(); | ||
| if (parent == current) { | ||
| break; | ||
| } else { | ||
| current = parent; | ||
| } | ||
| } | ||
|
|
||
| return std::nullopt; | ||
| } | ||
|
|
||
| auto Configuration::applies_to(const std::filesystem::path &path) const | ||
| -> bool { | ||
| if (this->extension.empty()) { | ||
| return true; | ||
| } | ||
|
|
||
| const std::string filename{path.filename().string()}; | ||
| return std::ranges::any_of(this->extension, | ||
| [&path, &filename](const auto &suffix) { | ||
| if (suffix.empty()) { | ||
| return path.extension().empty(); | ||
| } | ||
|
|
||
| return filename.ends_with(suffix); | ||
| }); | ||
| } | ||
|
|
||
| } // namespace sourcemeta::blaze |
81 changes: 81 additions & 0 deletions
81
src/configuration/include/sourcemeta/blaze/configuration.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #ifndef SOURCEMETA_BLAZE_CONFIGURATION_H_ | ||
| #define SOURCEMETA_BLAZE_CONFIGURATION_H_ | ||
|
|
||
| /// @defgroup configuration Configuration | ||
| /// @brief A configuration manifest for JSON Schema projects | ||
| /// | ||
| /// This functionality is included as follows: | ||
| /// | ||
| /// ```cpp | ||
| /// #include <sourcemeta/blaze/configuration.h> | ||
| /// ``` | ||
|
|
||
| #ifndef SOURCEMETA_BLAZE_CONFIGURATION_EXPORT | ||
| #include <sourcemeta/blaze/configuration_export.h> | ||
| #endif | ||
|
|
||
| // NOLINTBEGIN(misc-include-cleaner) | ||
| #include <sourcemeta/blaze/configuration_error.h> | ||
| // NOLINTEND(misc-include-cleaner) | ||
|
|
||
| #include <sourcemeta/core/json.h> | ||
|
|
||
| #include <filesystem> // std::filesystem | ||
| #include <optional> // std::optional | ||
| #include <unordered_map> // std::unordered_map | ||
| #include <unordered_set> // std::unordered_set | ||
|
|
||
| namespace sourcemeta::blaze { | ||
|
|
||
| // Exporting symbols that depends on the standard C++ library is considered | ||
| // safe. | ||
| // https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN | ||
| #if defined(_MSC_VER) | ||
| #pragma warning(disable : 4251 4275) | ||
| #endif | ||
|
|
||
| /// @ingroup configuration | ||
| /// A configuration file format for JSON Schema projects | ||
| struct SOURCEMETA_BLAZE_CONFIGURATION_EXPORT Configuration { | ||
| std::optional<sourcemeta::core::JSON::String> title; | ||
| std::optional<sourcemeta::core::JSON::String> description; | ||
| std::optional<sourcemeta::core::JSON::String> email; | ||
| std::optional<sourcemeta::core::JSON::String> github; | ||
| std::optional<sourcemeta::core::JSON::String> website; | ||
| std::filesystem::path absolute_path; | ||
| sourcemeta::core::JSON::String base; | ||
| std::optional<sourcemeta::core::JSON::String> default_dialect; | ||
| std::unordered_set<sourcemeta::core::JSON::String> extension; | ||
| std::unordered_map<sourcemeta::core::JSON::String, | ||
| sourcemeta::core::JSON::String> | ||
| resolve; | ||
| sourcemeta::core::JSON extra = sourcemeta::core::JSON::make_object(); | ||
|
|
||
| /// Check if the given path represents a schema described by this | ||
| /// configuration | ||
| [[nodiscard]] | ||
| auto applies_to(const std::filesystem::path &path) const -> bool; | ||
|
|
||
| /// Parse a configuration file from its contents | ||
| [[nodiscard]] | ||
| static auto from_json(const sourcemeta::core::JSON &value, | ||
| const std::filesystem::path &base_path) | ||
| -> Configuration; | ||
|
|
||
| /// Read and parse a configuration file from disk | ||
| [[nodiscard]] | ||
| static auto read_json(const std::filesystem::path &path) -> Configuration; | ||
|
|
||
| /// A nearest ancestor configuration lookup | ||
| [[nodiscard]] | ||
| static auto find(const std::filesystem::path &path) | ||
| -> std::optional<std::filesystem::path>; | ||
| }; | ||
|
|
||
| #if defined(_MSC_VER) | ||
| #pragma warning(default : 4251 4275) | ||
| #endif | ||
|
|
||
| } // namespace sourcemeta::blaze | ||
|
|
||
| #endif | ||
57 changes: 57 additions & 0 deletions
57
src/configuration/include/sourcemeta/blaze/configuration_error.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #ifndef SOURCEMETA_BLAZE_CONFIGURATION_ERROR_H_ | ||
| #define SOURCEMETA_BLAZE_CONFIGURATION_ERROR_H_ | ||
|
|
||
| #ifndef SOURCEMETA_BLAZE_CONFIGURATION_EXPORT | ||
| #include <sourcemeta/blaze/configuration_export.h> | ||
| #endif | ||
|
|
||
| #include <sourcemeta/core/jsonpointer.h> | ||
|
|
||
| #include <exception> // std::exception | ||
| #include <string> // std::string | ||
| #include <string_view> // std::string_view | ||
| #include <utility> // std::move | ||
|
|
||
| namespace sourcemeta::blaze { | ||
|
|
||
| // Exporting symbols that depends on the standard C++ library is considered | ||
| // safe. | ||
| // https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN | ||
| #if defined(_MSC_VER) | ||
| #pragma warning(disable : 4251 4275) | ||
| #endif | ||
|
|
||
| /// @ingroup configuration | ||
| class SOURCEMETA_BLAZE_CONFIGURATION_EXPORT ConfigurationParseError | ||
| : public std::exception { | ||
| public: | ||
| ConfigurationParseError(const char *message, | ||
| sourcemeta::core::Pointer location) | ||
| : message_{message}, location_{std::move(location)} {} | ||
| ConfigurationParseError(std::string message, | ||
| sourcemeta::core::Pointer location) = delete; | ||
| ConfigurationParseError(std::string &&message, | ||
| sourcemeta::core::Pointer location) = delete; | ||
| ConfigurationParseError(std::string_view message, | ||
| sourcemeta::core::Pointer location) = delete; | ||
|
|
||
| [[nodiscard]] auto what() const noexcept -> const char * override { | ||
| return this->message_; | ||
| } | ||
|
|
||
| [[nodiscard]] auto location() const noexcept -> const auto & { | ||
| return this->location_; | ||
| } | ||
|
|
||
| private: | ||
| const char *message_; | ||
| sourcemeta::core::Pointer location_; | ||
| }; | ||
|
|
||
| #if defined(_MSC_VER) | ||
| #pragma warning(default : 4251 4275) | ||
| #endif | ||
|
|
||
| } // namespace sourcemeta::blaze | ||
|
|
||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Using
#pragma warning(default : ...)resets warnings to the compiler defaults, which may override a user's global build settings (e.g., if they explicitly disabled these warnings). Use#pragma warning(push)and#pragma warning(pop)to restore the previous state safely.Prompt for AI agents