diff --git a/azure-pipelines/end-to-end-tests-dir/bundles.ps1 b/azure-pipelines/end-to-end-tests-dir/bundles.ps1 index 13ee72d4e7..9692fae966 100644 --- a/azure-pipelines/end-to-end-tests-dir/bundles.ps1 +++ b/azure-pipelines/end-to-end-tests-dir/bundles.ps1 @@ -42,9 +42,9 @@ $b = @{ downloads = Join-Path $VcpkgRoot "downloads" packages = Join-Path $VcpkgRoot "packages" installed = Join-Path $VcpkgRoot "installed" - versions_output = Join-Path $VcpkgRoot "buildtrees" "versioning_" "versions" + 'versions-output' = Join-Path $VcpkgRoot "buildtrees" "versioning_" "versions" tools = Join-Path $VcpkgRoot "downloads" "tools" - vcpkg_root = $VcpkgRoot + 'vcpkg-root' = $VcpkgRoot } foreach ($k in $b.keys) { if ($a[$k] -ne $b[$k]) { @@ -67,9 +67,9 @@ $b = @{ downloads = Join-Path $cache_home "vcpkg" "downloads" packages = $null installed = $null - versions_output = $null + 'versions-output' = $null tools = Join-Path $cache_home "vcpkg" "downloads" "tools" - vcpkg_root = $VcpkgRoot + 'vcpkg-root' = $VcpkgRoot } foreach ($k in $b.keys) { if ($a[$k] -ne $b[$k]) { @@ -97,10 +97,10 @@ $b = @{ downloads = Join-Path $cache_home "vcpkg" "downloads" packages = Join-Path $manifestdir "vcpkg_installed" "vcpkg" "pkgs" installed = Join-Path $manifestdir "vcpkg_installed" - versions_output = Join-Path $manifestdir "vcpkg_installed" "vcpkg" "blds" "versioning_" "versions" + 'versions-output' = Join-Path $manifestdir "vcpkg_installed" "vcpkg" "blds" "versioning_" "versions" tools = Join-Path $cache_home "vcpkg" "downloads" "tools" - vcpkg_root = $VcpkgRoot - manifest_mode_enabled = $True + 'vcpkg-root' = $VcpkgRoot + 'manifest-mode-enabled' = $True } foreach ($k in $b.keys) { if ($a[$k] -ne $b[$k]) { @@ -137,10 +137,10 @@ $b = @{ downloads = Join-Path $cache_home "vcpkg" "downloads" packages = $packagesRoot installed = $installRoot - versions_output = Join-Path $buildtreesRoot "versioning_" "versions" + 'versions-output' = Join-Path $buildtreesRoot "versioning_" "versions" tools = Join-Path $cache_home "vcpkg" "downloads" "tools" - vcpkg_root = $VcpkgRoot - manifest_mode_enabled = $True + 'vcpkg-root' = $VcpkgRoot + 'manifest-mode-enabled' = $True } foreach ($k in $b.keys) { if ($a[$k] -ne $b[$k]) { @@ -198,7 +198,7 @@ Run-Vcpkg search vcpkg-hello-world-1 @commonArgs ` Throw-IfFailed # Test CI environment detection -$detected_ci_key = 'detected_ci_environment' +$detected_ci_key = 'detected-ci-environment' $known_ci_vars = ( "env:VCPKG_NO_CI", "env:TF_BUILD", diff --git a/include/vcpkg/base/contractual-constants.h b/include/vcpkg/base/contractual-constants.h index 4297831476..97eae037dd 100644 --- a/include/vcpkg/base/contractual-constants.h +++ b/include/vcpkg/base/contractual-constants.h @@ -9,38 +9,60 @@ namespace vcpkg // JSON IDs are lowercase separated by dashes inline constexpr StringLiteral JsonIdAbi = "abi"; + inline constexpr StringLiteral JsonIdAcquiredArtifacts = "acquired-artifacts"; + inline constexpr StringLiteral JsonIdActivatedArtifacts = "activated-artifacts"; + inline constexpr StringLiteral JsonIdAlgorithm = "algorithm"; + inline constexpr StringLiteral JsonIdAllCapsSHA256 = "SHA256"; + inline constexpr StringLiteral JsonIdAllCapsSHA512 = "SHA512"; inline constexpr StringLiteral JsonIdApply = "apply"; + inline constexpr StringLiteral JsonIdArchiveCapitalLocation = "archiveLocation"; inline constexpr StringLiteral JsonIdArtifact = "artifact"; inline constexpr StringLiteral JsonIdBaseline = "baseline"; + inline constexpr StringLiteral JsonIdBuildtrees = "buildtrees"; inline constexpr StringLiteral JsonIdBuiltin = "builtin"; inline constexpr StringLiteral JsonIdBuiltinBaseline = "builtin-baseline"; inline constexpr StringLiteral JsonIdBuiltinError = "builtin-error"; inline constexpr StringLiteral JsonIdBuiltinFiles = "builtin-files"; inline constexpr StringLiteral JsonIdBuiltinGit = "builtin-git"; + inline constexpr StringLiteral JsonIdCacheCapitalId = "cacheId"; + inline constexpr StringLiteral JsonIdCacheCapitalSize = "cacheSize"; + inline constexpr StringLiteral JsonIdChecksums = "checksums"; + inline constexpr StringLiteral JsonIdComment = "comment"; inline constexpr StringLiteral JsonIdContacts = "contacts"; inline constexpr StringLiteral JsonIdCorrelator = "correlator"; + inline constexpr StringLiteral JsonIdCreated = "created"; + inline constexpr StringLiteral JsonIdCreators = "creators"; inline constexpr StringLiteral JsonIdDefault = "default"; inline constexpr StringLiteral JsonIdDefaultFeatures = "default-features"; inline constexpr StringLiteral JsonIdDefaultRegistry = "default-registry"; + inline constexpr StringLiteral JsonIdDefaultTriplet = "default-triplet"; inline constexpr StringLiteral JsonIdDemands = "demands"; inline constexpr StringLiteral JsonIdDependencies = "dependencies"; inline constexpr StringLiteral JsonIdDescription = "description"; + inline constexpr StringLiteral JsonIdDetectedCIEnvironment = "detected-ci-environment"; inline constexpr StringLiteral JsonIdDetector = "detector"; inline constexpr StringLiteral JsonIdDirect = "direct"; inline constexpr StringLiteral JsonIdDocumentation = "documentation"; + inline constexpr StringLiteral JsonIdDollarSchema = "$schema"; + inline constexpr StringLiteral JsonIdDownloads = "downloads"; inline constexpr StringLiteral JsonIdError = "error"; inline constexpr StringLiteral JsonIdFeatures = "features"; + inline constexpr StringLiteral JsonIdFiles = "files"; inline constexpr StringLiteral JsonIdFilesystem = "filesystem"; inline constexpr StringLiteral JsonIdGit = "git"; inline constexpr StringLiteral JsonIdGitTree = "git-tree"; inline constexpr StringLiteral JsonIdHomepage = "homepage"; inline constexpr StringLiteral JsonIdHost = "host"; + inline constexpr StringLiteral JsonIdHostTriplet = "host-triplet"; inline constexpr StringLiteral JsonIdId = "id"; + inline constexpr StringLiteral JsonIdInstalled = "installed"; inline constexpr StringLiteral JsonIdJob = "job"; + inline constexpr StringLiteral JsonIdKey = "key"; inline constexpr StringLiteral JsonIdKind = "kind"; inline constexpr StringLiteral JsonIdLicense = "license"; inline constexpr StringLiteral JsonIdLocation = "location"; inline constexpr StringLiteral JsonIdMaintainers = "maintainers"; + inline constexpr StringLiteral JsonIdManifestModeEnabled = "manifest-mode-enabled"; inline constexpr StringLiteral JsonIdManifestRoot = "manifest-root"; inline constexpr StringLiteral JsonIdManifests = "manifests"; inline constexpr StringLiteral JsonIdMessage = "message"; @@ -60,6 +82,7 @@ namespace vcpkg inline constexpr StringLiteral JsonIdReference = "reference"; inline constexpr StringLiteral JsonIdRegistries = "registries"; inline constexpr StringLiteral JsonIdRelationship = "relationship"; + inline constexpr StringLiteral JsonIdRelationships = "relationships"; inline constexpr StringLiteral JsonIdRepository = "repository"; inline constexpr StringLiteral JsonIdRequires = "requires"; inline constexpr StringLiteral JsonIdResolved = "resolved"; @@ -69,6 +92,7 @@ namespace vcpkg inline constexpr StringLiteral JsonIdState = "state"; inline constexpr StringLiteral JsonIdSummary = "summary"; inline constexpr StringLiteral JsonIdSupports = "supports"; + inline constexpr StringLiteral JsonIdTools = "tools"; inline constexpr StringLiteral JsonIdTriplet = "triplet"; inline constexpr StringLiteral JsonIdUrl = "url"; inline constexpr StringLiteral JsonIdVcpkgAssetSources = "vcpkg-asset-sources"; @@ -76,6 +100,7 @@ namespace vcpkg inline constexpr StringLiteral JsonIdVcpkgDisableMetrics = "vcpkg-disable-metrics"; inline constexpr StringLiteral JsonIdVcpkgDotJson = "vcpkg.json"; inline constexpr StringLiteral JsonIdVcpkgDownloads = "vcpkg-downloads"; + inline constexpr StringLiteral JsonIdVcpkgRoot = "vcpkg-root"; inline constexpr StringLiteral JsonIdVcpkgRootArg = "vcpkg-root-arg"; inline constexpr StringLiteral JsonIdVcpkgRootEnv = "vcpkg-root-env"; inline constexpr StringLiteral JsonIdVersion = "version"; @@ -83,9 +108,44 @@ namespace vcpkg inline constexpr StringLiteral JsonIdVersionGreaterEqual = "version>="; inline constexpr StringLiteral JsonIdVersions = "versions"; inline constexpr StringLiteral JsonIdVersionSemver = "version-semver"; + inline constexpr StringLiteral JsonIdVersionsOutput = "versions-output"; inline constexpr StringLiteral JsonIdVersionString = "version-string"; inline constexpr StringLiteral JsonIdWarning = "warning"; + // SPDX constants are JsonIds which follow capitalization and separation in the SPDX specification, + // rather than the lowercase-dash convention used above. + // + // SPDX documents also use the JsonId constants above for those values consistent with those we + // would use in other contexts. + inline constexpr StringLiteral SpdxCCZero = "CC0-1.0"; + inline constexpr StringLiteral SpdxChecksumValue = "checksumValue"; + inline constexpr StringLiteral SpdxContainedBy = "CONTAINED_BY"; + inline constexpr StringLiteral SpdxContains = "CONTAINS"; + inline constexpr StringLiteral SpdxCopyrightText = "copyrightText"; + inline constexpr StringLiteral SpdxCreationInfo = "creationInfo"; + inline constexpr StringLiteral SpdxDataLicense = "dataLicense"; + inline constexpr StringLiteral SpdxDependencyManifestOf = "DEPENDENCY_MANIFEST_OF"; + inline constexpr StringLiteral SpdxDocumentNamespace = "documentNamespace"; + inline constexpr StringLiteral SpdxDownloadLocation = "downloadLocation"; + inline constexpr StringLiteral SpdxElementId = "spdxElementId"; + inline constexpr StringLiteral SpdxFileName = "fileName"; + inline constexpr StringLiteral SpdxGeneratedFrom = "GENERATED_FROM"; + inline constexpr StringLiteral SpdxGenerates = "GENERATES"; + inline constexpr StringLiteral SpdxLicenseConcluded = "licenseConcluded"; + inline constexpr StringLiteral SpdxLicenseDeclared = "licenseDeclared"; + inline constexpr StringLiteral SpdxNoAssertion = "NOASSERTION"; + inline constexpr StringLiteral SpdxNone = "NONE"; + inline constexpr StringLiteral SpdxPackageFileName = "packageFileName"; + inline constexpr StringLiteral SpdxRefBinary = "SPDXRef-binary"; + inline constexpr StringLiteral SpdxRefDocument = "SPDXRef-DOCUMENT"; + inline constexpr StringLiteral SpdxRefPort = "SPDXRef-port"; + inline constexpr StringLiteral SpdxRelatedSpdxElement = "relatedSpdxElement"; + inline constexpr StringLiteral SpdxRelationshipType = "relationshipType"; + inline constexpr StringLiteral SpdxSpdxId = "SPDXID"; + inline constexpr StringLiteral SpdxTwoTwo = "SPDX-2.2"; + inline constexpr StringLiteral SpdxVersion = "spdxVersion"; + inline constexpr StringLiteral SpdxVersionInfo = "versionInfo"; + // Paragraph IDs are *usually* Capitals-Separated-By-Dashes inline constexpr StringLiteral ParagraphIdAbi = "Abi"; inline constexpr StringLiteral ParagraphIdArchitecture = "Architecture"; @@ -306,6 +366,7 @@ namespace vcpkg inline constexpr StringLiteral CMakeVariableEnvPassthrough = "VCPKG_ENV_PASSTHROUGH"; inline constexpr StringLiteral CMakeVariableEnvPassthroughUntracked = "VCPKG_ENV_PASSTHROUGH_UNTRACKED"; inline constexpr StringLiteral CMakeVariableFeatures = "FEATURES"; + inline constexpr StringLiteral CMakeVariableFilename = "FILENAME"; inline constexpr StringLiteral CMakeVariableGit = "GIT"; inline constexpr StringLiteral CMakeVariableHostTriplet = "_HOST_TRIPLET"; inline constexpr StringLiteral CMakeVariableLoadVcvarsEnv = "VCPKG_LOAD_VCVARS_ENV"; @@ -330,9 +391,14 @@ namespace vcpkg inline constexpr StringLiteral CMakeVariablePortConfigs = "VCPKG_PORT_CONFIGS"; inline constexpr StringLiteral CMakeVariableProhibitBackcompatFeatures = "_VCPKG_PROHIBIT_BACKCOMPAT_FEATURES"; inline constexpr StringLiteral CMakeVariablePublicAbiOverride = "VCPKG_PUBLIC_ABI_OVERRIDE"; + inline constexpr StringLiteral CMakeVariableRef = "REF"; + inline constexpr StringLiteral CMakeVariableRepo = "REPO"; + inline constexpr StringLiteral CMakeVariableSHA512 = "SHA512"; inline constexpr StringLiteral CMakeVariableTargetArchitecture = "VCPKG_TARGET_ARCHITECTURE"; inline constexpr StringLiteral CMakeVariableTargetTriplet = "TARGET_TRIPLET"; inline constexpr StringLiteral CMakeVariableTargetTripletFile = "TARGET_TRIPLET_FILE"; + inline constexpr StringLiteral CMakeVariableUrl = "URL"; + inline constexpr StringLiteral CMakeVariableUrls = "URLS"; inline constexpr StringLiteral CMakeVariableUseHeadVersion = "VCPKG_USE_HEAD_VERSION"; inline constexpr StringLiteral CMakeVariableVersion = "VERSION"; inline constexpr StringLiteral CMakeVariableVisualStudioPath = "VCPKG_VISUAL_STUDIO_PATH"; @@ -358,6 +424,8 @@ namespace vcpkg // Environment variables are ALL_CAPS_WITH_UNDERSCORES inline constexpr StringLiteral EnvironmentVariableActionsCacheUrl = "ACTIONS_CACHE_URL"; inline constexpr StringLiteral EnvironmentVariableActionsRuntimeToken = "ACTIONS_RUNTIME_TOKEN"; + inline constexpr StringLiteral EnvironmentVariableAndroidNdkHome = "ANDROID_NDK_HOME"; + inline constexpr StringLiteral EnvironmentVariableAppData = "APPDATA"; inline constexpr StringLiteral EnvironmentVariableAppveyor = "APPVEYOR"; inline constexpr StringLiteral EnvironmentVariableBuildId = "BUILD_ID"; inline constexpr StringLiteral EnvironmentVariableBuildNumber = "BUILD_NUMBER"; @@ -366,6 +434,7 @@ namespace vcpkg inline constexpr StringLiteral EnvironmentVariableCIProjectId = "CI_PROJECT_ID"; inline constexpr StringLiteral EnvironmentVariableCircleCI = "CIRCLECI"; inline constexpr StringLiteral EnvironmentVariableCodebuildBuildId = "CODEBUILD_BUILD_ID"; + inline constexpr StringLiteral EnvironmentVariableEditor = "EDITOR"; inline constexpr StringLiteral EnvironmentVariableGitCeilingDirectories = "GIT_CEILING_DIRECTORIES"; inline constexpr StringLiteral EnvironmentVariableGitHubActions = "GITHUB_ACTIONS"; inline constexpr StringLiteral EnvironmentVariableGitHubJob = "GITHUB_JOB"; @@ -386,15 +455,23 @@ namespace vcpkg inline constexpr StringLiteral EnvironmentVariableInclude = "INCLUDE"; inline constexpr StringLiteral EnvironmentVariableJenkinsHome = "JENKINS_HOME"; inline constexpr StringLiteral EnvironmentVariableJenkinsUrl = "JENKINS_URL"; + inline constexpr StringLiteral EnvironmentVariableLocalAppData = "LOCALAPPDATA"; inline constexpr StringLiteral EnvironmentVariableOverlayTriplets = "VCPKG_OVERLAY_TRIPLETS"; inline constexpr StringLiteral EnvironmentVariablePath = "PATH"; + inline constexpr StringLiteral EnvironmentVariablePlatform = "Platform"; + inline constexpr StringLiteral EnvironmentVariableProgramFiles = "PROGRAMFILES"; + inline constexpr StringLiteral EnvironmentVariableProgramFilesX86 = "ProgramFiles(x86)"; + inline constexpr StringLiteral EnvironmentVariableProgramW6432 = "ProgramW6432"; inline constexpr StringLiteral EnvironmentVariablePythonPath = "PYTHONPATH"; + inline constexpr StringLiteral EnvironmentVariableSystemRoot = "SystemRoot"; inline constexpr StringLiteral EnvironmentVariableTeamcityVersion = "TEAMCITY_VERSION"; inline constexpr StringLiteral EnvironmentVariableTfBuild = "TF_BUILD"; inline constexpr StringLiteral EnvironmentVariableTravis = "TRAVIS"; inline constexpr StringLiteral EnvironmentVariableUserprofile = "USERPROFILE"; + inline constexpr StringLiteral EnvironmentVariableVCInstallDir = "VCINSTALLDIR"; inline constexpr StringLiteral EnvironmentVariableVcpkgBinarySources = "VCPKG_BINARY_SOURCES"; inline constexpr StringLiteral EnvironmentVariableVcpkgCommand = "VCPKG_COMMAND"; + inline constexpr StringLiteral EnvironmentVariableVcpkgDefaultBinaryCache = "VCPKG_DEFAULT_BINARY_CACHE"; inline constexpr StringLiteral EnvironmentVariableVcpkgDefaultHostTriplet = "VCPKG_DEFAULT_HOST_TRIPLET"; inline constexpr StringLiteral EnvironmentVariableVcpkgDefaultTriplet = "VCPKG_DEFAULT_TRIPLET"; inline constexpr StringLiteral EnvironmentVariableVcpkgDisableMetrics = "VCPKG_DISABLE_METRICS"; @@ -402,12 +479,16 @@ namespace vcpkg inline constexpr StringLiteral EnvironmentVariableVcpkgFeatureFlags = "VCPKG_FEATURE_FLAGS"; inline constexpr StringLiteral EnvironmentVariableVcpkgForceDownloadedBinaries = "VCPKG_FORCE_DOWNLOADED_BINARIES"; inline constexpr StringLiteral EnvironmentVariableVcpkgForceSystemBinaries = "VCPKG_FORCE_SYSTEM_BINARIES"; + inline constexpr StringLiteral EnvironmentVariableVcpkgKeepEnvVars = "VCPKG_KEEP_ENV_VARS"; + inline constexpr StringLiteral EnvironmentVariableVcpkgMaxConcurrency = "VCPKG_MAX_CONCURRENCY"; inline constexpr StringLiteral EnvironmentVariableVcpkgNoCi = "VCPKG_NO_CI"; inline constexpr StringLiteral EnvironmentVariableVcpkgNuGetRepository = "VCPKG_NUGET_REPOSITORY"; inline constexpr StringLiteral EnvironmentVariableVcpkgOverlayPorts = "VCPKG_OVERLAY_PORTS"; inline constexpr StringLiteral EnvironmentVariableVcpkgRoot = "VCPKG_ROOT"; inline constexpr StringLiteral EnvironmentVariableVcpkgUseNuGetCache = "VCPKG_USE_NUGET_CACHE"; inline constexpr StringLiteral EnvironmentVariableVcpkgVisualStudioPath = "VCPKG_VISUAL_STUDIO_PATH"; + inline constexpr StringLiteral EnvironmentVariableVscmdArgTgtArch = "VSCMD_ARG_TGT_ARCH"; + inline constexpr StringLiteral EnvironmentVariableVSCmdSkipSendTelemetry = "VSCMD_SKIP_SENDTELEMETRY"; inline constexpr StringLiteral EnvironmentVariableVsLang = "VSLANG"; inline constexpr StringLiteral EnvironmentVariableXVcpkgAssetSources = "X_VCPKG_ASSET_SOURCES"; inline constexpr StringLiteral EnvironmentVariableXVcpkgIgnoreLockFailures = "X_VCPKG_IGNORE_LOCK_FAILURES"; diff --git a/src/vcpkg/base/system.cpp b/src/vcpkg/base/system.cpp index 9abec83f53..ac4d4b8d83 100644 --- a/src/vcpkg/base/system.cpp +++ b/src/vcpkg/base/system.cpp @@ -427,12 +427,12 @@ namespace vcpkg const ExpectedL& get_appdata_local() noexcept { static ExpectedL s_home = []() -> ExpectedL { - auto maybe_home = get_environment_variable("LOCALAPPDATA"); + auto maybe_home = get_environment_variable(EnvironmentVariableLocalAppData); if (!maybe_home.has_value() || maybe_home.get()->empty()) { // Consult %APPDATA% as a workaround for Service accounts // Microsoft/vcpkg#12285 - maybe_home = get_environment_variable("APPDATA"); + maybe_home = get_environment_variable(EnvironmentVariableAppData); if (!maybe_home.has_value() || maybe_home.get()->empty()) { return msg::format(msgUnableToReadAppDatas); @@ -442,7 +442,9 @@ namespace vcpkg p /= "Local"; if (!p.is_absolute()) { - return msg::format(msgEnvVarMustBeAbsolutePath, msg::path = p, msg::env_var = "%APPDATA%"); + return msg::format(msgEnvVarMustBeAbsolutePath, + msg::path = p, + msg::env_var = format_environment_variable(EnvironmentVariableAppData)); } return p; @@ -451,7 +453,9 @@ namespace vcpkg auto p = Path(*maybe_home.get()); if (!p.is_absolute()) { - return msg::format(msgEnvVarMustBeAbsolutePath, msg::path = p, msg::env_var = "%LOCALAPPDATA%"); + return msg::format(msgEnvVarMustBeAbsolutePath, + msg::path = p, + msg::env_var = format_environment_variable(EnvironmentVariableLocalAppData)); } return p; @@ -462,7 +466,7 @@ namespace vcpkg const ExpectedL& get_system_root() noexcept { static const ExpectedL s_system_root = []() -> ExpectedL { - auto env = get_environment_variable("SystemRoot"); + auto env = get_environment_variable(EnvironmentVariableSystemRoot); if (const auto p = env.get()) { return Path(std::move(*p)); @@ -625,7 +629,7 @@ namespace vcpkg static const Optional& get_program_files() { static const auto PROGRAMFILES = []() -> Optional { - auto value = get_environment_variable("PROGRAMFILES"); + auto value = get_environment_variable(EnvironmentVariableProgramFiles); if (auto v = value.get()) { return *v; @@ -640,7 +644,7 @@ namespace vcpkg const Optional& get_program_files_32_bit() { static const auto PROGRAMFILES_x86 = []() -> Optional { - auto value = get_environment_variable("ProgramFiles(x86)"); + auto value = get_environment_variable(EnvironmentVariableProgramFilesX86); if (auto v = value.get()) { return *v; @@ -653,7 +657,7 @@ namespace vcpkg const Optional& get_program_files_platform_bitness() { static const auto ProgramW6432 = []() -> Optional { - auto value = get_environment_variable("ProgramW6432"); + auto value = get_environment_variable(EnvironmentVariableProgramW6432); if (auto v = value.get()) { return *v; @@ -666,7 +670,7 @@ namespace vcpkg unsigned int get_concurrency() { static unsigned int concurrency = [] { - auto user_defined_concurrency = get_environment_variable("VCPKG_MAX_CONCURRENCY"); + auto user_defined_concurrency = get_environment_variable(EnvironmentVariableVcpkgMaxConcurrency); if (user_defined_concurrency) { int res = -1; @@ -677,14 +681,14 @@ namespace vcpkg catch (std::exception&) { Checks::msg_exit_with_message( - VCPKG_LINE_INFO, msgOptionMustBeInteger, msg::option = "VCPKG_MAX_CONCURRENCY"); + VCPKG_LINE_INFO, msgOptionMustBeInteger, msg::option = EnvironmentVariableVcpkgMaxConcurrency); } if (!(res > 0)) { Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgEnvInvalidMaxConcurrency, - msg::env_var = "VCPKG_MAX_CONCURRENCY", + msg::env_var = EnvironmentVariableVcpkgMaxConcurrency, msg::value = res); } return static_cast(res); @@ -710,16 +714,16 @@ namespace vcpkg Optional guess_visual_studio_prompt_target_architecture() { // Check for the "vsdevcmd" infrastructure used by Visual Studio 2017 and later - const auto vscmd_arg_tgt_arch_env = get_environment_variable("VSCMD_ARG_TGT_ARCH"); + const auto vscmd_arg_tgt_arch_env = get_environment_variable(EnvironmentVariableVscmdArgTgtArch); if (vscmd_arg_tgt_arch_env) { return to_cpu_architecture(vscmd_arg_tgt_arch_env.value_or_exit(VCPKG_LINE_INFO)); } // Check for the "vcvarsall" infrastructure used by Visual Studio 2015 - if (get_environment_variable("VCINSTALLDIR")) + if (get_environment_variable(EnvironmentVariableVCInstallDir)) { - const auto Platform = get_environment_variable("Platform"); + const auto Platform = get_environment_variable(EnvironmentVariablePlatform); if (Platform) { return to_cpu_architecture(Platform.value_or_exit(VCPKG_LINE_INFO)); diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 6fd241f3ce..64e5fd3a6e 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -582,7 +582,7 @@ namespace vcpkg "GXDKLatest", }; - const Optional keep_vars = get_environment_variable("VCPKG_KEEP_ENV_VARS"); + const Optional keep_vars = get_environment_variable(EnvironmentVariableVcpkgKeepEnvVars); const auto k = keep_vars.get(); if (k && !k->empty()) @@ -626,7 +626,7 @@ namespace vcpkg // but we still want to default to english just in case your specific // non-standard build system doesn't support non-english env.add_entry(EnvironmentVariableVsLang, "1033"); - env.add_entry("VSCMD_SKIP_SENDTELEMETRY", "1"); + env.add_entry(EnvironmentVariableVSCmdSkipSendTelemetry, "1"); for (const auto& item : extra_env) { diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 5658494c91..cb51b5b4ab 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -809,7 +809,7 @@ namespace auto maybe_json = Json::parse_object(*p, m_url); if (auto json = maybe_json.get()) { - auto archive_location = json->get("archiveLocation"); + auto archive_location = json->get(JsonIdArchiveCapitalLocation); if (archive_location && archive_location->is_string()) { return archive_location->string(VCPKG_LINE_INFO).to_string(); @@ -871,9 +871,9 @@ namespace Optional reserve_cache_entry(const std::string& name, const std::string& abi, int64_t cacheSize) const { Json::Object payload; - payload.insert("key", name + "-" + abi); - payload.insert("version", abi); - payload.insert("cacheSize", Json::Value::integer(cacheSize)); + payload.insert(JsonIdKey, name + "-" + abi); + payload.insert(JsonIdVersion, abi); + payload.insert(JsonIdCacheCapitalSize, Json::Value::integer(cacheSize)); const std::string headers[] = { m_accept_header.to_string(), @@ -887,7 +887,7 @@ namespace auto maybe_json = Json::parse_object(*p, m_url); if (auto json = maybe_json.get()) { - auto cache_id = json->get("cacheId"); + auto cache_id = json->get(JsonIdCacheCapitalId); if (cache_id && cache_id->is_integer()) { return cache_id->integer(VCPKG_LINE_INFO); @@ -1191,7 +1191,7 @@ namespace ExpectedL default_cache_path_impl() { - auto maybe_cachepath = get_environment_variable("VCPKG_DEFAULT_BINARY_CACHE"); + auto maybe_cachepath = get_environment_variable(EnvironmentVariableVcpkgDefaultBinaryCache); if (auto p_str = maybe_cachepath.get()) { get_global_metrics_collector().track_define(DefineMetric::VcpkgDefaultBinaryCache); @@ -1801,13 +1801,13 @@ namespace vcpkg return {*p}; } - auto gh_repo = get_environment_variable("GITHUB_REPOSITORY").value_or(""); + auto gh_repo = get_environment_variable(EnvironmentVariableGitHubRepository).value_or(""); if (gh_repo.empty()) { return {}; } - auto gh_server = get_environment_variable("GITHUB_SERVER_URL").value_or(""); + auto gh_server = get_environment_variable(EnvironmentVariableGitHubServerUrl).value_or(""); if (gh_server.empty()) { return {}; @@ -1815,8 +1815,8 @@ namespace vcpkg get_global_metrics_collector().track_define(DefineMetric::GitHubRepository); return {Strings::concat(gh_server, '/', gh_repo, ".git"), - get_environment_variable("GITHUB_REF").value_or(""), - get_environment_variable("GITHUB_SHA").value_or("")}; + get_environment_variable(EnvironmentVariableGitHubRef).value_or(""), + get_environment_variable(EnvironmentVariableGitHubSha).value_or("")}; } static ExpectedL make_binary_providers(const VcpkgCmdArguments& args, const VcpkgPaths& paths) diff --git a/src/vcpkg/commands.edit.cpp b/src/vcpkg/commands.edit.cpp index 14a9a6b3aa..9411f8a218 100644 --- a/src/vcpkg/commands.edit.cpp +++ b/src/vcpkg/commands.edit.cpp @@ -142,7 +142,10 @@ namespace vcpkg { constexpr CommandMetadata CommandEditMetadata{ "edit", - [] { return msg::format(msgHelpEditCommand, msg::env_var = format_environment_variable("EDITOR")); }, + [] { + return msg::format(msgHelpEditCommand, + msg::env_var = format_environment_variable(EnvironmentVariableEditor)); + }, {msgCmdEditExample1, "vcpkg edit zlib"}, Undocumented, AutocompletePriority::Public, @@ -173,7 +176,7 @@ namespace vcpkg // Scope to prevent use of moved-from variable { - auto maybe_editor_path = get_environment_variable("EDITOR"); + auto maybe_editor_path = get_environment_variable(EnvironmentVariableEditor); if (std::string* editor_path = maybe_editor_path.get()) { candidate_paths.emplace_back(std::move(*editor_path)); @@ -198,7 +201,7 @@ namespace vcpkg candidate_paths.push_back(*pf / VS_CODE); } - auto app_data = get_environment_variable("APPDATA"); + auto app_data = get_environment_variable(EnvironmentVariableAppData); if (auto* ad = app_data.get()) { Path default_base = std::move(*ad); @@ -253,11 +256,12 @@ namespace vcpkg const auto it = Util::find_if(candidate_paths, [&](const Path& p) { return fs.exists(p, IgnoreErrors{}); }); if (it == candidate_paths.cend()) { - msg::println_error(msg::format(msgErrorVsCodeNotFound, msg::env_var = format_environment_variable("EDITOR")) + msg::println_error(msg::format(msgErrorVsCodeNotFound, + msg::env_var = format_environment_variable(EnvironmentVariableEditor)) .append_raw('\n') .append(msgErrorVsCodeNotFoundPathExamined)); print_paths(out_sink, candidate_paths); - msg::println(msgInfoSetEnvVar, msg::env_var = format_environment_variable("EDITOR")); + msg::println(msgInfoSetEnvVar, msg::env_var = format_environment_variable(EnvironmentVariableEditor)); Checks::exit_fail(VCPKG_LINE_INFO); } diff --git a/src/vcpkg/commands.z-print-config.cpp b/src/vcpkg/commands.z-print-config.cpp index 499ecdc11c..d5ad761209 100644 --- a/src/vcpkg/commands.z-print-config.cpp +++ b/src/vcpkg/commands.z-print-config.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -42,25 +43,25 @@ namespace vcpkg { (void)args.parse_arguments(CommandZPrintConfigMetadata); Json::Object obj; - obj.insert("downloads", paths.downloads.native()); - obj.insert("default_triplet", default_triplet.canonical_name()); - obj.insert("host_triplet", host_triplet.canonical_name()); - obj.insert("vcpkg_root", paths.root.native()); - obj.insert("tools", paths.tools.native()); + obj.insert(JsonIdDownloads, paths.downloads.native()); + obj.insert(JsonIdDefaultTriplet, default_triplet.canonical_name()); + obj.insert(JsonIdHostTriplet, host_triplet.canonical_name()); + obj.insert(JsonIdVcpkgRoot, paths.root.native()); + obj.insert(JsonIdTools, paths.tools.native()); if (auto ci_env = args.detected_ci_environment().get()) { - obj.insert("detected_ci_environment", *ci_env); + obj.insert(JsonIdDetectedCIEnvironment, *ci_env); } if (auto i = paths.maybe_installed().get()) { - obj.insert("installed", i->root().native()); + obj.insert(JsonIdInstalled, i->root().native()); } - opt_add(obj, "buildtrees", paths.maybe_buildtrees()); - opt_add(obj, "packages", paths.maybe_packages()); + opt_add(obj, JsonIdBuildtrees, paths.maybe_buildtrees()); + opt_add(obj, JsonIdPackages, paths.maybe_packages()); if (paths.maybe_installed()) { - obj.insert("versions_output", paths.versions_output().native()); - obj.insert("manifest_mode_enabled", Json::Value::boolean(paths.manifest_mode_enabled())); + obj.insert(JsonIdVersionsOutput, paths.versions_output().native()); + obj.insert(JsonIdManifestModeEnabled, Json::Value::boolean(paths.manifest_mode_enabled())); } obj.sort_keys(); msg::write_unlocalized_text(Color::none, Json::stringify(obj) + "\n"); diff --git a/src/vcpkg/configure-environment.cpp b/src/vcpkg/configure-environment.cpp index 7f99f6c822..60d60defdb 100644 --- a/src/vcpkg/configure-environment.cpp +++ b/src/vcpkg/configure-environment.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,7 @@ namespace return; } - auto acquired_artifacts = pparsed->get("acquired_artifacts"); + auto acquired_artifacts = pparsed->get(JsonIdAcquiredArtifacts); if (acquired_artifacts) { if (acquired_artifacts->is_string()) @@ -56,7 +57,7 @@ namespace Debug::println("No artifacts acquired."); } - auto activated_artifacts = pparsed->get("activated_artifacts"); + auto activated_artifacts = pparsed->get(JsonIdActivatedArtifacts); if (activated_artifacts) { if (activated_artifacts->is_string()) diff --git a/src/vcpkg/export.prefab.cpp b/src/vcpkg/export.prefab.cpp index 8a08f72ecf..672c905631 100644 --- a/src/vcpkg/export.prefab.cpp +++ b/src/vcpkg/export.prefab.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -303,7 +304,7 @@ namespace vcpkg::Prefab Checks::msg_check_exit(VCPKG_LINE_INFO, required_archs.empty(), msgExportArchitectureReq); - Optional android_ndk_home = get_environment_variable("ANDROID_NDK_HOME"); + Optional android_ndk_home = get_environment_variable(EnvironmentVariableAndroidNdkHome); if (!android_ndk_home.has_value()) { @@ -323,7 +324,7 @@ namespace vcpkg::Prefab Checks::msg_check_maybe_upgrade(VCPKG_LINE_INFO, fs.exists(ndk_location, IgnoreErrors{}), msgAndroidHomeDirMissingProps, - msg::env_var = format_environment_variable("ANDROID_NDK_HOME"), + msg::env_var = format_environment_variable(EnvironmentVariableAndroidNdkHome), msg::path = source_properties_location); std::string content = fs.read_contents(source_properties_location, VCPKG_LINE_INFO); diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index cb17ecada9..2ab0267639 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -1285,7 +1285,7 @@ namespace return std::move(maybe_versions_json).error(); } - auto maybe_versions_array = versions_json->get("versions"); + auto maybe_versions_array = versions_json->get(JsonIdVersions); if (!maybe_versions_array || !maybe_versions_array->is_array()) { return msg::format_error(msgFailedToParseNoVersionsArray, msg::path = versions_file_path); @@ -1294,7 +1294,7 @@ namespace std::vector db_entries; GitVersionDbEntryArrayDeserializer deserializer{}; Json::Reader r(versions_file_path); - r.visit_in_key(*maybe_versions_array, "versions", db_entries, deserializer); + r.visit_in_key(*maybe_versions_array, JsonIdVersions, db_entries, deserializer); if (!r.errors().empty()) { return msg::format_error(msgFailedToParseVersionsFile, msg::path = versions_file_path) @@ -1332,7 +1332,7 @@ namespace return std::move(maybe_versions_json).error(); } - auto maybe_versions_array = versions_json->get("versions"); + auto maybe_versions_array = versions_json->get(JsonIdVersions); if (!maybe_versions_array || !maybe_versions_array->is_array()) { return msg::format_error(msgFailedToParseNoVersionsArray, msg::path = versions_file_path); @@ -1341,7 +1341,7 @@ namespace std::vector db_entries; FilesystemVersionDbEntryArrayDeserializer deserializer{registry_root}; Json::Reader r(versions_file_path); - r.visit_in_key(*maybe_versions_array, "versions", db_entries, deserializer); + r.visit_in_key(*maybe_versions_array, JsonIdVersions, db_entries, deserializer); if (!r.errors().empty()) { return msg::format_error(msgFailedToParseVersionsFile, msg::path = versions_file_path) diff --git a/src/vcpkg/spdx.cpp b/src/vcpkg/spdx.cpp index 07482c47d9..0b05ee1955 100644 --- a/src/vcpkg/spdx.cpp +++ b/src/vcpkg/spdx.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -15,7 +16,7 @@ static std::string fix_ref_version(StringView ref, StringView version) static std::string conclude_license(const std::string& license) { - if (license.empty()) return "NOASSERTION"; + if (license.empty()) return SpdxNoAssertion.to_string(); return license; } @@ -61,22 +62,22 @@ static Json::Object make_resource( std::string spdxid, std::string name, std::string downloadLocation, StringView sha512, StringView filename) { Json::Object obj; - obj.insert("SPDXID", std::move(spdxid)); - obj.insert("name", std::move(name)); + obj.insert(SpdxSpdxId, std::move(spdxid)); + obj.insert(JsonIdName, std::move(name)); if (!filename.empty()) { - obj.insert("packageFileName", filename); + obj.insert(SpdxPackageFileName, filename); } - obj.insert("downloadLocation", std::move(downloadLocation)); - obj.insert("licenseConcluded", "NOASSERTION"); - obj.insert("licenseDeclared", "NOASSERTION"); - obj.insert("copyrightText", "NOASSERTION"); + obj.insert(SpdxDownloadLocation, std::move(downloadLocation)); + obj.insert(SpdxLicenseConcluded, SpdxNoAssertion); + obj.insert(SpdxLicenseDeclared, SpdxNoAssertion); + obj.insert(SpdxCopyrightText, SpdxNoAssertion); if (!sha512.empty()) { - auto& chk = obj.insert("checksums", Json::Array()); + auto& chk = obj.insert(JsonIdChecksums, Json::Array()); auto& chk512 = chk.push_back(Json::Object()); - chk512.insert("algorithm", "SHA512"); - chk512.insert("checksumValue", Strings::ascii_to_lowercase(sha512)); + chk512.insert(JsonIdAlgorithm, JsonIdAllCapsSHA512); + chk512.insert(SpdxChecksumValue, Strings::ascii_to_lowercase(sha512)); } return obj; } @@ -87,13 +88,13 @@ Json::Value vcpkg::run_resource_heuristics(StringView contents, StringView versi // inclusion size_t n = 0; Json::Object ret; - auto& packages = ret.insert("packages", Json::Array{}); + auto& packages = ret.insert(JsonIdPackages, Json::Array{}); auto github = find_cmake_invocation(contents, "vcpkg_from_github"); if (!github.empty()) { - auto repo = extract_cmake_invocation_argument(github, "REPO"); - auto ref = fix_ref_version(extract_cmake_invocation_argument(github, "REF"), version_text); - auto sha = extract_cmake_invocation_argument(github, "SHA512"); + auto repo = extract_cmake_invocation_argument(github, CMakeVariableRepo); + auto ref = fix_ref_version(extract_cmake_invocation_argument(github, CMakeVariableRef), version_text); + auto sha = extract_cmake_invocation_argument(github, CMakeVariableSHA512); packages.push_back(make_resource(fmt::format("SPDXRef-resource-{}", ++n), repo.to_string(), @@ -104,27 +105,27 @@ Json::Value vcpkg::run_resource_heuristics(StringView contents, StringView versi auto git = find_cmake_invocation(contents, "vcpkg_from_git"); if (!git.empty()) { - auto url = extract_cmake_invocation_argument(github, "URL"); - auto ref = fix_ref_version(extract_cmake_invocation_argument(github, "REF"), version_text); + auto url = extract_cmake_invocation_argument(github, CMakeVariableUrl); + auto ref = fix_ref_version(extract_cmake_invocation_argument(github, CMakeVariableRef), version_text); packages.push_back(make_resource( fmt::format("SPDXRef-resource-{}", ++n), url.to_string(), fmt::format("git+{}@{}", url, ref), {}, {})); } auto distfile = find_cmake_invocation(contents, "vcpkg_download_distfile"); if (!distfile.empty()) { - auto url = extract_cmake_invocation_argument(distfile, "URLS"); - auto filename = extract_cmake_invocation_argument(distfile, "FILENAME"); - auto sha = extract_cmake_invocation_argument(distfile, "SHA512"); + auto url = extract_cmake_invocation_argument(distfile, CMakeVariableUrls); + auto filename = extract_cmake_invocation_argument(distfile, CMakeVariableFilename); + auto sha = extract_cmake_invocation_argument(distfile, CMakeVariableSHA512); packages.push_back(make_resource( fmt::format("SPDXRef-resource-{}", ++n), filename.to_string(), url.to_string(), sha, filename)); } auto sfg = find_cmake_invocation(contents, "vcpkg_from_sourceforge"); if (!sfg.empty()) { - auto repo = extract_cmake_invocation_argument(sfg, "REPO"); - auto ref = fix_ref_version(extract_cmake_invocation_argument(sfg, "REF"), version_text); - auto filename = extract_cmake_invocation_argument(sfg, "FILENAME"); - auto sha = extract_cmake_invocation_argument(sfg, "SHA512"); + auto repo = extract_cmake_invocation_argument(sfg, CMakeVariableRepo); + auto ref = fix_ref_version(extract_cmake_invocation_argument(sfg, CMakeVariableRef), version_text); + auto filename = extract_cmake_invocation_argument(sfg, CMakeVariableFilename); + auto sha = extract_cmake_invocation_argument(sfg, CMakeVariableSHA512); auto url = Strings::concat("https://sourceforge.net/projects/", repo, "/files/", ref, '/', filename); packages.push_back(make_resource( fmt::format("SPDXRef-resource-{}", ++n), filename.to_string(), std::move(url), sha, filename)); @@ -141,76 +142,79 @@ std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action, { Checks::check_exit(VCPKG_LINE_INFO, relative_paths.size() == hashes.size()); - const std::string noassert = "NOASSERTION"; const auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO); const auto& cpgh = *scfl.source_control_file->core_paragraph; - const StringView abi = action.package_abi() ? StringView(*action.package_abi().get()) : "NONE"; + StringView abi{SpdxNone}; + if (auto package_abi = action.package_abi().get()) + { + abi = *package_abi; + } Json::Object doc; - doc.insert("$schema", "https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.1/schemas/spdx-schema.json"); - doc.insert("spdxVersion", "SPDX-2.2"); - doc.insert("dataLicense", "CC0-1.0"); - doc.insert("SPDXID", "SPDXRef-DOCUMENT"); - doc.insert("documentNamespace", std::move(document_namespace)); - doc.insert("name", Strings::concat(action.spec.to_string(), '@', cpgh.version.to_string(), ' ', abi)); + doc.insert(JsonIdDollarSchema, "https://raw.githubusercontent.com/spdx/spdx-spec/v2.2.1/schemas/spdx-schema.json"); + doc.insert(SpdxVersion, SpdxTwoTwo); + doc.insert(SpdxDataLicense, SpdxCCZero); + doc.insert(SpdxSpdxId, SpdxRefDocument); + doc.insert(SpdxDocumentNamespace, std::move(document_namespace)); + doc.insert(JsonIdName, Strings::concat(action.spec.to_string(), '@', cpgh.version.to_string(), ' ', abi)); { - auto& cinfo = doc.insert("creationInfo", Json::Object()); - auto& creators = cinfo.insert("creators", Json::Array()); + auto& cinfo = doc.insert(SpdxCreationInfo, Json::Object()); + auto& creators = cinfo.insert(JsonIdCreators, Json::Array()); creators.push_back(Strings::concat("Tool: vcpkg-", VCPKG_VERSION_AS_STRING)); - cinfo.insert("created", std::move(created_time)); + cinfo.insert(JsonIdCreated, std::move(created_time)); } - auto& rels = doc.insert("relationships", Json::Array()); - auto& packages = doc.insert("packages", Json::Array()); + auto& rels = doc.insert(JsonIdRelationships, Json::Array()); + auto& packages = doc.insert(JsonIdPackages, Json::Array()); { auto& obj = packages.push_back(Json::Object()); - obj.insert("name", action.spec.name()); - obj.insert("SPDXID", "SPDXRef-port"); - obj.insert("versionInfo", cpgh.version.to_string()); - obj.insert("downloadLocation", scfl.spdx_location.empty() ? noassert : scfl.spdx_location); + obj.insert(JsonIdName, action.spec.name()); + obj.insert(SpdxSpdxId, SpdxRefPort); + obj.insert(SpdxVersionInfo, cpgh.version.to_string()); + obj.insert(SpdxDownloadLocation, scfl.spdx_location.empty() ? StringView{SpdxNoAssertion} : scfl.spdx_location); if (!cpgh.homepage.empty()) { - obj.insert("homepage", cpgh.homepage); + obj.insert(JsonIdHomepage, cpgh.homepage); } - obj.insert("licenseConcluded", conclude_license(cpgh.license.value_or(""))); - obj.insert("licenseDeclared", noassert); - obj.insert("copyrightText", noassert); - if (!cpgh.summary.empty()) obj.insert("summary", Strings::join("\n", cpgh.summary)); - if (!cpgh.description.empty()) obj.insert("description", Strings::join("\n", cpgh.description)); - obj.insert("comment", "This is the port (recipe) consumed by vcpkg."); + obj.insert(SpdxLicenseConcluded, conclude_license(cpgh.license.value_or(""))); + obj.insert(SpdxLicenseDeclared, SpdxNoAssertion); + obj.insert(SpdxCopyrightText, SpdxNoAssertion); + if (!cpgh.summary.empty()) obj.insert(JsonIdSummary, Strings::join("\n", cpgh.summary)); + if (!cpgh.description.empty()) obj.insert(JsonIdDescription, Strings::join("\n", cpgh.description)); + obj.insert(JsonIdComment, "This is the port (recipe) consumed by vcpkg."); { auto& rel = rels.push_back(Json::Object()); - rel.insert("spdxElementId", "SPDXRef-port"); - rel.insert("relationshipType", "GENERATES"); - rel.insert("relatedSpdxElement", "SPDXRef-binary"); + rel.insert(SpdxElementId, SpdxRefPort); + rel.insert(SpdxRelationshipType, SpdxGenerates); + rel.insert(SpdxRelatedSpdxElement, SpdxRefBinary); } for (size_t i = 0; i < relative_paths.size(); ++i) { auto& rel = rels.push_back(Json::Object()); - rel.insert("spdxElementId", "SPDXRef-port"); - rel.insert("relationshipType", "CONTAINS"); - rel.insert("relatedSpdxElement", fmt::format("SPDXRef-file-{}", i)); + rel.insert(SpdxElementId, SpdxRefPort); + rel.insert(SpdxRelationshipType, SpdxContains); + rel.insert(SpdxRelatedSpdxElement, fmt::format("SPDXRef-file-{}", i)); } } { auto& obj = packages.push_back(Json::Object()); - obj.insert("name", action.spec.to_string()); - obj.insert("SPDXID", "SPDXRef-binary"); - obj.insert("versionInfo", abi); - obj.insert("downloadLocation", "NONE"); - obj.insert("licenseConcluded", conclude_license(cpgh.license.value_or(""))); - obj.insert("licenseDeclared", noassert); - obj.insert("copyrightText", noassert); - obj.insert("comment", "This is a binary package built by vcpkg."); + obj.insert(JsonIdName, action.spec.to_string()); + obj.insert(SpdxSpdxId, SpdxRefBinary); + obj.insert(SpdxVersionInfo, abi); + obj.insert(SpdxDownloadLocation, SpdxNone); + obj.insert(SpdxLicenseConcluded, conclude_license(cpgh.license.value_or(""))); + obj.insert(SpdxLicenseDeclared, SpdxNoAssertion); + obj.insert(SpdxCopyrightText, SpdxNoAssertion); + obj.insert(JsonIdComment, "This is a binary package built by vcpkg."); { auto& rel = rels.push_back(Json::Object()); - rel.insert("spdxElementId", "SPDXRef-binary"); - rel.insert("relationshipType", "GENERATED_FROM"); - rel.insert("relatedSpdxElement", "SPDXRef-port"); + rel.insert(SpdxElementId, SpdxRefBinary); + rel.insert(SpdxRelationshipType, SpdxGeneratedFrom); + rel.insert(SpdxRelatedSpdxElement, SpdxRefPort); } } - auto& files = doc.insert("files", Json::Array()); + auto& files = doc.insert(JsonIdFiles, Json::Array()); { for (size_t i = 0; i < relative_paths.size(); ++i) { @@ -218,27 +222,27 @@ std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action, const auto& hash = hashes[i]; auto& obj = files.push_back(Json::Object()); - obj.insert("fileName", "./" + path.generic_u8string()); + obj.insert(SpdxFileName, "./" + path.generic_u8string()); const auto ref = fmt::format("SPDXRef-file-{}", i); - obj.insert("SPDXID", ref); - auto& checksum = obj.insert("checksums", Json::Array()); + obj.insert(SpdxSpdxId, ref); + auto& checksum = obj.insert(JsonIdChecksums, Json::Array()); auto& checksum1 = checksum.push_back(Json::Object()); - checksum1.insert("algorithm", "SHA256"); - checksum1.insert("checksumValue", hash); - obj.insert("licenseConcluded", noassert); - obj.insert("copyrightText", noassert); + checksum1.insert(JsonIdAlgorithm, JsonIdAllCapsSHA256); + checksum1.insert(SpdxChecksumValue, hash); + obj.insert(SpdxLicenseConcluded, SpdxNoAssertion); + obj.insert(SpdxCopyrightText, SpdxNoAssertion); { auto& rel = rels.push_back(Json::Object()); - rel.insert("spdxElementId", ref); - rel.insert("relationshipType", "CONTAINED_BY"); - rel.insert("relatedSpdxElement", "SPDXRef-port"); + rel.insert(SpdxElementId, ref); + rel.insert(SpdxRelationshipType, SpdxContainedBy); + rel.insert(SpdxRelatedSpdxElement, SpdxRefPort); } - if (path == "vcpkg.json") + if (path == FileVcpkgDotJson) { auto& rel = rels.push_back(Json::Object()); - rel.insert("spdxElementId", ref); - rel.insert("relationshipType", "DEPENDENCY_MANIFEST_OF"); - rel.insert("relatedSpdxElement", "SPDXRef-port"); + rel.insert(SpdxElementId, ref); + rel.insert(SpdxRelationshipType, SpdxDependencyManifestOf); + rel.insert(SpdxRelatedSpdxElement, SpdxRefPort); } } } @@ -247,9 +251,9 @@ std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action, { if (!rdoc.is_object()) continue; auto robj = std::move(rdoc).object(VCPKG_LINE_INFO); - append_move_if_exists_and_array(rels, robj, "relationships"); - append_move_if_exists_and_array(files, robj, "files"); - append_move_if_exists_and_array(packages, robj, "packages"); + append_move_if_exists_and_array(rels, robj, JsonIdRelationships); + append_move_if_exists_and_array(files, robj, JsonIdFiles); + append_move_if_exists_and_array(packages, robj, JsonIdPackages); } return Json::stringify(doc); diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 7940e94b6a..4247cf9018 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -323,18 +323,19 @@ namespace vcpkg SwitchVcpkgRoot, StabilityTag::Standard, args.vcpkg_root_dir_arg, - msg::format(msgVcpkgRootsDir, msg::env_var = format_environment_variable("VCPKG_ROOT"))); + msg::format(msgVcpkgRootsDir, msg::env_var = format_environment_variable(EnvironmentVariableVcpkgRoot))); args.parser.parse_option( SwitchTriplet, StabilityTag::Standard, args.triplet, - msg::format(msgSpecifyTargetArch, msg::env_var = format_environment_variable("VCPKG_DEFAULT_TRIPLET"))); + msg::format(msgSpecifyTargetArch, + msg::env_var = format_environment_variable(EnvironmentVariableVcpkgDefaultTriplet))); args.parser.parse_option( SwitchHostTriplet, StabilityTag::Standard, args.host_triplet, - msg::format(msgSpecifyHostArch, msg::env_var = format_environment_variable("VCPKG_DEFAULT_HOST_TRIPLET"))); - args.parser.parse_option(JsonIdManifestRoot, StabilityTag::Experimental, args.manifest_root_dir); + msg::format(msgSpecifyHostArch, + msg::env_var = format_environment_variable(EnvironmentVariableVcpkgDefaultHostTriplet))); args.parser.parse_option(SwitchManifestRoot, StabilityTag::Experimental, args.manifest_root_dir); args.parser.parse_option(SwitchBuildtreesRoot, StabilityTag::Experimental, @@ -344,7 +345,8 @@ namespace vcpkg SwitchDownloadsRoot, StabilityTag::Standard, args.downloads_root_dir, - msg::format(msgDownloadRootsDir, msg::env_var = format_environment_variable("VCPKG_DOWNLOADS"))); + msg::format(msgDownloadRootsDir, + msg::env_var = format_environment_variable(EnvironmentVariableVcpkgDownloads))); args.parser.parse_option( SwitchInstallRoot, StabilityTag::Experimental, args.install_root_dir, msg::format(msgInstallRootDir)); args.parser.parse_option( diff --git a/vcpkg-artifacts/session.ts b/vcpkg-artifacts/session.ts index ec28cb593b..d723a37f9b 100644 --- a/vcpkg-artifacts/session.ts +++ b/vcpkg-artifacts/session.ts @@ -253,8 +253,8 @@ export class Session { const telemetryFile = this.telemetryFile; if (telemetryFile) { return telemetryFile.writeUTF8(JSON.stringify({ - 'acquired_artifacts': acquiredArtifacts, - 'activated_artifacts': activatedArtifacts + 'acquired-artifacts': acquiredArtifacts, + 'activated-artifacts': activatedArtifacts })); }