Skip to content

Commit

Permalink
Add support for UnsupportedOSArchitecture manifest entry (microsoft#1807
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Chacón authored Jan 5, 2022
1 parent 64378e1 commit cfd8b29
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/AppInstallerCLICore/Workflows/ManifestComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ namespace AppInstaller::CLI::Workflow

InapplicabilityFlags IsApplicable(const Manifest::ManifestInstaller& installer) override
{
if (CheckAllowedArchitecture(installer.Arch) == Utility::InapplicableArchitecture)
if (CheckAllowedArchitecture(installer.Arch) == Utility::InapplicableArchitecture ||
IsSystemArchitectureUnsupportedByInstaller(installer))
{
return InapplicabilityFlags::MachineArchitecture;
}

return InapplicabilityFlags::None;
}

Expand All @@ -118,12 +119,18 @@ namespace AppInstaller::CLI::Workflow
if (Utility::IsApplicableArchitecture(installer.Arch) == Utility::InapplicableArchitecture)
{
result = "Machine is not compatible with ";
result += Utility::ToString(installer.Arch);
}
else if (IsSystemArchitectureUnsupportedByInstaller(installer))
{
result = "System architecture is unsupported by installer";
}
else
{
result = "Architecture was excluded by caller : ";
result += Utility::ToString(installer.Arch);
}
result += Utility::ToString(installer.Arch);

return result;
}

Expand Down Expand Up @@ -153,6 +160,15 @@ namespace AppInstaller::CLI::Workflow
}
}

bool IsSystemArchitectureUnsupportedByInstaller(const ManifestInstaller& installer)
{
auto unsupportedItr = std::find(
installer.UnsupportedOSArchitectures.begin(),
installer.UnsupportedOSArchitectures.end(),
Utility::GetSystemArchitecture());
return unsupportedItr != installer.UnsupportedOSArchitectures.end();
}

std::string GetAllowedArchitecturesString()
{
std::stringstream result;
Expand Down
2 changes: 0 additions & 2 deletions src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ namespace AppInstaller::CLI::Workflow
std::vector<Utility::Architecture> requiredArchitectures = Settings::User().Get<Settings::Setting::InstallArchitectureRequirement>();
std::vector<Utility::Architecture> optionalArchitectures = Settings::User().Get<Settings::Setting::InstallArchitecturePreference>();


if (!requiredArchitectures.empty())
{
context.Add<Execution::Data::AllowedArchitectures>({ requiredArchitectures.begin(), requiredArchitectures.end() });
Expand All @@ -998,7 +997,6 @@ namespace AppInstaller::CLI::Workflow
{
optionalArchitectures.emplace_back(Utility::Architecture::Unknown);
context.Add<Execution::Data::AllowedArchitectures>({ optionalArchitectures.begin(), optionalArchitectures.end() });

}
}
ManifestComparator manifestComparator(context, installationMetadata);
Expand Down
50 changes: 49 additions & 1 deletion src/AppInstallerCLITests/ManifestComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ struct ManifestComparatorTestContext : public NullStream, Context
ManifestComparatorTestContext() : NullStream(), Context(*m_nullOut, *m_nullIn) {}
};

const ManifestInstaller& AddInstaller(Manifest& manifest, Architecture architecture, InstallerTypeEnum installerType, ScopeEnum scope = ScopeEnum::Unknown, std::string minOSVersion = {}, std::string locale = {})
const ManifestInstaller& AddInstaller(
Manifest& manifest,
Architecture architecture,
InstallerTypeEnum installerType,
ScopeEnum scope = ScopeEnum::Unknown,
std::string minOSVersion = {},
std::string locale = {},
std::vector<Architecture> unsupportedOSArchitectures = {})
{
ManifestInstaller toAdd;
toAdd.Arch = architecture;
toAdd.InstallerType = installerType;
toAdd.Scope = scope;
toAdd.MinOSVersion = minOSVersion;
toAdd.Locale = locale;
toAdd.UnsupportedOSArchitectures = unsupportedOSArchitectures;

manifest.Installers.emplace_back(std::move(toAdd));

Expand Down Expand Up @@ -511,6 +519,46 @@ TEST_CASE("ManifestComparator_AllowedArchitecture", "[manifest_comparator]")
}
}

TEST_CASE("ManifestComparator_UnsupportedOSArchitecture", "[manifest_comparator]")
{
auto systemArchitecture = GetSystemArchitecture();
auto applicableArchitectures = GetApplicableArchitectures();

// Try to find an applicable architecture that is not the system architecture
auto itr = std::find_if(applicableArchitectures.begin(), applicableArchitectures.end(), [&](const auto& arch) { return arch != systemArchitecture; });
if (itr == applicableArchitectures.end())
{
// This test requires having an applicable architecture different from the system one.
// TODO: Does this actually happen in any arch we use?
return;
}

auto applicableArchitecture = *itr;

Manifest manifest;

SECTION("System is unsupported")
{
ManifestInstaller installer = AddInstaller(manifest, applicableArchitecture, InstallerTypeEnum::Msi, {}, {}, {}, { systemArchitecture });

ManifestComparator mc(ManifestComparatorTestContext{}, {});
auto [result, inapplicabilities] = mc.GetPreferredInstaller(manifest);

REQUIRE(!result);
RequireInapplicabilities(inapplicabilities, { InapplicabilityFlags::MachineArchitecture });
}
SECTION("Other is unsupported")
{
ManifestInstaller installer = AddInstaller(manifest, applicableArchitecture, InstallerTypeEnum::Msi, {}, {}, {}, { applicableArchitecture });

ManifestComparator mc(ManifestComparatorTestContext{}, {});
auto [result, inapplicabilities] = mc.GetPreferredInstaller(manifest);

RequireInstaller(result, installer);
REQUIRE(inapplicabilities.empty());
}
}

TEST_CASE("ManifestComparator_Inapplicabilities", "[manifest_comparator]")
{
Manifest manifest;
Expand Down

0 comments on commit cfd8b29

Please sign in to comment.