diff --git a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt index b309bca43b..207a9921e6 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/WinComponents.kt @@ -105,14 +105,9 @@ object WinComponents { const val VCREDIST_ARM64 = "vcredist2022_arm64" internal fun builtInArm64Runtime(): Component { - fun value(view: String, name: String, type: String, data: String) = Step("set_register_key", JSONObject() - .put("action", "set_register_key").put("key", "HKLM\\Software\\${view}Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64") - .put("value", name).put("type", type).put("data", data)) - val steps = listOf("", "Wow6432Node\\").flatMap { view -> - listOf(value(view, "Installed", "REG_DWORD", "1"), value(view, "Major", "REG_DWORD", "14"), value(view, "Minor", "REG_DWORD", "44"), - value(view, "Bld", "REG_DWORD", "35211"), value(view, "Rbld", "REG_DWORD", "0"), value(view, "Version", "REG_SZ", "v14.44.35211.00")) - } - return Component(VCREDIST_ARM64, "Microsoft Visual C++ 2015-2022 ARM64 runtime 14.44.35211 (registry entries only)", "Microsoft", "ready", emptyList(), steps) + val install = Step("install_exe", JSONObject().put("action", "install_exe").put("file_name", "VC_redist.arm64.exe") + .put("url", "https://aka.ms/vs/17/release/vc_redist.arm64.exe")) + return Component(VCREDIST_ARM64, "Microsoft Visual C++ 2015-2022 Redistributable (arm64)", "Microsoft", "ready", emptyList(), listOf(install), revision = 2) } private fun parse(body: String): List? { diff --git a/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt b/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt index 8311736999..4d70c02022 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/WinComponentsSupportTest.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.session.WinComponents.Support import org.json.JSONObject import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -31,12 +32,13 @@ class WinComponentsSupportTest { step("install_msi", "url" to "$base/ps-x86.msi"), step("install_msi", "url" to "$base/ps-x64.msi")))) } - @Test fun builtInArm64RuntimeIsRegistryOnlyInBothViews() { + @Test fun builtInArm64RuntimeInstallsTheRedistributable() { val c = WinComponents.builtInArm64Runtime() assertEquals(Support.READY, support(c)) - assertEquals(12, c.steps.count { it.action == "set_register_key" }) - assertEquals(setOf("HKLM\\Software\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64", - "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64"), c.steps.map { it.str("key") }.toSet()) + assertEquals(listOf("install_exe"), c.steps.map { it.action }) + assertEquals("VC_redist.arm64.exe", c.steps.single().str("file_name")) + assertEquals(0, c.steps.count { it.action == "set_register_key" }) + assertTrue(c.revision > 0) } @Test fun installerWrappersInstallHere() { diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install b/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install index 681cf4031b..0066f85577 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-msi-install @@ -51,6 +51,11 @@ SYSTEM_PROPERTIES = { "UILevel": "2", "INSTALLLEVEL": "1", "ProgramFilesFolder": None, "VersionMsi": "5.00", } +NATIVE_ARCHITECTURE = {"intel": "x86", "x64": "AMD64", "amd64": "AMD64", "arm64": "ARM64"} +ARCHITECTURE_VALUE = ("system\\currentcontrolset\\control\\session manager\\environment", "processor_architecture") +REG_LOCATOR_RAW = 2 +REG_ROOT_LOCAL_MACHINE = 2 + COMPONENT_64BIT = 0x100 FILE_NONCOMPRESSED = 0x2000 SET_PROPERTY, SET_DIRECTORY, ERROR_ACTION = 51, 35, 19 @@ -410,6 +415,18 @@ class Installer: return text + def run_app_search(self): + locators = {row["Signature_"]: row for row in self.pkg.table("RegLocator")} + architecture = NATIVE_ARCHITECTURE.get(self.platform) + for row in self.pkg.table("AppSearch"): + locator = locators.get(row["Signature_"]) + if locator is None or architecture is None: + continue + if to_int(locator.get("Root")) != REG_ROOT_LOCAL_MACHINE or to_int(locator.get("Type")) & 0xF != REG_LOCATOR_RAW: + continue + if (locator.get("Key", "").rstrip("\\").casefold(), locator.get("Name", "").casefold()) == ARCHITECTURE_VALUE: + self.props[row["Property"]] = architecture + def run_set_actions(self): actions = {row["Action"]: row for row in self.pkg.table("CustomAction")} sequence = {} @@ -704,6 +721,7 @@ class Installer: def install(self): self.span.report(0.0, "reading %s" % (self.pkg.summary.get("subject") or Path(self.pkg.path).name)) + self.run_app_search() self.run_set_actions() self.select() with tempfile.TemporaryDirectory(dir=str(self.out.parent), prefix=".msi-") as work: @@ -865,13 +883,9 @@ def choose_packages(found, root): names = [entry.name.lower() for entry in top] if any("full" in name for name in names) and any("_core" in name or "_extended" in name for name in names): top = [entry for entry in top if not ("_core" in entry.name.lower() or "_extended" in entry.name.lower())] - chosen = [] - for entry in top: - template = Package(entry).summary.get("template", "").split(";")[0].strip().lower() - if template in SKIP_PLATFORMS: - continue - chosen.append(entry) - return chosen + platforms = [(entry, Package(entry).summary.get("template", "").split(";")[0].strip().lower()) for entry in top] + native = [entry for entry, template in platforms if template not in SKIP_PLATFORMS] + return native or top def install_wrapper(path, out): @@ -901,6 +915,8 @@ def install_wrapper(path, out): for note in result["notes"]: if note not in total["notes"]: total["notes"].append(note) + if not total["packages"]: + raise MsiError("%s installs nothing here" % path.name) total["how"] = how return total diff --git a/tools/tests/test_msi_install.py b/tools/tests/test_msi_install.py index 60d8fc8df4..153c699cbf 100644 --- a/tools/tests/test_msi_install.py +++ b/tools/tests/test_msi_install.py @@ -33,6 +33,62 @@ def installer(tables, out="/tmp/unused", summary=None): return MSI["Installer"]("fake.msi", out, FakePackage(tables, summary)) +class ChoosePackagesTest(unittest.TestCase): + + def choose(self, platforms): + class Stub: + def __init__(self, path): + self.summary = {"template": platforms[Path(path).name] + ";1033"} + + root = Path(tempfile.mkdtemp()) + found = [] + for name in platforms: + (root / name).write_bytes(b"") + found.append(root / name) + choose = MSI["choose_packages"] + previous = choose.__globals__["Package"] + choose.__globals__["Package"] = Stub + try: + return [entry.name for entry in choose(found, root)] + finally: + choose.__globals__["Package"] = previous + + def test_arm_packages_are_dropped_beside_native_ones(self): + self.assertEqual(self.choose({"a.msi": "x64", "b.msi": "Arm64", "c.msi": "Intel"}), ["a.msi", "c.msi"]) + + def test_an_all_arm64_bundle_is_kept(self): + self.assertEqual(self.choose({"min.msi": "Arm64", "extra.msi": "Arm64"}), ["min.msi", "extra.msi"]) + + +class InstallWrapperTest(unittest.TestCase): + + def wrap(self, count): + wrap = MSI["install_wrapper"] + names = wrap.__globals__ + saved = {key: names[key] for key in ("unpack_installer", "packages_in", "choose_packages", "Installer")} + + class Empty: + def __init__(self, *args, **kwargs): + pass + + def install(self): + raise MSI["MsiError"]("the package installs nothing here") + + names["unpack_installer"] = lambda path, dest: "bundle" + names["packages_in"] = lambda dest: [] + names["choose_packages"] = lambda found, root: [Path("p%d.msi" % index) for index in range(count)] + names["Installer"] = Empty + root = Path(tempfile.mkdtemp()) + try: + return wrap(root / "setup.exe", root / "out") + finally: + names.update(saved) + + def test_a_bundle_whose_packages_all_install_nothing_is_rejected(self): + with self.assertRaises(MSI["MsiError"]): + self.wrap(2) + + class ToolsTest(unittest.TestCase): def test_the_tools_find_their_own_libraries(self): paths = MSI["tool_env"]()["LD_LIBRARY_PATH"].split(":") @@ -118,6 +174,39 @@ class LayoutTest(unittest.TestCase): inst.select() self.assertEqual(inst.included_components, {"Up", "Wide"}) + def architecture_package(self, platform, key="SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", name="PROCESSOR_ARCHITECTURE"): + return installer({ + "Feature": rows("Feature Feature_Parent Level", ("Main", "", "1")), + "AppSearch": rows("Property Signature_", ("ARM64CHECK", "arch"), ("OTHER", "unrelated")), + "RegLocator": rows("Signature_ Root Key Name Type", + ("arch", "2", key, name, "2"), + ("unrelated", "2", "SOFTWARE\\Vendor", "Path", "2")), + "Component": rows("Component Directory_ Attributes Condition", + ("Native", "TARGETDIR", "256", 'ARM64CHECK = "ARM64"'), + ("Always", "TARGETDIR", "256", "")), + "FeatureComponents": rows("Feature_ Component_", ("Main", "Native"), ("Main", "Always")), + }, summary={"template": "%s;1033" % platform}) + + def test_the_architecture_lookup_enables_arm64_components_in_an_arm64_package(self): + inst = self.architecture_package("Arm64") + inst.run_app_search() + inst.select() + self.assertEqual(inst.included_components, {"Native", "Always"}) + self.assertNotIn("OTHER", inst.props) + + def test_the_architecture_lookup_ignores_registry_name_case(self): + inst = self.architecture_package("Arm64", "System\\CurrentControlSet\\Control\\Session Manager\\Environment\\", "Processor_Architecture") + inst.run_app_search() + inst.select() + self.assertEqual(inst.props["ARM64CHECK"], "ARM64") + self.assertEqual(inst.included_components, {"Native", "Always"}) + + def test_the_architecture_lookup_leaves_other_packages_alone(self): + inst = self.architecture_package("x64") + inst.run_app_search() + inst.select() + self.assertEqual(inst.included_components, {"Always"}) + def test_a_duplicate_onto_the_file_itself_is_skipped(self): with tempfile.TemporaryDirectory() as tmp: src = Path(tmp) / "cab" / "dotnet.exe"