Skip to content
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

Added settings to select preferred/required architecture. #1727

Merged
merged 6 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ The `locale` behavior affects the choice of installer based on installer locale.
}
},
```
### Architecture

The `architecture` behavior affects what architecture will be selected when installing a package. The matching parameter is `--architecture`. Note that only architectures compatible with your system can be selected.

```json
"installBehavior": {
"preferences": {
"architecture": "x64"
}
},
```

## Telemetry

Expand Down
12 changes: 12 additions & 0 deletions schemas/JSON/settings/settings.schema.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
},
"minItems": 1,
"maxItems": 10
},
"architecture": {
"description": "The architecture for a package install",
"type": "string",
Copy link
Contributor

@yao-msft yao-msft Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we consider making it a list to be more flexible(like locale above) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ticket made it sound like you’d select a preferred (single) architecture instead of multiple, but I can do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking we would have a "single" preferred or required architecture. I can't think of a valid scenario where there would be three architectures that could all work and you would prefer (a), accept (b), and reject (c). With locale, I could see a set you would like in some kind of order so you could essentially have a bit of control when one of the languages you used was available, but it wasn't a logical close match otherwise. Let's keep this as a singleton for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just after I hit send, I remembered some emulation might be valid, but I think the "requires" forces it to be what I want and "prefers" will take anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how it works. Prefers will fallback to the normal logic if the architecture you prefer is not available. If your required architecture is not available you get an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just not completing thoughts last night. Days have bee feeling like weeks lately. I'm trying to close a lot of gaps. We have some heavy investments coming in related to Intune integration for the replacement of store for business, and Win32 support for the store. The next couple of quarters are going to be busy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have it be an array to start. At some point someone will want an array and then we will have two settings (or have to implement it allowing both scalar and array). Even requirements makes sense to support multiple, just like locales. I might be an ARM purist on my ARM64 machine and so require { arm64, arm }.

"enum": [
"neutral",
"x64",
"x86",
"arm64",
"arm"
],
"default": "neutral"
}
}
},
Expand Down
17 changes: 12 additions & 5 deletions src/AppInstallerCLICore/Workflows/ManifestComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ namespace AppInstaller::CLI::Workflow

struct MachineArchitectureComparator : public details::ComparisonField
{
MachineArchitectureComparator() : details::ComparisonField("Machine Architecture") {}
MachineArchitectureComparator(Utility::Architecture preference) :
details::ComparisonField("Machine Architecture"), m_preference(preference) {}

MachineArchitectureComparator(std::vector<Utility::Architecture> allowedArchitectures) :
details::ComparisonField("Machine Architecture"), m_allowedArchitectures(std::move(allowedArchitectures))
MachineArchitectureComparator(std::vector<Utility::Architecture> allowedArchitectures, Utility::Architecture preference) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have needed to change to fully support preferences and requirements. An entry of Utility::Architecture::Unknown in Execution::Data::AllowedArchitectures indicates "and all the rest"; aka that the previous architectures are preferences. Thus the only difference between the preferences and requirements settings are whether to append Unknown.

details::ComparisonField("Machine Architecture"), m_allowedArchitectures(std::move(allowedArchitectures)), m_preference(preference)
{
AICLI_LOG(CLI, Verbose, << "Architecture Comparator created with allowed architectures: " << GetAllowedArchitecturesString());
}

// TODO: At some point we can do better about matching the currently installed architecture
static std::unique_ptr<MachineArchitectureComparator> Create(const Execution::Context& context, const Repository::IPackageVersion::Metadata&)
{
Utility::Architecture preference = Settings::User().Get<Settings::Setting::InstallArchitecturePreference>();
if (context.Contains(Execution::Data::AllowedArchitectures))
{
const std::vector<Utility::Architecture>& allowedArchitectures = context.Get<Execution::Data::AllowedArchitectures>();
Expand Down Expand Up @@ -95,11 +97,11 @@ namespace AppInstaller::CLI::Workflow
}
}

return std::make_unique<MachineArchitectureComparator>(std::move(result));
return std::make_unique<MachineArchitectureComparator>(std::move(result), preference);
}
}

return std::make_unique<MachineArchitectureComparator>();
return std::make_unique<MachineArchitectureComparator>(preference);
}

InapplicabilityFlags IsApplicable(const Manifest::ManifestInstaller& installer) override
Expand Down Expand Up @@ -129,6 +131,10 @@ namespace AppInstaller::CLI::Workflow

bool IsFirstBetter(const Manifest::ManifestInstaller& first, const Manifest::ManifestInstaller& second) override
{
if (m_preference != Utility::Architecture::Neutral)
{
return (first.Arch == m_preference && second.Arch != m_preference);
}
auto arch1 = CheckAllowedArchitecture(first.Arch);
auto arch2 = CheckAllowedArchitecture(second.Arch);

Expand Down Expand Up @@ -170,6 +176,7 @@ namespace AppInstaller::CLI::Workflow
}

std::vector<Utility::Architecture> m_allowedArchitectures;
Utility::Architecture m_preference;
};

struct InstalledTypeComparator : public details::ComparisonField
Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,20 @@ namespace AppInstaller::CLI::Workflow
bool isUpdate = WI_IsFlagSet(context.GetFlags(), Execution::ContextFlag::InstallerExecutionUseUpdate);

IPackageVersion::Metadata installationMetadata;
Utility::Architecture requiredArchitecture = Settings::User().Get<Settings::Setting::InstallArchitectureRequirement>();
if (isUpdate)
{
installationMetadata = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata();
}
if (context.Args.Contains(Execution::Args::Type::InstallArchitecture))
{
// arguments override settings.
context.Add<Execution::Data::AllowedArchitectures>({ Utility::ConvertToArchitectureEnum(std::string(context.Args.GetArg(Execution::Args::Type::InstallArchitecture))) });
}
else if (requiredArchitecture != Utility::Architecture::Neutral)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this an unconditional else and the check the settings (both once you revert the ManifestComparator changes) inside it. That way we don't do unnecessary work getting the setting(s) if there is an argument passed in.

{
context.Add<Execution::Data::AllowedArchitectures>({ requiredArchitecture });
}
ManifestComparator manifestComparator(context, installationMetadata);
auto [installer, inapplicabilities] = manifestComparator.GetPreferredInstaller(context.Get<Execution::Data::Manifest>());

Expand Down
7 changes: 7 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <variant>
#include <vector>

#include "AppInstallerArchitecture.h"

using namespace std::chrono_literals;
using namespace std::string_view_literals;

Expand Down Expand Up @@ -54,6 +56,7 @@ namespace AppInstaller::Settings
DeliveryOptimization,
};


// Enum of settings.
// Must start at 0 to enable direct access to variant in UserSettings.
// Max must be last and unused.
Expand All @@ -73,6 +76,8 @@ namespace AppInstaller::Settings
InstallScopeRequirement,
NetworkDownloader,
NetworkDOProgressTimeoutInSeconds,
InstallArchitecturePreference,
InstallArchitectureRequirement,
InstallLocalePreference,
InstallLocaleRequirement,
EFDirectMSI,
Expand Down Expand Up @@ -116,6 +121,8 @@ namespace AppInstaller::Settings
SETTINGMAPPING_SPECIALIZATION(Setting::EFExperimentalArg, bool, bool, false, ".experimentalFeatures.experimentalArg"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFDependencies, bool, bool, false, ".experimentalFeatures.dependencies"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::TelemetryDisable, bool, bool, false, ".telemetry.disable"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::InstallArchitecturePreference, std::string, Utility::Architecture, Utility::Architecture::Neutral, ".installBehavior.preferences.architecture"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::InstallArchitectureRequirement, std::string, Utility::Architecture, Utility::Architecture::Neutral, ".installBehavior.requirements.architecture"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::InstallScopePreference, std::string, ScopePreference, ScopePreference::User, ".installBehavior.preferences.scope"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::InstallScopeRequirement, std::string, ScopePreference, ScopePreference::None, ".installBehavior.requirements.scope"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::NetworkDownloader, std::string, InstallerDownloader, InstallerDownloader::Default, ".network.downloader"sv);
Expand Down
Loading