[Libreoffice-commits] core.git: solenv/bin

David Ostrovsky david at ostrovsky.org
Wed Feb 1 18:08:15 UTC 2017


 solenv/bin/modules/installer.pm                   |   26 ++++++++-
 solenv/bin/modules/installer/globals.pm           |    1 
 solenv/bin/modules/installer/windows/directory.pm |   62 ++++++++++++++++++++++
 solenv/bin/modules/installer/windows/idtglobal.pm |   25 ++++++++
 solenv/bin/modules/installer/windows/update.pm    |   28 +++++++++
 5 files changed, 141 insertions(+), 1 deletion(-)

New commits:
commit 30473907a565764eb35a19051dc0d52704cf7bb7
Author: David Ostrovsky <david at ostrovsky.org>
Date:   Sat Jan 21 11:44:33 2017 +0100

    tdf#105311 VC++ Runtime installed in wrong directory
    
    Starting from MSVC 14.0, the directory table layout of VC++ Runtime merge
    module changed. As consequence, all MSI produced with newer compilers,
    including MSVC 15.0 (aka VS 2017) are broken in term that the VC++
    Runtime DLLs are installed in the wrong directory, e.g.: C:\System64.
    
    According to the specification for merging merge module (msm), see:
    "Authoring Merge Module Directory Tables": [1], custom action 51 (set
    property) must be emitted for every directory name in the merge module
    directory table if the directory name is starting with the standard
    directory name.
    
    Quoting it here:
    
    "
    When a predefined directory is included in a merge module, the merge
    tool automatically adds a Custom Action Type 51 to the target database.
    The merge module author must ensure that a CustomAction table is also
    included. The CustomAction table may be empty, but this table is required
    to exist in the target database and ensures that the modified predefined
    directories are written to the correct locations. For example, when a
    system directory is included in a merge module, the merge module author
    must ensure that a Custom Action table exists.
    
    Note that the matching algorithm for the generation of these type 51
    custom actions only checks that the directory name begins with one of
    the predefined SystemFolder properties. It does not verify that the
    directory name exactly equals the directory property. Any directory
    beginning with one of these standard folder names gets a type 51 custom
    action, even if the rest of the name is not a GUID. Authors need to take
    care that this does not generate false positive matches, and unintended
    custom action generation, on derivative primary keys that begin with one
    of the SystemFolder properties."
    
    Rectify the problem by analyzing the directory table from the merge
    module, checking whether the directory name starts with the standard
    prefix name and if it is the case, emitting custom action 51 to set this
    variable to the standard directory name.
    
    Implementation details:
    
    We use the existing facility for emitting the custom action table events
    including referencing them in the corresponding sequence tables. Given
    that the specification above doesn't mention what sequence table should
    be referencing this emitted custom action, we reversed engineer this
    information from WiX toolkit. Merging the VC++ CRT module with WiX
    toolkit and investigating the resulting MSI with Orca MSI reader, reveals
    that these sequence tables were referencing from these sequence tables:
    
    * AdminExecuteSequence
    * AdminUISequence
    * AdvtExecuteSequence
    * InstallExecuteSequence
    * InstallUISequence
    
    Replicate this behaviour here as well. Note, though, that custom actions
    are generally not referenced in AdminUISequence and AdvtExecuteSequence
    tables in LibreOffice MSI building tool chain.
    
    Rendering of the custom action is achieved by programmatic emulation of
    custom action in SCP module. Consider this similar SCP module based
    action:
    
      Name = "MigrateInstallPath";
      Typ = "321";
      Source = "shlxtmsi.dll";
      Target = "MigrateInstallPath";
      Inbinarytable = 1;
      Assignment1 = ("InstallExecuteSequence", "", "CostInitialize");
      Assignment2 = ("InstallUISequence", "", "CostInitialize");
    
    We instantiate the following data structure to emit custom action
    System64Folder.3CFBED52_9B44_3A4D_953C_90E456671BA1:
    
      Name = "System64Folder.3CFBED52_9B44_3A4D_953C_90E456671BA1"
      Typ = "51"
      Source = "System64Folder.3CFBED52_9B44_3A4D_953C_90E456671BA1"
      Target = "[System64Folder]"
      Styles = "NO_FILES"
      Assignment1 = ("AdminExecuteSequence", "", "CostInitialize")
      Assignment2 = ("InstallExecuteSequence", "", "CostInitialize")
      Assignment3 = ("InstallUISequence", "", "CostInitialize")
    
    [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa367787%28v=vs.85%29.aspx
    
    Change-Id: I2fbd37ff63298d99b2ba1b6afe6e875f56d8e378
    Reviewed-on: https://gerrit.libreoffice.org/33366
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: David Ostrovsky <david at ostrovsky.org>

diff --git a/solenv/bin/modules/installer.pm b/solenv/bin/modules/installer.pm
index 485a508..1acac03 100644
--- a/solenv/bin/modules/installer.pm
+++ b/solenv/bin/modules/installer.pm
@@ -518,9 +518,15 @@ sub run {
                 if ( $installer::globals::updatedatabase )
                 {
                     ($uniquefilename, $revuniquefilename, $revshortfilename, $allupdatesequences, $allupdatecomponents, $allupdatefileorder, $allupdatecomponentorder, $shortdirname, $componentid, $componentidkeypath, $alloldproperties, $allupdatelastsequences, $allupdatediskids) = installer::windows::update::create_database_hashes($refdatabase);
-                    if ( $mergemodulesarrayref > -1 ) { installer::windows::update::readmergedatabase($mergemodulesarrayref, $languagestringref, $includepatharrayref); }
                 }
             }
+
+            # Always analyze the merge module.
+            # We need to investigate the directory table in merge module to emit
+            # custom action for directory names that start with standard prefix
+            if ( $mergemodulesarrayref > -1 ) {
+                installer::windows::update::readmergedatabase($mergemodulesarrayref, $languagestringref, $includepatharrayref);
+            }
         }
 
         ##############################################
