Skip to content

Commit

Permalink
Optimize installation experience on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu0629 committed Apr 24, 2024
1 parent 33b3e3c commit d21c93f
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 25 deletions.
28 changes: 28 additions & 0 deletions bin/WiX/LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) .NET Foundation and contributors.
This software is released under the Microsoft Reciprocal License (MS-RL) (the "License"); you may not use the software except in compliance with the License.

The text of the Microsoft Reciprocal License (MS-RL) can be found online at:
http://opensource.org/licenses/ms-rl


Microsoft Reciprocal License (MS-RL)

This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.

1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.

2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.

3. Conditions and Limitations
(A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
(B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
(D) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
(E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
(F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
Binary file added bin/WiX/WixDependencyExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixDifxAppExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixDirectXExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixFirewallExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixGamingExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixHttpExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixIIsExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixNetFxExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixSqlExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixUIExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixUtilExtension.dll
Binary file not shown.
Binary file added bin/WiX/WixVSExtension.dll
Binary file not shown.
Binary file added bin/WiX/dark.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions bin/WiX/dark.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->


<configuration>
<appSettings>
<add key="extensions" value="WixDifxAppExtension;WixDependencyExtension;WixDirectXExtension;WixFirewallExtension;WixGamingExtension;WixHttpExtension;WixIIsExtension;WixNetFxExtension;WixSqlExtension;WixUIExtension;WixUtilExtension;WixVSExtension" />
</appSettings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
Binary file added bin/WiX/winterop.dll
Binary file not shown.
Binary file added bin/WiX/wix.dll
Binary file not shown.
122 changes: 97 additions & 25 deletions lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ function checkIsReleaseVersion(version)
end
return true
end

function windowsCompile(ctx)
local sdkInfo = ctx.sdkInfo['python']
local path = sdkInfo.path
local version = sdkInfo.version
local url, filename = checkAvailableReleaseForWindows(version)
local url, filename = getReleaseForWindows(version)

--- Attention system difference
local qInstallFile = path .. "\\" .. filename
local qInstallLog = path .. "\\install.log"
local qInstallPath = path
local msiPath = path .. '\\AttachedContainer'

print("Downloading installer")
-- download
print("Downloading installer...")
print("from:\t" .. url)
print("to:\t" .. qInstallFile)
local resp, err = http.get({
Expand All @@ -65,27 +67,97 @@ function windowsCompile(ctx)
print("size:\t" .. size .. " bytes")
end

--local exitCode = os.execute('msiexec /quiet /a "' .. qInstallFile .. '" TargetDir="' .. qInstallPath .. '"')
print("Installing python, please wait patiently for a while, about two minutes.")
local exitCode = os.execute(qInstallFile .. ' /quiet InstallAllUsers=0 PrependPath=0 TargetDir=' .. qInstallPath .. ' /log ' .. qInstallLog)
if exitCode ~= 0 then
-- show install log
local logFile = io.open(qInstallLog, "r")
if logFile then
local contents = logFile:read("*a")
logFile:close()
print("=====================================")
print(qInstallLog)
print(contents)
print("=====================================")
print("Please uninstall python manually and try again.")
-- Extract
print("Extracting installer...")
local wixBin = RUNTIME.pluginDirPath .. '\\bin\\WiX\\dark.exe'
local command = wixBin .. " -x " .. qInstallPath .. '\\ ' .. qInstallFile
local extractExitCode = os.execute(command)
if extractExitCode ~= 0 then
error("Extract failed")
end

-- Cleaning up ...
print("Cleaning installer...")
os.remove(qInstallFile)
local files = {'appendpath.msi', 'launcher.msi', 'path.msi', 'pip.msi'}
for _, file in ipairs(files) do
os.remove(msiPath .. '\\' .. file)
end

-- Install msi
print("Installing python...")
local files = io.popen("dir /b " .. msiPath):lines()
for file in files do
if file:match("%.msi$") then
local command = "msiexec /quiet /a " .. msiPath .. '\\' .. file .. " TargetDir=" .. qInstallPath
local MsiExitCode = os.execute(command)
if MsiExitCode ~= 0 then
error("Install msi failed: " .. file)
end
os.remove(qInstallPath .. '\\' .. file)
end
error("Error installing python, exitCode=" .. exitCode )
else
os.remove(qInstallLog)
os.remove(qInstallFile)
end

-- Define paths for executables based on installation path
local pythonExePath = qInstallPath .. "\\python.exe"
local pythonwExePath = qInstallPath .. "\\pythonw.exe"
local venvlauncherExePath = qInstallPath .. "\\Lib\\venv\\scripts\\nt\\python.exe"

-- Split the version string into major and minor parts
local major, minor = 3, 12

local pattern = "(%d+)%.(%d+)"
local major, minor = string.match(version, pattern)
local majorMinor = major .. minor
local majorDotMinor = major .. "." .. minor

-- Copy Python executables with versioned names
-- python.exe
local files = {qInstallPath .. "\\python" .. major .. ".exe", qInstallPath .. "\\python" .. majorMinor .. ".exe",
qInstallPath .. "\\python" .. majorDotMinor .. ".exe"}
for _, file in ipairs(files) do
local command = 'copy /y ' .. pythonExePath .. ' ' .. file
os.execute(command)
end

-- pythonw.exe
local files = {qInstallPath .. "\\pythonw" .. major .. ".exe", qInstallPath .. "\\pythonw" .. majorMinor .. ".exe",
qInstallPath .. "\\pythonw" .. majorDotMinor .. ".exe"}
for _, file in ipairs(files) do
local command = 'copy /y ' .. pythonwExePath .. ' ' .. file
os.execute(command)
end

-- Check if venvlauncher exists
local file = io.open(venvlauncherExePath, "r")
if file then
io.close(file)
-- python.exe
local files = {qInstallPath .. "\\Lib\\venv\\scripts\\nt\\python" .. major .. ".exe",
qInstallPath .. "\\Lib\\venv\\scripts\\nt\\python" .. majorMinor .. ".exe",
qInstallPath .. "\\Lib\\venv\\scripts\\nt\\python" .. majorDotMinor .. ".exe",
qInstallPath .. "\\Lib\\venv\\scripts\\nt\\pythonw" .. major .. ".exe",
qInstallPath .. "\\Lib\\venv\\scripts\\nt\\pythonw" .. majorMinor .. ".exe",
qInstallPath .. "\\Lib\\venv\\scripts\\nt\\pythonw" .. majorDotMinor .. ".exe"}
for _, file in ipairs(files) do
local command = 'copy /y ' .. venvlauncherExePath .. ' ' .. file
os.execute(command)
end
end

print("Installing pip...")
local ensurepipPath = qInstallPath .. "\\Lib\\ensurepip\\__init__.py"
local file = io.open(ensurepipPath, "r")
if file then
local command = qInstallPath .. '\\python -E -s -m ensurepip -U --default-pip'
local exitCode = os.execute(command)
if exitCode ~= 0 then
error("error installing pip. exitCode=" .. exitCode)
end
end

end

function linuxCompile(ctx)
local sdkInfo = ctx.sdkInfo['python']
local path = sdkInfo.path
Expand All @@ -109,7 +181,7 @@ function linuxCompile(ctx)
error("remove build tool failed")
end
end
function checkAvailableReleaseForWindows(version)
function getReleaseForWindows(version)
local archType = RUNTIME.archType
if archType == "386" then
archType = ""
Expand Down Expand Up @@ -147,13 +219,13 @@ function parseVersion()
if compare_versions(vn, "3.5.0") >= 0 then
table.insert(result, {
version = string.sub(href, 1, -2),
note = "",
note = ""
})
end
else
table.insert(result, {
version = vn,
note = "",
note = ""
})
end
end
Expand Down

0 comments on commit d21c93f

Please sign in to comment.