Commenting for clarity
This commit is contained in:
parent
9eaf30bbf9
commit
b9d529161c
23
compile.ps1
23
compile.ps1
@ -1,7 +1,9 @@
|
||||
Param(
|
||||
# Default params, if $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
|
||||
@ -11,29 +13,38 @@ else {
|
||||
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
|
||||
|
||||
#Remove all jobs, in case there are old ones from a failed build
|
||||
Get-Job | Remove-Job
|
||||
#Start the jobs. Max 4 jobs running simultaneously.
|
||||
|
||||
#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
|
||||
}
|
||||
#Wait for all jobs to finish.
|
||||
|
||||
#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
|
||||
Get-Job | Remove-Job
|
||||
|
Loading…
x
Reference in New Issue
Block a user