Support custom deprecation messages in bindings generator

This commit is contained in:
2024-06-17 20:00:30 +03:00
parent 6e0dd2064a
commit e08b57e814
21 changed files with 98 additions and 43 deletions

View File

@@ -184,8 +184,20 @@ public:
/// <param name="assets">The output collection of the asset ids referenced by this asset.</param>
/// <param name="files">The output list of file paths referenced by this asset. Files might come from project Content folder (relative path is preserved in cooked game), or external location (copied into Content root folder of cooked game).</param>
virtual void GetReferences(Array<Guid, HeapAllocation>& assets, Array<String, HeapAllocation>& files) const;
// [Deprecated in v1.9]
DEPRECATED virtual void GetReferences(Array<Guid, HeapAllocation>& output) const;
/// <summary>
/// Gets the asset references. Supported only in Editor.
/// [Deprecated in v1.9]
/// </summary>
/// <remarks>
/// For some asset types (e.g. scene or prefab) it may contain invalid asset ids due to not perfect gather method,
/// which is optimized to perform scan very quickly. Before using those ids perform simple validation via Content cache API.
/// The result collection contains only 1-level-deep references (only direct ones) and is invalid if asset is not loaded.
/// Also, the output data may have duplicated asset ids or even invalid ids (Guid::Empty).
/// </remarks>
/// <param name="output">The output collection of the asset ids referenced by this asset.</param>
DEPRECATED("Use GetReferences with assets and files parameter instead") virtual void GetReferences(Array<Guid, HeapAllocation>& output) const;
/// <summary>
/// Gets the asset references. Supported only in Editor.

View File

@@ -21,7 +21,6 @@
#define ALIGN_BEGIN(_align)
#define ALIGN_END(_align) __attribute__( (aligned(_align) ) )
#define OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
#define DEPRECATED [[deprecated]]
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
@@ -53,7 +52,6 @@
#define ALIGN_BEGIN(_align)
#define ALIGN_END(_align) __attribute__( (aligned(_align) ) )
#define OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
#define DEPRECATED [[deprecated]]
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
@@ -80,7 +78,6 @@
#define ALIGN_BEGIN(_align) __declspec(align(_align))
#define ALIGN_END(_align)
#define OFFSET_OF(X, Y) offsetof(X, Y)
#define DEPRECATED __declspec(deprecated)
#undef __PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__ __FUNCSIG__
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS \
@@ -100,6 +97,11 @@
#define PACK_STRUCT(_declaration) PACK_BEGIN() _declaration PACK_END()
#define _DEPRECATED_0() [[deprecated]]
#define _DEPRECATED_1(msg) [[deprecated(msg)]]
#define _DEPRECATED(_0, _1, LASTARG, ...) LASTARG
#define DEPRECATED(...) _DEPRECATED(, ##__VA_ARGS__, _DEPRECATED_1(__VA_ARGS__), _DEPRECATED_0())
// C++ 17
#if __cplusplus >= 201703L
#define IF_CONSTEXPR constexpr

View File

@@ -64,7 +64,7 @@ public:
/// [Deprecated in v1.9]
/// </summary>
API_FIELD(Attributes="EditorOrder(1320), DefaultValue(false), EditorDisplay(\"Quality\", \"Allow CSM Blending\")")
DEPRECATED bool AllowCSMBlending = false;
DEPRECATED() bool AllowCSMBlending = false;
/// <summary>
/// Default probes cubemap resolution (use for Environment Probes, can be overriden per-actor).

View File

@@ -481,7 +481,7 @@ public:
/// <param name="translation">When the method completes, contains the translation component of the decomposed matrix.</param>
/// <remarks>This method is designed to decompose an SRT transformation matrix only.</remarks>
void Decompose(Float3& scale, Matrix3x3& rotation, Float3& translation) const;
DEPRECATED void Decompose(Float3& scale, Matrix& rotation, Float3& translation) const;
DEPRECATED("Use Decompose with 'Matrix3x3& rotation' parameter instead") void Decompose(Float3& scale, Matrix& rotation, Float3& translation) const;
public:
Matrix operator*(const float scale) const

View File

@@ -115,7 +115,7 @@ public:
/// Gets the pointer to the string or to the static empty text if string is null. Returned pointer is always non-null, but is not null-terminated.
/// [Deprecated on 26.10.2022, expires on 26.10.2024] Use GetText()
/// </summary>
DEPRECATED const T* GetNonTerminatedText() const
DEPRECATED("Use GetText instead") const T* GetNonTerminatedText() const
{
return _data ? _data : (const T*)TEXT("");
}

