Beispiel #1
0
        /// <summary>
        ///     Writes out <c>BuildInfo</c> prior to build.
        /// </summary>
        public override void OnBeforeBuild()
        {
            GDXConfig config = GDXConfig.Get();

            if (config == null || !config.developerBuildInfoEnabled)
            {
                return;
            }

            // Cache for destructor
            _enabled = true;

            try
            {
                string path = Path.Combine(Application.dataPath, config.developerBuildInfoPath);
                Platform.EnsureFileFolderHierarchyExists(path);
                File.WriteAllText(path, BuildInfoProvider.GetContent(config, false, Context.BuildConfigurationName));

                BuildInfoProvider.CheckForAssemblyDefinition();
            }
            catch (Exception e)
            {
                Debug.LogWarning(e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get/Create an instance of the <see cref="GDXConfig"/> <see cref="UnityEngine.ScriptableObject"/>.
        /// </summary>
        /// <returns>A fully realized <see cref="GDXConfig"/>.</returns>
        public static GDXConfig Get()
        {
            // Attempt to load the settings file from the asset database.
            GDXConfig settings = AssetDatabase.LoadAssetAtPath <GDXConfig>("Assets/Resources/GDX/GDXConfig.asset");

            // If it worked, send it back!
            if (settings != null)
            {
                return(settings);
            }

            // Looks like we need to make one
            settings = ScriptableObject.CreateInstance <GDXConfig>();

            // Ensure the folder structure is in place before we manually make the asset
            Platform.EnsureFileFolderHierarchyExists(
                System.IO.Path.Combine(Application.dataPath, "Resources/GDX/GDXConfig.asset"));

            // Create and save the asset
            AssetDatabase.CreateAsset(settings, "Assets/Resources/GDX/GDXConfig.asset");
            AssetDatabase.SaveAssets();

            // Send it back!
            return(settings);
        }
Beispiel #3
0
        /// <summary>
        ///     Restores the default <c>BuildInfo</c> after a build process finishes.
        /// </summary>
        /// <param name="report">Build process reported information.</param>
        public void OnPostprocessBuild(BuildReport report)
        {
            GDXConfig config = GDXConfig.Get();

            if (config == null || !config.developerBuildInfoEnabled)
            {
                return;
            }

            BuildInfoProvider.WriteDefaultFile();
        }
Beispiel #4
0
        /// <summary>
        ///     Process an array of arguments into <see cref="Arguments" /> and <see cref="Flags" />.
        /// </summary>
        /// <param name="argumentArray">An array of arguments to process.</param>
        /// <param name="shouldClear">Should the storage containers be cleared.</param>
        public static void ProcessArguments(string[] argumentArray, bool shouldClear = true)
        {
            if (shouldClear)
            {
                Arguments.Clear();
                Flags.Clear();
            }

            // Grabs runtime method of GDX Config
            GDXConfig gdxConfig = GDXConfig.Get();

            string argumentPrefix = gdxConfig.developerCommandLineParserArgumentPrefix;
            int    prefixLength   = argumentPrefix.Length;
            string argumentSplit  = gdxConfig.developerCommandLineParserArgumentSplit;
            int    argumentLength = argumentArray.Length;

            for (int i = 0; i < argumentLength; i++)
            {
                // Cache current argument
                string argument = argumentArray[i];

                // Has the starter and has an assignment
                if (!argument.StartsWith(argumentPrefix))
                {
                    continue;
                }

                if (argument.Contains(argumentSplit))
                {
                    int    keyEnd = argument.IndexOf(argumentSplit, StringComparison.Ordinal);
                    string key    = argument.Substring(prefixLength, keyEnd - prefixLength);

                    int    valueStart = argument.IndexOf(argumentSplit, StringComparison.Ordinal) + 1;
                    int    valueEnd   = argument.Length;
                    string value      = argument.Substring(valueStart, valueEnd - valueStart);

                    // Value parameter
                    Arguments.Add(key.ToUpper(), value);
                }
                else
                {
                    string flag = argument.Substring(prefixLength).ToUpper();

                    // Flag parameter, ensure they are unique
                    if (!Flags.Contains(flag))
                    {
                        Flags.Add(flag);
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        ///     Check if an assembly definition should be placed along side the written <c>BuildInfo</c> and write one.
        /// </summary>
        public static void CheckForAssemblyDefinition()
        {
            GDXConfig config = GDXConfig.Get();

            if (config == null || !config.developerBuildInfoAssemblyDefinition)
            {
                return;
            }

            string assemblyDefinition = Path.Combine(
                Path.GetDirectoryName(Path.Combine(Application.dataPath, config.developerBuildInfoPath)) ??
                string.Empty,
                config.developerBuildInfoNamespace + ".asmdef");

            if (File.Exists(assemblyDefinition))
            {
                return;
            }

            StringBuilder fileBuilder = new StringBuilder();

            fileBuilder.AppendLine("{");
            fileBuilder.Append("\t\"name\": \"");
            fileBuilder.Append(config.developerBuildInfoNamespace);
            fileBuilder.AppendLine("\",");
            fileBuilder.Append("\t\"rootNamespace\": \"");
            fileBuilder.Append(config.developerBuildInfoNamespace);
            fileBuilder.AppendLine("\",");
            fileBuilder.AppendLine("\t\"references\": [],");
            fileBuilder.AppendLine("\t\"includePlatforms\": [],");
            fileBuilder.AppendLine("\t\"excludePlatforms\": [],");
            fileBuilder.AppendLine("\t\"allowUnsafeCode\": false,");
            fileBuilder.AppendLine("\t\"overrideReferences\": false,");
            fileBuilder.AppendLine("\t\"precompiledReferences\": [],");
            fileBuilder.AppendLine("\t\"autoReferenced\": true,");
            fileBuilder.AppendLine("\t\"defineConstraints\": [],");
            fileBuilder.AppendLine("\t\"versionDefines\": [],");
            fileBuilder.AppendLine("\t\"noEngineReferences\": true");
            fileBuilder.AppendLine("}");

            File.WriteAllText(assemblyDefinition, fileBuilder.ToString());
            AssetDatabase.ImportAsset("Assets/" +
                                      Path.GetDirectoryName(config.developerBuildInfoPath) + "/" +
                                      config.developerBuildInfoNamespace + ".asmdef");
        }
Beispiel #6
0
        /// <summary>
        ///     Writes out <c>BuildInfo</c> prior to build.
        /// </summary>
        /// <param name="report">Build process reported information.</param>
        public void OnPreprocessBuild(BuildReport report)
        {
            GDXConfig config = GDXConfig.Get();

            if (config == null || !config.developerBuildInfoEnabled)
            {
                return;
            }

            try
            {
                string path = Path.Combine(Application.dataPath, config.developerBuildInfoPath);
                Platform.EnsureFileFolderHierarchyExists(path);
                File.WriteAllText(path, BuildInfoProvider.GetContent(config, false, "Legacy"));

                BuildInfoProvider.CheckForAssemblyDefinition();
            }
            catch (Exception e)
            {
                Debug.LogWarning(e);
            }
        }
Beispiel #7
0
        /// <summary>
        ///     Write default content to <c>BuildInfo</c> file.
        /// </summary>
        public static void WriteDefaultFile()
        {
            GDXConfig config = GDXConfig.Get();

            if (config == null)
            {
                return;
            }

            try
            {
                string path = Path.Combine(Application.dataPath, config.developerBuildInfoPath);
                Platform.EnsureFileFolderHierarchyExists(path);
                File.WriteAllText(path, GetContent(config, true));

                CheckForAssemblyDefinition();
            }
            catch (Exception e)
            {
                Debug.LogWarning(e);
            }
        }
        public void True_GetContent_ForceDefaults()
        {
            string generateContent = BuildInfoProvider.GetContent(GDXConfig.Get(), true);

            Assert.IsTrue(generateContent.Contains(" public const int Changelist = 0;"), "Expected to find 'public const int Changelist = 0;'");
        }
Beispiel #9
0
        /// <summary>
        ///     Create the content for the <c>BuildInfo</c> file based on provided information.
        /// </summary>
        /// <param name="config">A <see cref="GDXConfig" /> used to determine many of the keys for information.</param>
        /// <param name="forceDefaults">Should all default values be used instead?</param>
        /// <param name="internalDescription">An internally used description.</param>
        /// <returns>The files content.</returns>
        public static string GetContent(GDXConfig config, bool forceDefaults = false,
                                        string internalDescription           = null)
        {
            // Force the parse because this isn't a runtime thing
            if (!forceDefaults)
            {
                CommandLineParser.ParseArguments();
            }

            StringBuilder fileContent = new StringBuilder();

            fileContent.Append("namespace ");
            fileContent.Append(config.developerBuildInfoNamespace);
            fileContent.AppendLine();

            fileContent.AppendLine("{");

            fileContent.AppendLine("    /// <summary>");
            fileContent.AppendLine(
                "    ///     A collection of information providing further information as to the conditions present when the build was made.");
            fileContent.AppendLine("    /// </summary>");
            fileContent.AppendLine("    public static class BuildInfo");
            fileContent.AppendLine("    {");

            // BuildNumber
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The builds numerically incremented version.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.AppendLine("        /// <remarks>");
            fileContent.AppendLine("        ///     This may not be a shared build number across all build tasks.");
            fileContent.AppendLine("        /// </remarks>");
            fileContent.Append("        public const int BuildNumber = ");
            fileContent.Append(!forceDefaults &&
                               CommandLineParser.Arguments.ContainsKey(config.developerBuildInfoBuildNumberArgument)
                ? CommandLineParser.Arguments[config.developerBuildInfoBuildNumberArgument]
                : "0");
            fileContent.AppendLine(";");

            // Changelist
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The revision the workspace was at when the build was made.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.Append("        public const int Changelist = ");
            fileContent.Append(!forceDefaults &&
                               CommandLineParser.Arguments.ContainsKey(config.developerBuildInfoBuildChangelistArgument)
                ? CommandLineParser.Arguments[config.developerBuildInfoBuildChangelistArgument]
                : "0");
            fileContent.AppendLine(";");


            // BuildTask
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The specific build task used to create the build.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.Append("        public const string BuildTask = \"");
            fileContent.Append(!forceDefaults &&
                               CommandLineParser.Arguments.ContainsKey(config.developerBuildInfoBuildTaskArgument)
                ? CommandLineParser.Arguments[config.developerBuildInfoBuildTaskArgument]
                : "N/A");
            fileContent.AppendLine("\";");

            // Stream
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The version control stream which the build was built from.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.Append("        public const string Stream = \"");
            fileContent.Append(!forceDefaults &&
                               CommandLineParser.Arguments.ContainsKey(config.developerBuildInfoBuildStreamArgument)
                ? CommandLineParser.Arguments[config.developerBuildInfoBuildStreamArgument]
                : "N/A");
            fileContent.AppendLine("\";");

            // Build Description
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The passed in build description.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.Append("        public const string Description = \"");
            fileContent.Append(!forceDefaults &&
                               CommandLineParser.Arguments.ContainsKey(
                                   config.developerBuildInfoBuildDescriptionArgument)
                ? CommandLineParser.Arguments[config.developerBuildInfoBuildDescriptionArgument]
                : "N/A");
            fileContent.AppendLine("\";");

            // Internal Description
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The internal description set through method invoke.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.Append("        public const string InternalDescription = \"");
            fileContent.Append(!forceDefaults && !string.IsNullOrEmpty(internalDescription)
                ? internalDescription
                : "N/A");
            fileContent.AppendLine("\";");

            // Timestamp
            fileContent.AppendLine("        /// <summary>");
            fileContent.AppendLine("        ///     The date and time when the build was started.");
            fileContent.AppendLine("        /// </summary>");
            fileContent.Append("        public const string Timestamp = \"");
            fileContent.Append(!forceDefaults
                ? DateTime.Now.ToString(Localization.Language.Default.GetTimestampFormat())
                : "N/A");
            fileContent.AppendLine("\";");

            fileContent.AppendLine("\t}");

            fileContent.AppendLine("}");

            return(fileContent.ToString());
        }