@@ -1499,6 +1505,24 @@ sub run {
 
                 installer::windows::idtglobal::addcustomactions($languageidtdir, $windowscustomactionsarrayref, $filesinproductlanguageresolvedarrayref);
 
+                installer::logger::print_message( "... Analyze if custom action table must be patched with merge module directory names ...\n" );
+
+                my @customactions = ();
+                for my $e (keys %installer::globals::merge_directory_hash) {
+                    my $var;
+                    installer::logger::print_message( "... analyzing directory from merge module: $e\n");
+                    if (installer::windows::directory::has_standard_directory_prefix($e, \$var)) {
+                        installer::logger::print_message( "... emitting custom action to set the var $e to directory: $var\n");
+                        push(@customactions, installer::windows::idtglobal::emit_custom_action_for_standard_directory($e, $var));
+                    }
+                }
+
+                if (@customactions) {
+                    installer::logger::print_message( "... Patching custom action table with merge module directory names ...\n" );
+                    #print Dumper(@customactions);
+                    installer::windows::idtglobal::addcustomactions($languageidtdir, \@customactions, $filesinproductlanguageresolvedarrayref);
+                }
+
                 # Then the language specific msi database can be created
 
                 if ( $installer::globals::iswin || $installer::globals::packageformat eq 'msi' )
diff --git a/solenv/bin/modules/installer/globals.pm b/solenv/bin/modules/installer/globals.pm
index 5a7423a..c09b696 100644
--- a/solenv/bin/modules/installer/globals.pm
+++ b/solenv/bin/modules/installer/globals.pm
@@ -159,6 +159,7 @@ BEGIN
     %merge_media_line = ();
     %merge_allfeature_hash = ();
     %merge_alldirectory_hash = ();
+    %merge_directory_hash = ();
     %copy_msm_files = ();
     $mergefeaturecollected = 0;
     $mergedirectoriescollected = 0;
diff --git a/solenv/bin/modules/installer/windows/directory.pm b/solenv/bin/modules/installer/windows/directory.pm
index a1d6773..b29fa13 100644
--- a/solenv/bin/modules/installer/windows/directory.pm
+++ b/solenv/bin/modules/installer/windows/directory.pm
@@ -29,6 +29,36 @@ use installer::windows::msiglobal;
 # Collecting all directory trees in global hash
 ##############################################################
 
+my @msistandarddirectorynames = qw(
+   AdminToolsFolder
+   AppDataFolder
+   CommonAppDataFolder
+   CommonFiles64Folder
+   CommonFilesFolder
+   DesktopFolder
+   FavoritesFolder
+   FontsFolder
+   LocalAppDataFolder
+   MyPicturesFolder
+   NetHoodFolder
+   PersonalFolder
+   PrintHoodFolder
+   ProgramFiles64Folder
+   ProgramFilesFolder
+   ProgramMenuFolder
+   RecentFolder
+   SendToFolder
+   StartMenuFolder
+   StartupFolder
+   System16Folder
+   System64Folder
+   SystemFolder
+   TempFolder
+   TemplateFolder
+   WindowsFolder
+   WindowsVolume
+);
+
 sub collectdirectorytrees
 {
     my ( $directoryref ) = @_;
@@ -569,4 +599,36 @@ sub create_directory_table
     }
 }
 