View File

@@ -96,7 +96,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw
/// <param name="color">The color.</param>
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
API_FUNCTION() DEPRECATED static void DrawRay(const Vector3& origin, const Vector3& direction, const Color& color = Color::White, float duration = 0.0f, bool depthTest = true);
API_FUNCTION() DEPRECATED("Use DrawRay with length parameter instead") static void DrawRay(const Vector3& origin, const Vector3& direction, const Color& color, float duration, bool depthTest);
/// <summary>
/// Draws the line in a direction.

View File

@@ -52,7 +52,7 @@ public:
/// Enables cascades splits blending for directional light shadows.
/// [Deprecated in v1.9]
/// </summary>
API_FIELD() DEPRECATED static bool AllowCSMBlending;
API_FIELD() DEPRECATED() static bool AllowCSMBlending;
/// <summary>
/// The Global SDF quality. Controls the volume texture resolution and amount of cascades to use.

View File

@@ -161,13 +161,13 @@ public:
/// The model LOD bias. Default is 0. Applied to all the objects in the shadow maps render views. Can be used to improve shadows rendering performance or increase quality.
/// [Deprecated on 26.10.2022, expires on 26.10.2024]
/// </summary>
API_FIELD() DEPRECATED int32 ShadowModelLODBias = 0;
API_FIELD() DEPRECATED() int32 ShadowModelLODBias = 0;
/// <summary>
/// The model LOD distance scale factor. Default is 1. Applied to all the objects in the shadow maps render views. Higher values increase LODs quality. Can be used to improve shadows rendering performance or increase quality.
/// [Deprecated on 26.10.2022, expires on 26.10.2024]
/// </summary>
API_FIELD() DEPRECATED float ShadowModelLODDistanceFactor = 1.0f;
API_FIELD() DEPRECATED() float ShadowModelLODDistanceFactor = 1.0f;
/// <summary>
/// Temporal Anti-Aliasing jitter frame index.

View File

@@ -164,13 +164,13 @@ public:
/// [Deprecated in v1.5]
/// </summary>
API_PROPERTY(Attributes="HideInEditor, NoSerialize, NoAnimate")
DEPRECATED const String& GetTag() const;
DEPRECATED("Use HasTag instead") const String& GetTag() const;
/// <summary>
/// Sets the name of the tag.
/// [Deprecated in v1.5]
/// </summary>
API_PROPERTY() DEPRECATED void SetTag(const StringView& value);
API_PROPERTY() DEPRECATED("Use AddTag instead") void SetTag(const StringView& value);
/// <summary>
/// Gets the actor name.

View File

@@ -160,7 +160,7 @@ public:
/// [Deprecated on 26.10.2022, expires on 26.10.2024]
/// </summary>
API_FIELD(Attributes="EditorOrder(110), DefaultValue(ShadowsCastingMode.All), EditorDisplay(\"Skinned Model\")")
DEPRECATED ShadowsCastingMode ShadowsMode = ShadowsCastingMode::All;
DEPRECATED() ShadowsCastingMode ShadowsMode = ShadowsCastingMode::All;
/// <summary>
/// The animation root motion apply target. If not specified the animated model will apply it itself.

View File

@@ -160,7 +160,7 @@ public:
/// <param name="point">The source point.</param>
/// <param name="result">The result position on the navmesh (valid only if method returns true).</param>
/// <returns>True if found valid location on the navmesh, otherwise false.</returns>
API_FUNCTION() DEPRECATED bool ProjectPoint(const Vector3& point, API_PARAM(Out) Vector3& result) const
API_FUNCTION() DEPRECATED("Use FindClosestPoint instead") bool ProjectPoint(const Vector3& point, API_PARAM(Out) Vector3& result) const
{
return FindClosestPoint(point, result);
}

View File

@@ -54,7 +54,7 @@ public:
/// <param name="point">The source point.</param>
/// <param name="result">The result position on the navmesh (valid only if method returns true).</param>
/// <returns>True if found valid location on the navmesh, otherwise false.</returns>
API_FUNCTION() DEPRECATED static bool ProjectPoint(const Vector3& point, API_PARAM(Out) Vector3& result)
API_FUNCTION() DEPRECATED("Use FindClosestPoint instead") static bool ProjectPoint(const Vector3& point, API_PARAM(Out) Vector3& result)
{
return FindClosestPoint(point, result);
}

