|
| 1 | +// Copyright 2023 Fred Emmott <[email protected]> |
| 2 | +// SPDX-License-Identifier: ISC |
| 3 | + |
| 4 | +#include <fmt/format.h> |
| 5 | + |
| 6 | +#include "Linter.hpp" |
| 7 | +#include "LoaderData.hpp" |
| 8 | +#include "Platform.hpp" |
| 9 | + |
| 10 | +namespace FredEmmott::OpenXRLayers { |
| 11 | +class SkippedByLoaderLinter final : public Linter { |
| 12 | + virtual std::vector<std::shared_ptr<LintError>> Lint( |
| 13 | + const APILayerStore*, |
| 14 | + const std::vector<std::tuple<APILayer, APILayerDetails>>& layers) { |
| 15 | + const auto loaderData = Platform::Get().GetLoaderData(); |
| 16 | + if (!loaderData) { |
| 17 | + return {}; |
| 18 | + } |
| 19 | + |
| 20 | + std::vector<std::shared_ptr<LintError>> errors; |
| 21 | + |
| 22 | + for (const auto& [layer, details]: layers) { |
| 23 | + if (details.mState != APILayerDetails::State::Loaded) { |
| 24 | + continue; |
| 25 | + } |
| 26 | + if (!layer.IsEnabled()) { |
| 27 | + continue; |
| 28 | + } |
| 29 | + |
| 30 | + if (loaderData->mEnabledLayerNames.contains(details.mName)) { |
| 31 | + continue; |
| 32 | + } |
| 33 | + |
| 34 | + const auto& enableEnv = details.mEnableEnvironment; |
| 35 | + if ((!enableEnv.empty()) && !std::getenv(enableEnv.c_str())) { |
| 36 | + continue; |
| 37 | + } |
| 38 | + |
| 39 | + const auto& disableEnv = details.mDisableEnvironment; |
| 40 | + if (!disableEnv.empty()) { |
| 41 | + if (std::getenv(disableEnv.c_str())) { |
| 42 | + continue; |
| 43 | + } |
| 44 | + if ( |
| 45 | + loaderData->mEnvironmentVariablesAfterLoader.contains(disableEnv) |
| 46 | + && !loaderData->mEnvironmentVariablesBeforeLoader.contains( |
| 47 | + disableEnv)) { |
| 48 | + errors.push_back( |
| 49 | + std::make_shared<LintError>( |
| 50 | + fmt::format( |
| 51 | + "This layer is blocked by your current OpenXR runtime", |
| 52 | + details.mName), |
| 53 | + PathSet {layer.mJSONPath})); |
| 54 | + continue; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + errors.push_back( |
| 59 | + std::make_shared<LintError>( |
| 60 | + fmt::format( |
| 61 | + "Layer appears enabled, but is not loaded by OpenXR; it may be " |
| 62 | + "blocked by your runtime vendor", |
| 63 | + details.mName), |
| 64 | + PathSet {layer.mJSONPath})); |
| 65 | + } |
| 66 | + return errors; |
| 67 | + } |
| 68 | +}; |
| 69 | + |
| 70 | +// Unused, but we care about the constructor |
| 71 | +[[maybe_unused]] static SkippedByLoaderLinter gInstance; |
| 72 | + |
| 73 | +}// namespace FredEmmott::OpenXRLayers |
0 commit comments