+################################################
+# Check if the string starts with another string
+################################################
+
+sub starts_with
+{
+    my ($first, $second) = @_;
+
+    return substr($first, 0, length($second)) eq $second;
+}
+
+###############################################
+# Check if the directory prefix is a standard
+# directory name. If it is the case, then the
+# standard directory name is returned in $var.
+###############################################
+
+sub has_standard_directory_prefix
+{
+    my ($dir, $var) = @_;
+
+    for my $d (@msistandarddirectorynames) {
+        if (starts_with($dir, $d) && $dir ne $d) {
+            installer::logger::print_message("... match found: [$d]\n");
+            ${$var} = $d;
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
 1;
diff --git a/solenv/bin/modules/installer/windows/idtglobal.pm b/solenv/bin/modules/installer/windows/idtglobal.pm
index 8cbfcb2..a8b9ea6 100644
--- a/solenv/bin/modules/installer/windows/idtglobal.pm
+++ b/solenv/bin/modules/installer/windows/idtglobal.pm
@@ -1841,4 +1841,29 @@ sub setbidiattributes
     push(@installer::globals::logfileinfo, $infoline);
 }
 
+###############################################
+# Emit custom action 51 for setting standard
+# directory variable. Reference to a hash is
+# returned, represented the custom action.
+# This can be passed in to addcustomaction
+# method.
+###############################################
+
+sub emit_custom_action_for_standard_directory
+{
+    my ($dir, $var) = @_;
+    my %action = ();
+
+    $action{'Name'} = $dir;
+    $action{'Typ'} = "51";
+    $action{'Source'} = $dir;
+    $action{'Target'} = "[$var]";
+    $action{'Styles'} = "NO_FILE";
+    $action{'Assignment1'} = '("AdminExecuteSequence", "", "CostInitialize")';
+    $action{'Assignment2'} = '("InstallExecuteSequence", "", "CostInitialize")';
+    $action{'Assignment3'} = '("InstallUISequence", "", "CostInitialize")';
+
+    return \%action;
+}
+
 1;
diff --git a/solenv/bin/modules/installer/windows/update.pm b/solenv/bin/modules/installer/windows/update.pm
index 0edaaf2..45c47ed 100644
--- a/solenv/bin/modules/installer/windows/update.pm
+++ b/solenv/bin/modules/installer/windows/update.pm
@@ -183,6 +183,9 @@ sub read_all_tables_from_msidatabase
         if ( ! -f $longonefilename ) { installer::exiter::exit_program("ERROR: Could not find idt file: $longonefilename!", "read_all_tables_from_msidatabase"); }
         my $filecontent = installer::files::read_file($longonefilename);
         my $idtcontent = analyze_idt_file($filecontent);
+        if ($onefilename eq "Directory.idt") {
+            collect_directories($filecontent);
+        }
         my $key = $onefilename;
         $key =~ s/\.idt\s*$//;
         $database{$key} = $idtcontent;
@@ -406,6 +409,31 @@ sub readdatabase
     return $database;
 }
 
+#########################################################################
+# Reading the file "Directory.idt".
+#########################################################################
+
+sub collect_directories
+{
+    my ($filecontent) = @_;
+
+    for ( my $i = 0; $i <= $#{$filecontent}; $i++ )
+    {
+        if ( $i <= 2 ) { next; }                        # ignoring first three lines
+        if ( ${$filecontent}[$i] =~ /^\s*$/ ) { next; } # ignoring empty lines
+        # Format: Directory Directory_Parent    DefaultDir
+        if ( ${$filecontent}[$i] =~ /^\s*(.+?)\t(.*?)\t(.*?)\s*$/ )
+        {
+            $installer::globals::merge_directory_hash{$1} = 1;
+        }
+        else
+        {
+            my $linecount = $i + 1;
+            installer::exiter::exit_program("ERROR: Unknown line format in table \"$idtfilename\" (line $linecount) !", "collect_directories");
+        }
+    }
+}
+
 #################################################################################
 # Files can be included in merge modules. This is also important for update.
 #################################################################################


More information about the Libreoffice-commits mailing list