diff --git a/builders/ubuntu-python-builder.psm1 b/builders/ubuntu-python-builder.psm1 index 35b159c5..e7a6eb3c 100644 --- a/builders/ubuntu-python-builder.psm1 +++ b/builders/ubuntu-python-builder.psm1 @@ -30,8 +30,8 @@ class UbuntuPythonBuilder : NixPythonBuilder { $pythonBinariesLocation = $this.GetFullPythonToolcacheLocation() - ### To build Python with SO we must pass full path to lib folder to the linker - $env:LDFLAGS="-Wl,--rpath=${pythonBinariesLocation}/lib" + ### To build Python with SO, passing relative path W.r.t to the binary location. + $env:LDFLAGS="-Wl,-rpath='`$`$ORIGIN/../lib'" $configureString = "./configure" $configureString += " --prefix=$pythonBinariesLocation" $configureString += " --enable-shared" @@ -43,6 +43,7 @@ class UbuntuPythonBuilder : NixPythonBuilder { Write-Host "The passed configure options are: " Write-Host $configureString + Write-Host "LDFLAGS: $env:LDFLAGS" Execute-Command -Command $configureString } diff --git a/tests/python-tests.ps1 b/tests/python-tests.ps1 index 706a3b42..8acbd9c2 100644 --- a/tests/python-tests.ps1 +++ b/tests/python-tests.ps1 @@ -36,6 +36,12 @@ BeforeAll { return 0 } + + function moveAssets([string] $source, [string] $destination) { + $parentDestDir = Split-Path -Path $destination -Parent + New-Item -Path $parentDestDir -ItemType Directory -Force + Move-Item -Path $source -Destination $parentDestDir -Force + } } Describe "Tests" { @@ -88,6 +94,30 @@ Describe "Tests" { It "Check if shared libraries are linked correctly" { "bash ./sources/psutil-install-test.sh" | Should -ReturnZeroExitCode } + + It "Relocatable Python" { + $semversion = [semver] $Version + $pyfilename = "python$($semversion.Major).$($semversion.Minor)" + $artifactPath = Join-Path "Python" $Version | Join-Path -ChildPath $Architecture + + $relocatedPython = Join-Path $HOME "relocated_python" + $relocatedPythonTool = Join-Path -Path $relocatedPython -ChildPath $artifactPath + $relocatedFullPath = Join-Path $relocatedPythonTool "bin" | Join-Path -ChildPath $pyfilename + + # copy the current build to relocated_python + $toolCacheArtifact = Join-Path $env:RUNNER_TOOL_CACHE $artifactPath + moveAssets -source $toolCacheArtifact -destination $relocatedPythonTool + try { + # Verify that relocated Python works + $relocatedFullPath | Should -Exist + "$relocatedFullPath --version" | Should -ReturnZeroExitCode + "sudo $relocatedFullPath --version" | Should -ReturnZeroExitCode + } + finally { + # Revert the changes for other tests + moveAssets -source $relocatedPythonTool -destination $toolCacheArtifact + } + } } # Pyinstaller 3.5 does not support Python 3.8.0. Check issue https://github.com/pyinstaller/pyinstaller/issues/4311