Skip to content

Commit cdf9325

Browse files
auto: sync standard files [skip ci]
1 parent 47e2d95 commit cdf9325

5 files changed

Lines changed: 334 additions & 1 deletion

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Evergine
3+
Copyright (c) 2025 Evergine
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<#
2+
.SYNOPSIS
3+
Evergine bindings generator script, (c) 2025 Evergine Team
4+
.DESCRIPTION
5+
This script generates bindings used in Evergine using a .NET generator
6+
It's meant to have the same behavior when executed locally as when it's executed in a CI pipeline.
7+
.PARAMETER BuildVerbosity
8+
Build verbosity level for dotnet commands
9+
.PARAMETER BuildConfiguration
10+
Build configuration (Debug/Release)
11+
.PARAMETER GeneratorProject
12+
Path to the generator .csproj file
13+
.PARAMETER GeneratorName
14+
Name of the generator (used for display and executable name)
15+
.PARAMETER TargetFramework
16+
Target framework for the generator (default: net8.0)
17+
.PARAMETER RuntimeIdentifier
18+
Runtime identifier for the generator (e.g., win-x64)
19+
.EXAMPLE
20+
.\Generate-Bindings-DotNet.ps1 -GeneratorProject "MyLibGen\MyLibGen\MyLibGen.csproj" -GeneratorName "MyLib"
21+
.LINK
22+
https://evergine.com/
23+
#>
24+
25+
param (
26+
[string]$BuildVerbosity = "normal", # Verbosity for dotnet build/publish (e.g., minimal, normal, detailed)
27+
[string]$BuildConfiguration = "Release", # Build configuration (Release/Debug)
28+
[string]$GeneratorProject = "", # Path to the generator .csproj file
29+
[string]$GeneratorName = "", # Generator name (used for display and executable name)
30+
[string]$TargetFramework = "net8.0", # Target framework for the generator (default: net8.0)
31+
[string]$RuntimeIdentifier = "win-x64", # Runtime identifier for the generator (e.g., win-x64)
32+
[switch]$TestMode # Load only functions for testing, do not execute main logic
33+
)
34+
35+
# Exported utility functions for unit testing
36+
function LogDebug($line) {
37+
Write-Host "##[debug] $line" -ForegroundColor Blue -BackgroundColor Black
38+
}
39+
40+
function Get-BuildOutputPath {
41+
param(
42+
[string]$GeneratorDir,
43+
[string]$BuildConfiguration,
44+
[string]$TargetFramework,
45+
[string]$RuntimeIdentifier
46+
)
47+
$buildPath = "$GeneratorDir\bin\$BuildConfiguration\$TargetFramework"
48+
if (-not [string]::IsNullOrWhiteSpace($RuntimeIdentifier)) {
49+
$buildPath += "\$RuntimeIdentifier"
50+
}
51+
return $buildPath
52+
}
53+
54+
function Get-ProjectNameFromPath {
55+
param([string]$ProjectPath)
56+
# Normalize separators for cross-platform compatibility
57+
$normalizedPath = $ProjectPath -replace '\\', '/'
58+
$filename = Split-Path $normalizedPath -Leaf
59+
return [System.IO.Path]::GetFileNameWithoutExtension($filename)
60+
}
61+
62+
function Test-BindingParameters {
63+
param(
64+
[Parameter(Mandatory)] [hashtable]$params
65+
)
66+
if ([string]::IsNullOrWhiteSpace($params.GeneratorProject)) { return $false }
67+
if ([string]::IsNullOrWhiteSpace($params.GeneratorName)) { return $false }
68+
# Optionally: you could validate other parameters here
69+
return $true
70+
}
71+
72+
# If in test mode, only load functions and exit
73+
if ($TestMode) {
74+
return
75+
}
76+
77+
# Validate required parameters
78+
if (-not (Test-BindingParameters @{ GeneratorProject = $GeneratorProject; GeneratorName = $GeneratorName })) {
79+
Write-Host "ERROR: GeneratorProject and GeneratorName parameters are required" -ForegroundColor Red
80+
exit 1
81+
}
82+
83+
84+
# Show variables
85+
LogDebug "############## VARIABLES ##############"
86+
LogDebug "Generator name......: $GeneratorName"
87+
LogDebug "Generator project...: $GeneratorProject"
88+
LogDebug "Build configuration.: $BuildConfiguration"
89+
LogDebug "Build verbosity.....: $BuildVerbosity"
90+
LogDebug "Target framework....: $TargetFramework"
91+
LogDebug "Runtime identifier..: $RuntimeIdentifier"
92+
LogDebug "#######################################"
93+
94+
# Validate generator project exists
95+
if (-not (Test-Path $GeneratorProject)) {
96+
LogDebug "ERROR: Generator project not found at: $GeneratorProject"
97+
exit 1
98+
}
99+
100+
# Compile generator
101+
LogDebug "START $GeneratorName generator build process"
102+
dotnet publish -v:$BuildVerbosity -p:Configuration=$BuildConfiguration $GeneratorProject
103+
if ($LASTEXITCODE -eq 0) {
104+
LogDebug "END $GeneratorName generator build process"
105+
}
106+
else {
107+
LogDebug "ERROR: $GeneratorName generator build failed"
108+
exit 1
109+
}
110+
111+
# Run generator
112+
LogDebug "START $GeneratorName binding generator process"
113+
114+
$generatorDir = Split-Path $GeneratorProject -Parent
115+
$projectName = Get-ProjectNameFromPath $GeneratorProject
116+
$buildPath = Get-BuildOutputPath $generatorDir $BuildConfiguration $TargetFramework $RuntimeIdentifier
117+
118+
Push-Location $buildPath
119+
try {
120+
& ".\publish\$projectName.exe"
121+
if ($LASTEXITCODE -eq 0) {
122+
LogDebug "END $GeneratorName binding generator process"
123+
}
124+
else {
125+
LogDebug "ERROR: $GeneratorName binding generation failed"
126+
exit 1
127+
}
128+
}
129+
finally {
130+
Pop-Location
131+
}
132+
133+
LogDebug "$GeneratorName bindings generated successfully!"
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<#
2+
.SYNOPSIS
3+
Evergine NuGet Packages generator script, (c) 2025 Evergine Team
4+
.DESCRIPTION
5+
This script generates NuGet packages for Evergine projects using dotnet pack.
6+
Supports both single and multiple project scenarios with flexible versioning.
7+
It's meant to have the same behavior when executed locally as when it's executed in a CI pipeline.
8+
.PARAMETER Version
9+
Direct version string to use for packages (used by add-ons)
10+
.PARAMETER Revision
11+
Revision number to append to date-based version (used by bindings)
12+
.PARAMETER Projects
13+
Array of .csproj paths to pack. For single project, can be a string.
14+
.PARAMETER OutputFolderBase
15+
Base folder for NuGet package output
16+
.PARAMETER BuildVerbosity
17+
dotnet verbosity level
18+
.PARAMETER BuildConfiguration
19+
Build configuration (Release, Debug, etc.)
20+
.PARAMETER IncludeSymbols
21+
Whether to include debug symbols in packages
22+
.PARAMETER SymbolsFormat
23+
Symbol package format: 'snupkg' (modern, default) or 'symbols.nupkg' (legacy)
24+
.PARAMETER HelpersPath
25+
Path to the Helpers.ps1 file. Defaults to Helpers.ps1 in the same directory as this script.
26+
.EXAMPLE
27+
# Binding style (date-based version with revision)
28+
.\Generate-NuGets-DotNet.ps1 -Revision 123 -Projects "SampleBinding\Evergine.Bindings.Sample\Evergine.Bindings.Sample.csproj"
29+
.EXAMPLE
30+
# Add-on style (direct version)
31+
.\Generate-NuGets-DotNet.ps1 -Version "3.4.22.288-local" -Projects @("Source\Evergine.SampleAddon\Evergine.SampleAddon.csproj", "Source\Evergine.SampleAddon.Editor\Evergine.SampleAddon.Editor.csproj")
32+
.EXAMPLE
33+
# Using custom helpers path
34+
.\Generate-NuGets-DotNet.ps1 -Revision 123 -Projects "test.csproj" -HelpersPath "C:\Scripts\MyHelpers.ps1"
35+
.EXAMPLE
36+
# Using legacy symbol format
37+
.\Generate-NuGets-DotNet.ps1 -Version "1.0.0" -Projects "test.csproj" -SymbolsFormat "symbols.nupkg"
38+
.LINK
39+
https://evergine.com/
40+
#>
41+
42+
param (
43+
[string]$Version,
44+
[string]$Revision,
45+
[Parameter(Mandatory = $true)]$Projects,
46+
[string]$OutputFolderBase = "nupkgs",
47+
[string]$BuildVerbosity = "normal",
48+
[string]$BuildConfiguration = "Release",
49+
[bool]$IncludeSymbols = $false,
50+
[ValidateSet("snupkg", "symbols.nupkg")]
51+
[string]$SymbolsFormat = "snupkg",
52+
[string]$HelpersPath = "$PSScriptRoot\Helpers.ps1"
53+
)
54+
55+
# Import shared helper functions
56+
if (Test-Path $HelpersPath) {
57+
. $HelpersPath
58+
}
59+
else {
60+
throw "Helpers file not found at: $HelpersPath. Please ensure Helpers.ps1 is available or specify correct path with -HelpersPath parameter."
61+
}
62+
63+
# Parameter validation
64+
if ([string]::IsNullOrEmpty($Version) -and [string]::IsNullOrEmpty($Revision)) {
65+
throw "Either -Version or -Revision parameter must be provided"
66+
}
67+
68+
if (![string]::IsNullOrEmpty($Version) -and ![string]::IsNullOrEmpty($Revision)) {
69+
throw "Cannot specify both -Version and -Revision parameters"
70+
}
71+
72+
if ($Projects -eq $null -or $Projects.Count -eq 0 -or ($Projects -is [array] -and $Projects.Length -eq 0)) {
73+
throw "Projects parameter cannot be empty"
74+
}
75+
76+
# Convert Projects to array if it's a single string
77+
if ($Projects -is [string]) {
78+
$Projects = @($Projects)
79+
}
80+
81+
# Calculate version
82+
if (![string]::IsNullOrEmpty($Revision)) {
83+
$Version = "$(Get-Date -Format "yyyy.M.d").$Revision"
84+
}
85+
86+
# Validate version format (NuGet semantic versioning)
87+
# See: https://docs.microsoft.com/en-us/nuget/concepts/package-versioning
88+
if ($Version -notmatch '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-([a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)(?:\.([a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?))*)?$') {
89+
throw "Invalid version format: '$Version'. NuGet version must follow semantic versioning (e.g., '1.0.0', '1.0.0-alpha', '1.0.0.123')."
90+
}
91+
92+
# Show variables
93+
$parameters = @{
94+
"Version" = $Version
95+
"Projects" = ($Projects -join ", ")
96+
"BuildConfiguration" = $BuildConfiguration
97+
"BuildVerbosity" = $BuildVerbosity
98+
"OutputFolderBase" = $OutputFolderBase
99+
"IncludeSymbols" = $IncludeSymbols
100+
"SymbolsFormat" = $SymbolsFormat
101+
}
102+
103+
ShowVariables $parameters
104+
105+
# Create output folder
106+
$absoluteOutputFolder = CreateOutputFolder $OutputFolderBase
107+
108+
# Generate packages
109+
LogDebug "START packaging process"
110+
111+
foreach ($projectPath in $Projects) {
112+
LogDebug "Processing project: $projectPath"
113+
114+
if (!(Test-Path $projectPath)) {
115+
throw "Project file not found: $projectPath"
116+
}
117+
118+
LogDebug "Packing $projectPath with dotnet"
119+
120+
# Build dotnet pack command with appropriate symbol format
121+
$packArgs = @(
122+
"pack", $projectPath,
123+
"--verbosity", $BuildVerbosity,
124+
"--configuration", $BuildConfiguration,
125+
"--output", $absoluteOutputFolder,
126+
"-p:PackageVersion=$Version"
127+
)
128+
129+
if ($IncludeSymbols) {
130+
if ($SymbolsFormat -eq "snupkg") {
131+
$packArgs += "-p:IncludeSymbols=true"
132+
$packArgs += "-p:SymbolPackageFormat=snupkg"
133+
}
134+
else {
135+
$packArgs += "-p:IncludeSymbols=true"
136+
}
137+
}
138+
else {
139+
$packArgs += "-p:IncludeSymbols=false"
140+
}
141+
142+
& dotnet @packArgs
143+
144+
if ($LASTEXITCODE -ne 0) {
145+
throw "dotnet pack failed for $projectPath"
146+
}
147+
}
148+
149+
LogDebug "END packaging process"
150+
LogDebug "NuGet packages generated in: $absoluteOutputFolder"

