51 lines
1.5 KiB
PowerShell
51 lines
1.5 KiB
PowerShell
# Default params, $Cores must be set to 0 to automatically detect core count.
|
|
Param(
|
|
[Int]$Cores = 0
|
|
)
|
|
|
|
# If $Cores param is set to 0, detect how many cores this machine has, else use $Cores
|
|
if ($Cores-ne 0) {
|
|
Write-Host "Overriding core count with $Cores."
|
|
$MaxThreads = $Cores
|
|
}
|
|
else {
|
|
$MaxThreads = (Get-WmiObject -Class Win32_Processor).NumberOfLogicalProcessors
|
|
Write-Host "Running with $MaxThreads" Cores by default.
|
|
}
|
|
|
|
# Generate a list of files to process
|
|
$files = (ls *.pwn).Name
|
|
|
|
# Set the working directory to pass in to the background job
|
|
$workdir = (pwd)
|
|
|
|
# Define the script block, used by start-job when initiating the background job. This block defines the command that will be run, along with it's parameters.
|
|
$Block = {
|
|
Param([string] $file, [string] $workdir)
|
|
& cd $workdir; .\pawncc.exe $file
|
|
}
|
|
|
|
# Remove all jobs, in case there are old ones from a failed build
|
|
Get-Job | Remove-Job
|
|
|
|
# Start the jobs. Max jobs running simultaneously defined by $MaxThreads set above.
|
|
foreach($file in $files){
|
|
While ($(Get-Job -state running).count -ge $MaxThreads){
|
|
Start-Sleep -Milliseconds 3
|
|
}
|
|
Start-Job -Scriptblock $Block -ArgumentList $file, $workdir
|
|
}
|
|
|
|
# Once last job has been started, wait for all jobs to finish.
|
|
While ($(Get-Job -State Running).count -gt 0){
|
|
start-sleep 1
|
|
}
|
|
|
|
# Get information from each job.
|
|
foreach($job in Get-Job){
|
|
$info= Receive-Job -Id ($job.Id)
|
|
}
|
|
|
|
# Remove all jobs created.
|
|
Get-Job | Remove-Job
|