View File

@@ -10,7 +10,7 @@ class ScriptingObject;
/// Network driver implementations enum.
/// [Deprecated in v1.3]
/// </summary>
API_ENUM(Namespace="FlaxEngine.Networking") enum class DEPRECATED NetworkDriverType
API_ENUM(Namespace="FlaxEngine.Networking") enum class DEPRECATED() NetworkDriverType
{
/// <summary>
/// Invalid network driver implementation.
@@ -36,7 +36,7 @@ API_STRUCT(Namespace="FlaxEngine.Networking") struct FLAXENGINE_API NetworkConfi
/// [Deprecated in v1.3]
/// </summary>
API_FIELD()
DEPRECATED NetworkDriverType NetworkDriverType;
DEPRECATED("Use NetworkDriver field instead") NetworkDriverType NetworkDriverType;
/// <summary>
/// The network driver instance (implements INetworkDriver) that will be used to create and manage the peer, send and receive messages.

View File

@@ -753,7 +753,7 @@ public:
/// <param name="hiddenWindow">True if start process with hidden window</param>
/// <param name="waitForEnd">True if wait for process competition</param>
/// <returns>Retrieves the termination status of the specified process. Valid only if processed ended.</returns>
API_FUNCTION() DEPRECATED static int32 StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow = false, bool waitForEnd = false);
API_FUNCTION() DEPRECATED("Use CreateProcess instead") static int32 StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow = false, bool waitForEnd = false);
/// <summary>
/// Starts a new process (runs commandline). Waits for it's end and captures its output.
@@ -763,7 +763,7 @@ public:
/// <param name="workingDir">The custom path of the working directory.</param>
/// <param name="hiddenWindow">True if start process with hidden window.</param>
/// <returns>Retrieves the termination status of the specified process. Valid only if processed ended.</returns>
API_FUNCTION() DEPRECATED static int32 RunProcess(const StringView& cmdLine, const StringView& workingDir, bool hiddenWindow = true);
API_FUNCTION() DEPRECATED("Use CreateProcess instead") static int32 RunProcess(const StringView& cmdLine, const StringView& workingDir, bool hiddenWindow = true);
/// <summary>
/// Starts a new process (runs commandline). Waits for it's end and captures its output.
@@ -774,7 +774,7 @@ public:
/// <param name="environment">The process environment variables. If null the current process environment is used.</param>
/// <param name="hiddenWindow">True if start process with hidden window.</param>
/// <returns>Retrieves the termination status of the specified process. Valid only if processed ended.</returns>
API_FUNCTION() DEPRECATED static int32 RunProcess(const StringView& cmdLine, const StringView& workingDir, const Dictionary<String, String, HeapAllocation>& environment, bool hiddenWindow = true);
API_FUNCTION() DEPRECATED("Use CreateProcess instead") static int32 RunProcess(const StringView& cmdLine, const StringView& workingDir, const Dictionary<String, String, HeapAllocation>& environment, bool hiddenWindow = true);
/// <summary>
/// Creates a new process.

View File

@@ -21,7 +21,7 @@ namespace Flax.Build.Bindings
public string Attributes;
public string[] Comment;
public bool IsInBuild;
public bool IsDeprecated;
public string DeprecatedMessage;
public TypeInfo MarshalAs;
internal bool IsInited;
internal TypedefInfo Instigator;
@@ -34,6 +34,7 @@ namespace Flax.Build.Bindings
public virtual bool IsScriptingObject => false;
public virtual bool IsPod => false;
public virtual bool SkipGeneration => IsInBuild;
public virtual bool IsDeprecated => DeprecatedMessage != null;
public FileInfo File
{
@@ -154,7 +155,7 @@ namespace Flax.Build.Bindings
BindingsGenerator.Write(writer, Comment);
BindingsGenerator.Write(writer, MarshalAs);
writer.Write(IsInBuild);
writer.Write(IsDeprecated);
BindingsGenerator.Write(writer, DeprecatedMessage);
BindingsGenerator.Write(writer, Tags);
BindingsGenerator.Write(writer, Children);
}
@@ -168,7 +169,7 @@ namespace Flax.Build.Bindings
Comment = BindingsGenerator.Read(reader, Comment);
MarshalAs = BindingsGenerator.Read(reader, MarshalAs);
IsInBuild = reader.ReadBoolean();
IsDeprecated = reader.ReadBoolean();
DeprecatedMessage = BindingsGenerator.Read(reader, DeprecatedMessage);
Tags = BindingsGenerator.Read(reader, Tags);
Children = BindingsGenerator.Read(reader, Children);

