ubisoft / Sharpmake

Sharpmake is an open-source C#-based solution for generating project definition files, such as Visual Studio projects and solutions, GNU makefiles, Xcode projects, etc.
Apache License 2.0
922 stars 168 forks source link

Is there a way to get the name of a custom platform, given its Sharpmake.Platform enum value? #313

Closed cmello closed 8 months ago

cmello commented 9 months ago

Hi,

When working with custom platforms that map to __reserved entries of the Sharpmake.Platform enum, is there a recommended way to get the platform name?

I believe one way to get the mapping would be querying the PlatformRegistry, to obtain the platform implementation type and then get its SimplePlatformString . However, the Query<TInterface>(Platform platform) method of the PlatformRegistry class requires the caller to know the type of the interface to get (given in its generic argument). Link to code: https://github.com/ubisoft/Sharpmake/blob/main/Sharpmake/PlatformRegistry.cs#L417-L425

Could you please suggest an alternative method to get the platform name, or may I contribute a PR to add one more Query method that does not require passing the platform interface type?

Thank you!

Best regards, Cesar

jspelletier commented 9 months ago

Hello,

I extracted some code from our scripts... Removed the things that are under nda.

    static class Extensions
    {
        public static string ToPlatformString(this Platform platform)
        {
            switch (platform)
            {
                // Used by buildsystemhelper, need to target value in Pipeline.Core/Targets.cs
                case Platform._reserved8: return "<removed the name> - Put the name here";
                case Platform._reserved7: return "<removed the name> - put that other name here";
            }

            return platform.ToString();
        }
    }

    We also have this
    class EngineTarget : ITarget
    {
            public Platform Platform;

            public string PlatformString
        {
            get
            {
                if (Platform == SomeHiddenPlatform.SharpmakePlatform)
                    return "somestring";
                if (Platform == Platform.XXXX)
                    return "XXX";
                if (Platform == XYZ.SharpmakePlatform)
                    return "xyz";

                return _platformString ??= Platform.ToString();
            }
        }
    }
cmello commented 9 months ago

Thank you!