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

Conversation

jedieaston
Copy link
Contributor

@jedieaston jedieaston commented Nov 18, 2021


Resolves #906.

This is the other half of #906, adding settings to select a preferred or required architecture. The required architecture behaves exactly like the --architecture flag, where AllowedArchitectures only contains the architecture that is in the setting. The preferred architecture behaves much like the preferred scope setting, where the installer entry with the preferred architecture is selected over all others, but if there isn't an installer entry with the preferred architecture, the normal rationale is used.

The fields are validated by determining if the architecture selected is compatible with the current system. By default the setting is set to neutral. (although if there is a reason we need to allow users to require neutral manifests, that could just as easily be unknown. I figured there were few scenarios where a user wouldn't want a installer that only had the relevant bits for their system over a neutral one with all of the bits.)

The only other note I have is that I decided to make these just strings instead of arrays since that's what it sounded like in the original ticket. If there's a usecase where someone wants to prefer multiple architectures, that's a quick fix (although there's only ever at most three options, so I doubt that comes up much?).

Tested: manually. I can write unit tests if necessary.

image

Edit: also, sorry for the big diff on UserSettings.cpp. Visual Studio got upset that the line endings were mixed.

Microsoft Reviewers: Open in CodeFlow

@jedieaston jedieaston requested a review from a team as a code owner November 18, 2021 20:18
@ghost ghost added the Issue-Feature This is a feature request for the Windows Package Manager client. label Nov 18, 2021
},
"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 }.


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.

},
"architecture": {
"description": "The architecture for a package install",
"type": "string",
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 }.

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.

WINGET_VALIDATE_SIGNATURE(InstallArchitecturePreference)
{
Utility::Architecture arch = Utility::ConvertToArchitectureEnum(value);
if (Utility::IsApplicableArchitecture(arch) != Utility::InapplicableArchitecture)
Copy link
Member

Choose a reason for hiding this comment

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

You have tabs here; please convert to 4 spaces.

WINGET_VALIDATE_PASS_THROUGH(TelemetryDisable)
WINGET_VALIDATE_PASS_THROUGH(EFDirectMSI)
WINGET_VALIDATE_PASS_THROUGH(EnableSelfInitiatedMinidump)

Copy link
Member

Choose a reason for hiding this comment

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

What did whitespace do to you?

@ghost ghost added the Needs-Author-Feedback Issue needs attention from issue or PR author label Nov 19, 2021
@ghost ghost removed the Needs-Author-Feedback Issue needs attention from issue or PR author label Nov 25, 2021
@jedieaston
Copy link
Contributor Author

I fixed all of the complaints (array is used, ManifestComparator isn't messed with, whitespace fixed). All of the changes to AllowedArchitectures are now dealt with in SelectInstaller.

Sorry for the delay, I was traveling for Thanksgiving.

@ghost ghost added Needs-Author-Feedback Issue needs attention from issue or PR author and removed Needs-Author-Feedback Issue needs attention from issue or PR author labels Nov 29, 2021
@jedieaston
Copy link
Contributor Author

I noticed something when working on that last commit, which is that adding the Unknown architecture to AllowedArchitectures makes the ManifestComparator use its traditional logic instead of accepting the user's preference above all else:

settings.json:

{
    "$schema": "https://aka.ms/winget-settings.schema.json",

    // For documentation on these settings, see: https://aka.ms/winget-settings
    // "source": {
    //    "autoUpdateIntervalInMinutes": 5
    // },
    "installBehavior": {
        "preferences": {
            "architectures": ["x86"]
        }
    },
}

Relevant logs from wingetdev install Google.Chrome

2021-11-30 09:27:59.146 [YAML] Detected UTF-8
2021-11-30 09:27:59.153 [CLI ] Manifest fields: Name [Google Chrome], Version [96.0.4664.45]
2021-11-30 09:28:39.117 [CLI ] Locale Comparator created with Required Locales: [] , Preferred Locales: [en-US]
2021-11-30 09:28:39.117 [CLI ] Architecture Comparator created with allowed architectures: X64, X86, Neutral
2021-11-30 09:28:39.117 [CLI ] Starting installer selection.
2021-11-30 09:28:39.117 [CLI ] Installer [X64,msi,Machine,] is current best choice
2021-11-30 09:28:39.117 [CLI ] Installer [X64,msi,Machine,] is better than [X86,msi,Machine,] due to: Machine Architecture
2021-11-30 09:28:39.117 [CLI ] Completed installer selection.

Am I missing something here or do I still need to do something to ManifestComparator to make sure that the preferences are honored above the traditional logic?

@JohnMcPMS
Copy link
Member

Am I missing something here or do I still need to do something to ManifestComparator to make sure that the preferences are honored above the traditional logic?

Are you putting the Unknown value at the back of the vector? I would double check in the allowed architectures vector coming in is { x86, Unknown }.

@jedieaston
Copy link
Contributor Author

That was exactly it, thanks! Now it's using emplace_back, and all is right with the world.

@JohnMcPMS
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@JohnMcPMS JohnMcPMS merged commit f1c2358 into microsoft:master Dec 1, 2021
@jedieaston jedieaston deleted the stlouis-eat-your-heart-out branch December 1, 2021 19:45
hackean-msft pushed a commit to hackean-msft/winget-cli that referenced this pull request Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Feature This is a feature request for the Windows Package Manager client.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify installer architecture
4 participants