View File

@@ -829,7 +829,7 @@ namespace Flax.Build.Bindings
}
}
private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, string attributes = null, string[] comment = null, bool canUseTooltip = false, bool useUnmanaged = false, string defaultValue = null, bool isDeprecated = false, TypeInfo defaultValueType = null)
private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, string attributes = null, string[] comment = null, bool canUseTooltip = false, bool useUnmanaged = false, string defaultValue = null, string deprecatedMessage = null, TypeInfo defaultValueType = null)
{
#if AUTO_DOC_TOOLTIPS
var writeTooltip = true;
@@ -853,10 +853,15 @@ namespace Flax.Build.Bindings
// Skip boilerplate code when using debugger
//contents.Append(indent).AppendLine("[System.Diagnostics.DebuggerStepThrough]");
}
if (isDeprecated || apiTypeInfo.IsDeprecated)
if (deprecatedMessage != null || apiTypeInfo.IsDeprecated)
{
// Deprecated type
contents.Append(indent).AppendLine("[Obsolete]");
if (!string.IsNullOrEmpty(apiTypeInfo.DeprecatedMessage))
contents.Append(indent).AppendLine($"[Obsolete(\"{apiTypeInfo.DeprecatedMessage}\")]");
else if (!string.IsNullOrEmpty(deprecatedMessage))
contents.Append(indent).AppendLine($"[Obsolete(\"{deprecatedMessage}\")]");
else
contents.Append(indent).AppendLine("[Obsolete]");
}
#if AUTO_DOC_TOOLTIPS
@@ -901,12 +906,12 @@ namespace Flax.Build.Bindings
private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, bool useUnmanaged, string defaultValue = null, TypeInfo defaultValueType = null)
{
GenerateCSharpAttributes(buildData, contents, indent, apiTypeInfo, apiTypeInfo.Attributes, apiTypeInfo.Comment, true, useUnmanaged, defaultValue, false, defaultValueType);
GenerateCSharpAttributes(buildData, contents, indent, apiTypeInfo, apiTypeInfo.Attributes, apiTypeInfo.Comment, true, useUnmanaged, defaultValue, null, defaultValueType);
}
private static void GenerateCSharpAttributes(BuildData buildData, StringBuilder contents, string indent, ApiTypeInfo apiTypeInfo, MemberInfo memberInfo, bool useUnmanaged, string defaultValue = null, TypeInfo defaultValueType = null)
{
GenerateCSharpAttributes(buildData, contents, indent, apiTypeInfo, memberInfo.Attributes, memberInfo.Comment, true, useUnmanaged, defaultValue, memberInfo.IsDeprecated, defaultValueType);
GenerateCSharpAttributes(buildData, contents, indent, apiTypeInfo, memberInfo.Attributes, memberInfo.Comment, true, useUnmanaged, defaultValue, memberInfo.DeprecatedMessage, defaultValueType);
}
private static bool GenerateCSharpStructureUseDefaultInitialize(BuildData buildData, StructureInfo structureInfo)

View File

