Просмотр исходного кода

Bundle MSVCRT with format=bundled installers

Thomas Kluyver 8 лет назад
Родитель
Сommit
768d142a90
3 измененных файлов с 34 добавлено и 70 удалено
  1. 16 0
      nsist/__init__.py
  2. 6 1
      nsist/pyapp.nsi
  3. 12 69
      nsist/pyapp_msvcrt.nsi

+ 16 - 0
nsist/__init__.py

@@ -141,6 +141,7 @@ class InstallerBuilder(object):
         # To be filled later
         self.install_files = []
         self.install_dirs = []
+        self.msvcrt_files = []
     
     _py_version_pattern = re.compile(r'\d\.\d+\.\d+$')
 
@@ -212,6 +213,20 @@ class InstallerBuilder(object):
 
         self.install_dirs.append(('Python', '$INSTDIR'))
 
+    def prepare_msvcrt(self):
+        arch = 'x64' if self.py_bitness == 64 else 'x86'
+        src = pjoin(_PKGDIR, 'msvcrt', arch)
+        dst = pjoin(self.build_dir, 'msvcrt')
+        self.msvcrt_files = sorted(os.listdir(src))
+
+        try:
+            shutil.rmtree(dst)
+        except OSError as e:
+            if e.errno != errno.ENOENT:
+                raise
+
+        shutil.copytree(src, dst)
+
     def fetch_pylauncher(self):
         """Fetch the MSI for PyLauncher (required for Python2.x).
     
@@ -448,6 +463,7 @@ if __name__ == '__main__':
 
         if self.py_format == 'bundled':
             self.fetch_python_embeddable()
+            self.prepare_msvcrt()
         else:
             self.fetch_python()
             if self.py_version < '3.3':

+ 6 - 1
nsist/pyapp.nsi

@@ -46,7 +46,8 @@ Section "!${PRODUCT_NAME}" sec_app
   SetOutPath "$INSTDIR\pkgs"
   File /r "pkgs\*.*"
   SetOutPath "$INSTDIR"
-  
+
+  [% block install_files %]
   ; Install files
   [% for destination, group in grouped_files %]
     SetOutPath "[[destination]]"
@@ -60,6 +61,7 @@ Section "!${PRODUCT_NAME}" sec_app
     SetOutPath "[[ pjoin(destination, dir) ]]"
     File /r "[[dir]]\*.*"
   [% endfor %]
+  [% endblock install_files %]
   
   [% block install_shortcuts %]
   ; Install shortcuts
@@ -127,6 +129,7 @@ Section "Uninstall"
   [% endif %]
   [% endblock uninstall_commands %]
 
+  [% block uninstall_files %]
   ; Uninstall files
   [% for file, destination in ib.install_files %]
     Delete "[[pjoin(destination, file)]]"
@@ -135,6 +138,8 @@ Section "Uninstall"
   [% for dir, destination in ib.install_dirs %]
     RMDir /r "[[pjoin(destination, dir)]]"
   [% endfor %]
+  [% endblock uninstall_files %]
+
   [% block uninstall_shortcuts %]
   ; Uninstall shortcuts
   [% if single_shortcut %]

+ 12 - 69
nsist/pyapp_msvcrt.nsi

@@ -1,71 +1,14 @@
 [% extends "pyapp.nsi" %]
 
-[% block sections %]
-!addplugindir [[ pynsist_pkg_dir ]]
-!include windowsversion.nsh
-!include x64.nsh
-
-Section "-msvcrt"
-  ${GetWindowsVersion} $R0
-
-  StrCpy $0 "--"
-
-  ${If} ${RunningX64}
-    ${If} $R0 == "8.1"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x64/Windows8.1-KB2999226-x64.msu"
-    ${ElseIf} $R0 == "8"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x64/Windows8-RT-KB2999226-x64.msu"
-    ${ElseIf} $R0 == "7"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x64/Windows6.1-KB2999226-x64.msu"
-    ${ElseIf} $R0 == "Vista"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x64/Windows6.0-KB2999226-x64.msu"
-    ${EndIf}
-  ${Else}
-    ${If} $R0 == "8.1"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x86/Windows8.1-KB2999226-x86.msu"
-    ${ElseIf} $R0 == "8"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x86/Windows8-RT-KB2999226-x86.msu"
-    ${ElseIf} $R0 == "7"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x86/Windows6.1-KB2999226-x86.msu"
-    ${ElseIf} $R0 == "Vista"
-      StrCpy $0 "https://cdn.rawgit.com/takluyver/pynsist/msvcrt-tag1/x86/Windows6.0-KB2999226-x86.msu"
-    ${EndIf}
-  ${EndIf}
-
-  IfFileExists "$SYSDIR\ucrtbase.dll" skip_msvcrt
-  StrCmp $0 "--" skip_msvcrt
-
-  DetailPrint "Need to install MSVCRT 2015. This may take a few minutes."
-  DetailPrint "Downloading $0"
-  inetc::get /RESUME "" "$0" "$INSTDIR\msvcrt.msu"
-  Pop $2
-  DetailPrint "Download finished ($2)"
-  ${If} $2 == "OK"
-    DetailPrint "Running wusa to install update package"
-    ExecWait 'wusa "$INSTDIR\msvcrt.msu" /quiet /norestart' $1
-    Delete "$INSTDIR\msvcrt.msu"
-  ${Else}
-    MessageBox MB_OK "Failed to download important update! \
-            ${PRODUCT_NAME} will not run until you install the Visual C++ \
-            redistributable for Visual Studio 2015.\
-            $\n$\nhttp://www.microsoft.com/en-us/download/details.aspx?id=48145"
-  ${EndIf}
-
-  # This WUSA exit code means a reboot is needed.
-  ${If} $1 = 0x00240005
-    SetRebootFlag true
-  ${Else}
-    IntOp $0 $1 & 0x80000000
-    ${If} $0 <> 0
-      MessageBox MB_OK "Failed to install important update! \
-            ${PRODUCT_NAME} will not run until you install the Visual C++ \
-            redistributable for Visual Studio 2015.\
-            $\n$\nhttp://www.microsoft.com/en-us/download/details.aspx?id=48145"
-    ${EndIf}
-  ${EndIf}
-
-  skip_msvcrt:
-SectionEnd
-
-[[ super() ]]
-[% endblock sections %]
+[% block install_files %]
+    [[ super() ]]
+
+    ; Install MSVCRT if it's not already on the system
+    IfFileExists "$SYSDIR\ucrtbase.dll" skip_msvcrt
+    SetOutPath $INSTDIR\Python
+    [% for file in ib.msvcrt_files %]
+    File msvcrt\[[file]]
+    [% endfor %]
+    skip_msvcrt:
+
+[% endblock %]