build/scripts/Helpers.ps1

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<#
2+
.SYNOPSIS
3+
Evergine shared helper functions, (c) 2025 Evergine Team
4+
.DESCRIPTION
5+
This script contains helper functions shared across different Evergine build and packaging scripts.
6+
These functions provide consistent logging, variable display, and common file operations.
7+
.EXAMPLE
8+
. scripts/common/Helpers.ps1
9+
LogDebug "Starting process"
10+
$outputPath = CreateOutputFolder "nupkgs"
11+
.LINK
12+
https://evergine.com/
13+
#>
14+
15+
# Utility function for consistent debug logging
16+
function LogDebug($line) {
17+
Write-Host "##[debug] $line" -ForegroundColor Blue -BackgroundColor Black
18+
}
19+
20+
# Display script variables in a consistent format
21+
function ShowVariables($parameters) {
22+
LogDebug "############## VARIABLES ##############"
23+
foreach ($param in $parameters.GetEnumerator()) {
24+
$paddedKey = $param.Key + (' ' * [Math]::Max(0, 20 - $param.Key.Length))
25+
$message = "${paddedKey}: $($param.Value)"
26+
LogDebug $message
27+
}
28+
LogDebug "#######################################"
29+
}
30+
31+
# Create output folder and return absolute path
32+
function CreateOutputFolder($outputFolderBase) {
33+
try {
34+
$null = New-Item -ItemType Directory -Force -Path $outputFolderBase -ErrorAction Stop
35+
Resolve-Path $outputFolderBase -ErrorAction Stop
36+
}
37+
catch {
38+
throw "Failed to create or resolve output folder: $outputFolderBase. Error: $($_.Exception.Message)"
39+
}
40+
}
41+
42+
# Display script variables in a legacy format (for backward compatibility)
43+
function ShowVariablesLegacy($version, $buildConfiguration, $buildVerbosity, $outputFolderBase) {
44+
LogDebug "############## VARIABLES ##############"
45+
LogDebug "Version.............: $version"
46+
LogDebug "Build configuration.: $buildConfiguration"
47+
LogDebug "Build verbosity.....: $buildVerbosity"
48+
LogDebug "Output folder.......: $outputFolderBase"
49+
LogDebug "#######################################"
50+
}

icon.png

3.37 KB
Loading

0 commit comments

Comments
 (0)