@@ -19,7 +19,7 @@ namespace Flax.Build.Bindings
partial class BindingsGenerator
{
private static readonly Dictionary<string, Type> TypeCache = new Dictionary<string, Type>();
private const int CacheVersion = 22;
private const int CacheVersion = 23;
internal static void Write(BinaryWriter writer, string e)
{

View File

@@ -589,7 +589,13 @@ namespace Flax.Build.Bindings
token = context.Tokenizer.NextToken();
if (!desc.IsDeprecated && token.Value == "DEPRECATED")
{
desc.IsDeprecated = true;
token = context.Tokenizer.NextToken();
string message = "";
if (token.Type == TokenType.LeftParent)
context.Tokenizer.SkipUntil(TokenType.RightParent, out message);
else
context.Tokenizer.PreviousToken();
desc.DeprecatedMessage = message.Trim('"');
}
else
{
@@ -698,7 +704,13 @@ namespace Flax.Build.Bindings
token = context.Tokenizer.NextToken();
if (!desc.IsDeprecated && token.Value == "DEPRECATED")
{
desc.IsDeprecated = true;
token = context.Tokenizer.NextToken();
string message = "";
if (token.Type == TokenType.LeftParent)
context.Tokenizer.SkipUntil(TokenType.RightParent, out message);
else
context.Tokenizer.PreviousToken();
desc.DeprecatedMessage = message.Trim('"');
}
else
{
@@ -797,8 +809,14 @@ namespace Flax.Build.Bindings
}
else if (!desc.IsDeprecated && token.Value == "DEPRECATED")
{
desc.IsDeprecated = true;
context.Tokenizer.NextToken();
token = context.Tokenizer.NextToken();
string message = "";
if (token.Type == TokenType.LeftParent)
{
context.Tokenizer.SkipUntil(TokenType.RightParent, out message);
context.Tokenizer.NextToken();
}
desc.DeprecatedMessage = message.Trim('"');
}
else
{
@@ -960,7 +978,7 @@ namespace Flax.Build.Bindings
propertyInfo.Getter = functionInfo;
else
propertyInfo.Setter = functionInfo;
propertyInfo.IsDeprecated |= functionInfo.IsDeprecated;
propertyInfo.DeprecatedMessage = functionInfo.DeprecatedMessage;
propertyInfo.IsHidden |= functionInfo.IsHidden;
if (propertyInfo.Getter != null && propertyInfo.Setter != null)
@@ -1025,7 +1043,13 @@ namespace Flax.Build.Bindings
token = context.Tokenizer.NextToken();
if (!desc.IsDeprecated && token.Value == "DEPRECATED")
{
desc.IsDeprecated = true;
token = context.Tokenizer.NextToken();
string message = "";
if (token.Type == TokenType.LeftParent)
context.Tokenizer.SkipUntil(TokenType.RightParent, out message);
else
context.Tokenizer.PreviousToken();
desc.DeprecatedMessage = message.Trim('"');
}
else
{
@@ -1300,8 +1324,14 @@ namespace Flax.Build.Bindings
}
else if (!desc.IsDeprecated && token.Value == "DEPRECATED")
{
desc.IsDeprecated = true;
context.Tokenizer.NextToken();
token = context.Tokenizer.NextToken();
string message = "";
if (token.Type == TokenType.LeftParent)
{
context.Tokenizer.SkipUntil(TokenType.RightParent, out message);
context.Tokenizer.NextToken();
}
desc.DeprecatedMessage = message.Trim('"');
}
else
{

View File

@@ -14,12 +14,14 @@ namespace Flax.Build.Bindings
public string[] Comment;
public bool IsStatic;
public bool IsConstexpr;
public bool IsDeprecated;
public string DeprecatedMessage;
public bool IsHidden;
public AccessLevel Access;
public string Attributes;
public Dictionary<string, string> Tags;
public virtual bool IsDeprecated => DeprecatedMessage != null;
public bool HasAttribute(string name)
{
return Attributes != null && Attributes.Contains(name);
@@ -46,7 +48,7 @@ namespace Flax.Build.Bindings
BindingsGenerator.Write(writer, Comment);
writer.Write(IsStatic);
writer.Write(IsConstexpr);
writer.Write(IsDeprecated);
BindingsGenerator.Write(writer, DeprecatedMessage);
writer.Write(IsHidden);
writer.Write((byte)Access);
BindingsGenerator.Write(writer, Attributes);
@@ -59,7 +61,7 @@ namespace Flax.Build.Bindings
Comment = BindingsGenerator.Read(reader, Comment);
IsStatic = reader.ReadBoolean();
IsConstexpr = reader.ReadBoolean();
IsDeprecated = reader.ReadBoolean();
DeprecatedMessage = BindingsGenerator.Read(reader, DeprecatedMessage);
IsHidden = reader.ReadBoolean();
Access = (AccessLevel)reader.ReadByte();
Attributes = BindingsGenerator.Read(reader, Attributes);

View File

@@ -76,7 +76,7 @@ namespace Flax.Build.Bindings
if (Comment != null && Comment.Length != 0)
typedef.Comment = Comment;
typedef.IsInBuild |= IsInBuild;
typedef.IsDeprecated |= IsDeprecated;
typedef.DeprecatedMessage = DeprecatedMessage;
if (typedef is ClassStructInfo typedefClassStruct && typedefClassStruct.IsTemplate)
{
// Inflate template type

View File

@@ -617,6 +617,9 @@ namespace Flax.Build.Platforms
commonArgs.Add(string.Format("/FU\"{0}\\platform.winmd\"", dir));
}
}
// Preprocessor conformance mode
commonArgs.Add("/Zc:preprocessor");
}
// Add preprocessor definitions