Browse Source

Exclude executables when running heat

This allows for fine-grained control of our executables later on.

Contributes to CURA-9157
Jelle Spijker 2 years ago
parent
commit
6aa6786535

+ 37 - 0
packaging/msi/ExcludeComponents.xslt

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet
+        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+        xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
+        xmlns="http://schemas.microsoft.com/wix/2006/wi"
+        version="1.0"
+        exclude-result-prefixes="xsl wix" >
+
+    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
+    <xsl:strip-space elements="*"/>
+
+    <!--
+    Find all <Component> elements with <File> elements with Source="" attributes ending in ".exe" and tag it with the "ExeToRemove" key.
+
+    <Component Id="cmpSYYKP6B1M7WSD5KLEQ7PZW4YLOPYG61L" Directory="INSTALLDIR" Guid="*">
+        <File Id="filKUS7ZRMJ0AOKDU6ATYY6IRUSR2ECPDFO" KeyPath="yes" Source="!(wix.StagingAreaPath)\ProofOfPEqualsNP.exe" />
+    </Component>
+
+    Because WiX's Heat.exe only supports XSLT 1.0 and not XSLT 2.0 we cannot use `ends-with( haystack, needle )` (e.g. `ends-with( wix:File/@Source, '.exe' )`...
+    ...but we can use this longer `substring` expression instead (see https://github.com/wixtoolset/issues/issues/5609 )
+    -->
+    <xsl:key
+            name="ExeToRemove"
+            match="wix:Component[ substring( wix:File/@Source, string-length( wix:File/@Source ) - 3 ) = '.exe' ]"
+            use="@Id"
+    /> <!-- Get the last 4 characters of a string using `substring( s, len(s) - 3 )`, it uses -3 and not -4 because XSLT uses 1-based indexes, not 0-based indexes. -->
+
+    <!-- By default, copy all elements and nodes into the output... -->
+    <xsl:template match="@*|node()">
+        <xsl:copy>
+            <xsl:apply-templates select="@*|node()"/>
+        </xsl:copy>
+    </xsl:template>
+
+    <!-- ...but if the element has the "ExeToRemove" key then don't render anything (i.e. removing it from the output) -->
+    <xsl:template match="*[ self::wix:Component or self::wix:ComponentRef ][ key( 'ExeToRemove', @Id ) ]"/>
+</xsl:stylesheet>

+ 2 - 0
packaging/msi/UltiMaker-Cura.wxs.jinja

@@ -109,6 +109,8 @@
         </DirectoryRef>
 
         <Feature Id="ProductFeature" Title="{{ app_name }}" Level="1">
+            <ComponentRef Id="CMP_UltiMaker_Cura_exe" />
+            <ComponentRef Id="CMP_CuraEngine_exe" />
             <ComponentGroupRef Id="NewFilesGroup" />
             <ComponentRef Id="CMP_Shortcuts" />
         </Feature>

+ 8 - 1
packaging/msi/create_windows_msi.py

@@ -57,17 +57,24 @@ def generate_wxs(source_path: Path, dist_path: Path, filename: Path, app_name: s
     except shutil.SameFileError:
         pass
 
+    try:
+        shutil.copy(source_loc.joinpath("packaging", "msi", "ExcludeComponents.xslt"),
+                    work_loc.joinpath("ExcludeComponents.xslt"))
+    except shutil.SameFileError:
+        pass
 
 def build(dist_path: Path, filename: str):
     dist_loc = Path(os.getcwd(), dist_path)
     work_loc = work_path(filename)
     wxs_loc = work_loc.joinpath("UltiMaker-Cura.wxs")
     heat_loc = work_loc.joinpath("HeatFile.wxs")
+    exclude_components_loc = work_loc.joinpath("ExcludeComponents.xslt")
     manageoldcuradlg_loc = work_loc.joinpath("CustomizeCuraDlg.wxs")
     build_loc = work_loc.joinpath("build_msi")
 
     heat_command = ["heat", "dir", f"{dist_loc.as_posix()}\\", "-dr", "APPLICATIONFOLDER", "-cg", "NewFilesGroup",
-                    "-gg", "-g1", "-sf", "-srd", "-var", "var.CuraDir", "-out", f"{heat_loc.as_posix()}"]
+                    "-gg", "-g1", "-sf", "-srd", "-var", "var.CuraDir", "-t", f"{exclude_components_loc.as_posix()}",
+                    "-out", f"{heat_loc.as_posix()}"]
     subprocess.call(heat_command)
 
     build_command = ["candle", "-arch", "x64", f"-dCuraDir={dist_loc}\\", "-out", f"{build_loc.as_posix()}\\",