Skip to content

Commit

Permalink
C#: Automatically generate version defines
Browse files Browse the repository at this point in the history
(cherry picked from commit fe7c27b)
  • Loading branch information
RedworkDE authored and akien-mga committed Jul 5, 2023
1 parent 529a55b commit ce5c615
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 15 additions & 1 deletion modules/mono/build_scripts/build_assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,29 @@ def generate_sdk_package_versions():
version_status = version_status[:pos] + "." + version_status[pos:]
version_str += "-" + version_status

import version

version_defines = (
[
f"GODOT{version.major}",
f"GODOT{version.major}_{version.minor}",
f"GODOT{version.major}_{version.minor}_{version.patch}",
]
+ [f"GODOT{v}_OR_GREATER" for v in range(4, version.major + 1)]
+ [f"GODOT{version.major}_{v}_OR_GREATER" for v in range(0, version.minor + 1)]
+ [f"GODOT{version.major}_{version.minor}_{v}_OR_GREATER" for v in range(0, version.patch + 1)]
)

props = """<Project>
<PropertyGroup>
<PackageVersion_GodotSharp>{0}</PackageVersion_GodotSharp>
<PackageVersion_Godot_NET_Sdk>{0}</PackageVersion_Godot_NET_Sdk>
<PackageVersion_Godot_SourceGenerators>{0}</PackageVersion_Godot_SourceGenerators>
<GodotVersionConstants>{1}</GodotVersionConstants>
</PropertyGroup>
</Project>
""".format(
version_str
version_str, ";".join(version_defines)
)

# We write in ../SdkPackageVersions.props.
Expand Down
13 changes: 3 additions & 10 deletions modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,8 @@

<!-- Godot DefineConstants. -->
<PropertyGroup>
<!-- Define constants to identify Godot builds and versions. -->
<GodotDefineConstants>
GODOT;
GODOT4;GODOT4_OR_GREATER;
GODOT4_1;GODOT4_1_OR_GREATER;GODOT4_0_OR_GREATER;
GODOT4_1_0;GODOT4_1_0_OR_GREATER;
</GodotDefineConstants>
<!-- Ensure the define constants don't contain whitespace (see https://github.com/dotnet/roslyn/issues/58391). -->
<GodotDefineConstants>$(GodotDefineConstants.Replace('%0A','').Replace('%0D','').Replace('%09','').Replace(' ',''))</GodotDefineConstants>
<!-- Define constants to identify Godot builds. -->
<GodotDefineConstants>GODOT</GodotDefineConstants>

<!--
Define constant to determine the target Godot platform. This includes the
Expand All @@ -97,7 +90,7 @@
<GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'ios' ">GODOT_IPHONE;GODOT_IOS;GODOT_MOBILE</GodotPlatformConstants>
<GodotPlatformConstants Condition=" '$(GodotTargetPlatform)' == 'web' ">GODOT_JAVASCRIPT;GODOT_HTML5;GODOT_WASM;GODOT_WEB</GodotPlatformConstants>

<GodotDefineConstants>$(GodotDefineConstants);$(GodotPlatformConstants)</GodotDefineConstants>
<GodotDefineConstants>$(GodotDefineConstants);$(GodotPlatformConstants);$(GodotVersionConstants)</GodotDefineConstants>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit ce5c615

Please sign in to comment.