Skip to content

Commit

Permalink
Create machinery for disabling experimental features; disable some ve…
Browse files Browse the repository at this point in the history
…rbose logs (#1490)
  • Loading branch information
JohnMcPMS authored Sep 21, 2021
1 parent d15d6e3 commit c0e7409
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/AppInstallerCLICore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
<PreprocessorDefinitions>AICLI_DISABLE_TEST_HOOKS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(WingetDisableExperimentalFeatures)'=='true'">
<ClCompile>
<PreprocessorDefinitions>WINGET_DISABLE_EXPERIMENTAL_FEATURES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Argument.h" />
<ClInclude Include="ChannelStreams.h" />
Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerCLICore/Commands/FeaturesCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace AppInstaller::CLI

void FeaturesCommand::ExecuteInternal(Execution::Context& context) const
{
#ifdef WINGET_DISABLE_EXPERIMENTAL_FEATURES
context.Reporter.Info() << Resource::String::FeaturesMessageDisabledByBuild << std::endl;
#else
if (GroupPolicies().IsEnabled(TogglePolicy::Policy::ExperimentalFeatures) &&
GroupPolicies().IsEnabled(TogglePolicy::Policy::Settings))
{
Expand Down Expand Up @@ -61,5 +64,6 @@ namespace AppInstaller::CLI
// Better work hard to get some out there!
context.Reporter.Info() << Resource::String::NoExperimentalFeaturesMessage << std::endl;
}
#endif
}
}
6 changes: 3 additions & 3 deletions src/AppInstallerCLICore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace AppInstaller::CLI

// Enable all logging for this phase; we will update once we have the arguments
Logging::Log().EnableChannel(Logging::Channel::All);
Logging::Log().SetLevel(Logging::Level::Verbose);
Logging::Log().SetLevel(Logging::Level::Info);
Logging::AddFileLogger();
Logging::EnableWilFailureTelemetry();

Expand Down Expand Up @@ -100,9 +100,9 @@ namespace AppInstaller::CLI
command->ParseArguments(invocation, context.Args);

// Change logging level to Info if Verbose not requested
if (!context.Args.Contains(Execution::Args::Type::VerboseLogs))
if (context.Args.Contains(Execution::Args::Type::VerboseLogs))
{
Logging::Log().SetLevel(Logging::Level::Info);
Logging::Log().SetLevel(Logging::Level::Verbose);
}

context.UpdateForArgs();
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesFeature);
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesLink);
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesMessage);
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesMessageDisabledByBuild);
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesMessageDisabledByPolicy);
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesProperty);
WINGET_DEFINE_RESOURCE_STRINGID(FeaturesStatus);
Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1165,4 +1165,8 @@ Please specify one of them using the `--source` option to proceed.</value>
<data name="SearchFailureErrorNoMatches" xml:space="preserve">
<value>No packages were found among the working sources.</value>
</data>
<data name="FeaturesMessageDisabledByBuild" xml:space="preserve">
<value>This is a stable release of the Windows Package Manager. If you would like to try experimental features, please install a pre-release build. Instructions are available on GitHub at https://github.com/microsoft/winget-cli.</value>
<comment>{Locked="Windows Package Manager","GitHub","https://github.com/microsoft/winget-cli"}</comment>
</data>
</root>
5 changes: 5 additions & 0 deletions src/AppInstallerCommonCore/AppInstallerCommonCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@
<PreprocessorDefinitions>AICLI_DISABLE_TEST_HOOKS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(WingetDisableExperimentalFeatures)'=='true'">
<ClCompile>
<PreprocessorDefinitions>WINGET_DISABLE_EXPERIMENTAL_FEATURES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="DODownloader.h" />
<ClInclude Include="Public\winget\AdminSettings.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCommonCore/ExperimentalFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace AppInstaller::Settings
return true;
}

#ifdef WINGET_DISABLE_EXPERIMENTAL_FEATURES
UNREFERENCED_PARAMETER(userSettings);
return false;
#else

if (!GroupPolicies().IsEnabled(TogglePolicy::Policy::ExperimentalFeatures))
{
AICLI_LOG(Core, Info, <<
Expand All @@ -40,6 +45,7 @@ namespace AppInstaller::Settings
default:
THROW_HR(E_UNEXPECTED);
}
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCommonCore/GroupPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace AppInstaller::Settings
return std::nullopt;
}

AICLI_LOG(Core, Info, << "Found policy '" << valueName << "', Value: " << *intValue);
AICLI_LOG(Core, Verbose, << "Found policy '" << valueName << "', Value: " << *intValue);
return (bool)*intValue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCommonCore/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace AppInstaller::Settings

void LogSettingAction(std::string_view action, const StreamDefinition& def)
{
AICLI_LOG(Core, Info, << "Setting action: " << action << ", Type: " << ToString(def.Type) << ", Name: " << def.Path);
AICLI_LOG(Core, Verbose, << "Setting action: " << action << ", Type: " << ToString(def.Type) << ", Name: " << def.Path);
}

// A settings container.
Expand Down
8 changes: 4 additions & 4 deletions src/AppInstallerCommonCore/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ namespace AppInstaller::Settings
// Add it to the map
settings[S].emplace<details::SettingIndex(S)>(
std::forward<typename details::SettingMapping<S>::value_t>(validatedValue.value()));
AICLI_LOG(Core, Info, << "Valid setting from Group Policy. Field: " << path << " Value: " << GetValueString(policyValue.value()));
AICLI_LOG(Core, Verbose, << "Valid setting from Group Policy. Field: " << path << " Value: " << GetValueString(policyValue.value()));
}
else
{
auto valueAsString = GetValueString(policyValue.value());
AICLI_LOG(Core, Info, << "Invalid setting from Group Policy. Field: " << path << " Value: " << valueAsString);
AICLI_LOG(Core, Error, << "Invalid setting from Group Policy. Field: " << path << " Value: " << valueAsString);
warnings.emplace_back(StringResource::String::SettingsWarningInvalidValueFromPolicy, path, valueAsString);
}

Expand All @@ -148,7 +148,7 @@ namespace AppInstaller::Settings
// Finally add it to the map
settings[S].emplace<details::SettingIndex(S)>(
std::forward<typename details::SettingMapping<S>::value_t>(validatedValue.value()));
AICLI_LOG(Core, Info, << "Valid setting. Field: " << path << " Value: " << GetValueString(jsonValue.value()));
AICLI_LOG(Core, Verbose, << "Valid setting. Field: " << path << " Value: " << GetValueString(jsonValue.value()));
}
else
{
Expand All @@ -165,7 +165,7 @@ namespace AppInstaller::Settings
}
else
{
AICLI_LOG(Core, Info, << "Setting " << path << " not found. Using default");
AICLI_LOG(Core, Verbose, << "Setting " << path << " not found. Using default");
}
}

Expand Down

0 comments on commit c0e7409

Please sign in to comment.