From ec8ab6d6880781bf262f9faeb7fd1e858913b9ed Mon Sep 17 00:00:00 2001 From: Twangboy Date: Thu, 9 Mar 2023 09:58:02 -0700 Subject: [PATCH] Timestamp files to match git commit --- pkg/windows/msi/build_pkg.ps1 | 76 ++++++++++++++++++++++++++++++++++ pkg/windows/nsis/build_pkg.ps1 | 64 ++++++++++++++++++++++++++++ pkg/windows/prep_salt.ps1 | 64 ++++++++++++++++++++++++---- 3 files changed, 197 insertions(+), 7 deletions(-) diff --git a/pkg/windows/msi/build_pkg.ps1 b/pkg/windows/msi/build_pkg.ps1 index 37fdd5f3483..f1b453f5143 100644 --- a/pkg/windows/msi/build_pkg.ps1 +++ b/pkg/windows/msi/build_pkg.ps1 @@ -263,6 +263,82 @@ Write-Host "Packaging *.dll's to *.CA.dll: " -NoNewline "$SCRIPT_DIR\CustomAction01\CustomAction.config" > build.tmp CheckExitCode +#------------------------------------------------------------------------------- +# Remove compiled files +#------------------------------------------------------------------------------- +# We have to do this again because we use the Relenv Python to get the build +# architecture. This recreates some of the pycache files that were removed +# in the prep_salt script +Write-Host "Removing __pycache__ directories: " -NoNewline +$found = Get-ChildItem -Path "$BUILDENV_DIR" -Filter "__pycache__" -Recurse +$found | ForEach-Object { + Remove-Item -Path "$($_.FullName)" -Recurse -Force + if ( Test-Path -Path "$($_.FullName)" ) { + Write-Result "Failed" -ForegroundColor Red + Write-Host "Failed to remove: $($_.FullName)" + exit 1 + } +} +Write-Result "Success" -ForegroundColor Green + +# If we try to remove *.pyc with the same Get-ChildItem that we used to remove +# __pycache__ directories, it won't be able to find them because they are no +# longer present +# This probably won't find any *.pyc files, but just in case +$remove = "*.pyc", + "*.chm" +$remove | ForEach-Object { + Write-Host "Removing unneeded $_ files: " -NoNewline + $found = Get-ChildItem -Path "$BUILDENV_DIR" -Filter $_ -Recurse + $found | ForEach-Object { + Remove-Item -Path "$($_.FullName)" -Recurse -Force + if ( Test-Path -Path "$($_.FullName)" ) { + Write-Result "Failed" -ForegroundColor Red + Write-Host "Failed to remove: $($_.FullName)" + exit 1 + } + } + Write-Result "Success" -ForegroundColor Green +} + +#------------------------------------------------------------------------------- +# Set timestamps on Files +#------------------------------------------------------------------------------- +# We're doing this on the dlls that were created abive + +Write-Host "Getting commit time stamp: " -NoNewline +[DateTime]$origin = "1970-01-01 00:00:00" +$hash_time = $(git show -s --format=%at) +$time_stamp = $origin.AddSeconds($hash_time) +if ( $hash_time ) { + Write-Result "Success" -ForegroundColor Green +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +Write-Host "Setting time stamp on all files: " -NoNewline +$found = Get-ChildItem -Path $BUILDENV_DIR -Recurse +$found | ForEach-Object { + $_.CreationTime = $time_stamp + $_.LastAccessTime = $time_stamp + $_.LastWriteTime = $time_stamp +} +Write-Result "Success" -ForegroundColor Green + +Write-Host "Setting time stamp on installer dlls: " -NoNewline +$found = Get-ChildItem -Path $SCRIPT_DIR -Filter "*.dll" -Recurse +$found | ForEach-Object { + $_.CreationTime = $time_stamp + $_.LastAccessTime = $time_stamp + $_.LastWriteTime = $time_stamp +} +Write-Result "Success" -ForegroundColor Green + +#------------------------------------------------------------------------------- +# Let's start building the MSI +#------------------------------------------------------------------------------- + # move conf folder up one dir because it must not be discovered twice and xslt is difficult Write-Host "Remove configs from discovery: " -NoNewline Move-Item -Path "$DISCOVER_CONFDIR" ` diff --git a/pkg/windows/nsis/build_pkg.ps1 b/pkg/windows/nsis/build_pkg.ps1 index 980b6956e9f..ef402d23f27 100644 --- a/pkg/windows/nsis/build_pkg.ps1 +++ b/pkg/windows/nsis/build_pkg.ps1 @@ -142,6 +142,70 @@ if ( Test-Path -Path "$INSTALLER_DIR\salt.ico" ) { exit 1 } +#------------------------------------------------------------------------------- +# Remove compiled files +#------------------------------------------------------------------------------- +# We have to do this again because we use the Relenv Python to get the build +# architecture. This recreates some of the pycache files that were removed +# in the prep_salt script +Write-Host "Removing __pycache__ directories: " -NoNewline +$found = Get-ChildItem -Path "$BUILDENV_DIR" -Filter "__pycache__" -Recurse +$found | ForEach-Object { + Remove-Item -Path "$($_.FullName)" -Recurse -Force + if ( Test-Path -Path "$($_.FullName)" ) { + Write-Result "Failed" -ForegroundColor Red + Write-Host "Failed to remove: $($_.FullName)" + exit 1 + } +} +Write-Result "Success" -ForegroundColor Green + +# If we try to remove *.pyc with the same Get-ChildItem that we used to remove +# __pycache__ directories, it won't be able to find them because they are no +# longer present +# This probably won't find any *.pyc files, but just in case +$remove = "*.pyc", +"*.chm" +$remove | ForEach-Object { + Write-Host "Removing unneeded $_ files: " -NoNewline + $found = Get-ChildItem -Path "$BUILDENV_DIR" -Filter $_ -Recurse + $found | ForEach-Object { + Remove-Item -Path "$($_.FullName)" -Recurse -Force + if ( Test-Path -Path "$($_.FullName)" ) { + Write-Result "Failed" -ForegroundColor Red + Write-Host "Failed to remove: $($_.FullName)" + exit 1 + } + } + Write-Result "Success" -ForegroundColor Green +} + +#------------------------------------------------------------------------------- +# Set timestamps on Files +#------------------------------------------------------------------------------- + +# We're doing this again in this script because we use python above to get the +# build architecture and that adds back some __pycache__ and *.pyc files +Write-Host "Getting commit time stamp: " -NoNewline +[DateTime]$origin = "1970-01-01 00:00:00" +$hash_time = $(git show -s --format=%at) +$time_stamp = $origin.AddSeconds($hash_time) +if ( $hash_time ) { + Write-Result "Success" -ForegroundColor Green +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +Write-Host "Setting time stamp on all files: " -NoNewline +$found = Get-ChildItem -Path $BUILDENV_DIR -Recurse +$found | ForEach-Object { + $_.CreationTime = $time_stamp + $_.LastAccessTime = $time_stamp + $_.LastWriteTime = $time_stamp +} +Write-Result "Success" -ForegroundColor Green + #------------------------------------------------------------------------------- # Build the Installer #------------------------------------------------------------------------------- diff --git a/pkg/windows/prep_salt.ps1 b/pkg/windows/prep_salt.ps1 index 85c5bc4c813..a56af4075b8 100644 --- a/pkg/windows/prep_salt.ps1 +++ b/pkg/windows/prep_salt.ps1 @@ -467,20 +467,70 @@ $states | ForEach-Object { } Write-Result "Success" -ForegroundColor Green -Write-Host "Removing unneeded files (.pyc, .chm): " -NoNewline -$remove = "__pycache__", - "*.pyc", +Write-Host "Removing __pycache__ directories: " -NoNewline +$found = Get-ChildItem -Path "$BUILD_DIR" -Filter "__pycache__" -Recurse +$found | ForEach-Object { + Remove-Item -Path "$($_.FullName)" -Recurse -Force + if ( Test-Path -Path "$($_.FullName)" ) { + Write-Result "Failed" -ForegroundColor Red + Write-Host "Failed to remove: $($_.FullName)" + exit 1 + } +} +Write-Result "Success" -ForegroundColor Green + +# If we try to remove *.pyc with the same Get-ChildItem that we used to remove +# __pycache__ directories, it won't be able to find them because they are no +# longer present +# This probably won't find any *.pyc files, but just in case +$remove = "*.pyc", "*.chm" $remove | ForEach-Object { - $found = Get-ChildItem -Path "$BUILD_DIR\$_" -Recurse + Write-Host "Removing unneeded $_ files: " -NoNewline + $found = Get-ChildItem -Path "$BUILD_DIR" -Filter $_ -Recurse $found | ForEach-Object { - Remove-Item -Path "$_" -Recurse -Force - if ( Test-Path -Path $_ ) { + Remove-Item -Path "$($_.FullName)" -Recurse -Force + if ( Test-Path -Path "$($_.FullName)" ) { Write-Result "Failed" -ForegroundColor Red - Write-Host "Failed to remove: $_" + Write-Host "Failed to remove: $($_.FullName)" exit 1 } } + Write-Result "Success" -ForegroundColor Green +} + +#------------------------------------------------------------------------------- +# Set timestamps on Files +#------------------------------------------------------------------------------- + +# We're doing this again in this script because we use python above to get the +# build architecture and that adds back some __pycache__ and *.pyc files +Write-Host "Getting commit time stamp: " -NoNewline +[DateTime]$origin = "1970-01-01 00:00:00" +$hash_time = $(git show -s --format=%at) +$time_stamp = $origin.AddSeconds($hash_time) +if ( $hash_time ) { + Write-Result "Success" -ForegroundColor Green +} else { + Write-Result "Failed" -ForegroundColor Red + exit 1 +} + +Write-Host "Setting time stamp on all salt files: " -NoNewline +$found = Get-ChildItem -Path $BUILD_DIR -Recurse +$found | ForEach-Object { + $_.CreationTime = $time_stamp + $_.LastAccessTime = $time_stamp + $_.LastWriteTime = $time_stamp +} +Write-Result "Success" -ForegroundColor Green + +Write-Host "Setting time stamp on all prereq files: " -NoNewline +$found = Get-ChildItem -Path $PREREQ_DIR -Recurse +$found | ForEach-Object { + $_.CreationTime = $time_stamp + $_.LastAccessTime = $time_stamp + $_.LastWriteTime = $time_stamp } Write-Result "Success" -ForegroundColor Green