Ejemplo n.º 1
0
        public void Execute()
        {
            CLITools.PrintBanner("Build");

            // TODO: Find a way to extract this into a build-script plugin.
            ScenesMenu.GenerateMapData();
            string staticDataPath = Path.Combine(buildPath, ScenesMenu.MAP_PATH);

            new FileInfo(staticDataPath).Directory?.Create();
            File.Copy(Path.Combine(Application.persistentDataPath, ScenesMenu.MAP_PATH), staticDataPath, true);


            if (target == BuildTarget.Android)
            {
                HandleAndroidAppBundle();
                HandleAndroidBundleVersionCode();
                HandleAndroidKeystore();
            }

            SetScriptingBackendFromEnv(target);

            string[]    scenes = CLITools.GetEnabledScenes();
            BuildReport report = BuildPipeline.BuildPlayer(scenes, fixedBuildPath, target, buildOpts);

            if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
            {
                throw new Exception($"Build ended with {report.summary.result} status");
            }
            else
            {
                PrintReport(report);
            }
        }
Ejemplo n.º 2
0
        public void RunFinished(ITestResultAdaptor results)
        {
            if (silent && results.FailCount == 0)
            {
                return;
            }

            if (verbose || results.FailCount > 0)
            {
                CLITools.PrintBanner("Tests");
                PrintTest(results, 0);
            }

            Console.WriteLine();
            CLITools.PrintInlineBanner("Test Summary");
            Console.WriteLine(" Passed: " + results.PassCount);
            Console.WriteLine(" Failed: " + results.FailCount);
            Console.WriteLine(" Skipped/Inconclusive: " + (results.SkipCount + results.InconclusiveCount));
            CLITools.PrintBannerBar();
            Console.WriteLine();

            if (results.FailCount > 0)
            {
                throw new Exception("Fix your tests, dag nabbit!");
            }
        }
Ejemplo n.º 3
0
        private BuildOptions GetBuildOptions()
        {
            string options = CLITools.GetArgument("opts");

            string[]     allOptionVars = !string.IsNullOrEmpty(options) ? options.Split(',') : new string[] {};
            BuildOptions allOptions    = BuildOptions.None;
            BuildOptions option;
            string       optionVar;
            int          length = allOptionVars.Length;

            for (int i = 0; i < length; i++)
            {
                optionVar = allOptionVars[i];

                if (optionVar.TryConvertToEnum(out option))
                {
                    allOptions |= option;
                }
                else
                {
                    Console.WriteLine($":: Cannot convert {optionVar} to {nameof(BuildOptions)} enum, skipping it.");
                }
            }

            return(allOptions);
        }
Ejemplo n.º 4
0
 //-------------------------------------------------------------------------
 // Public Interface
 //-------------------------------------------------------------------------
 public void ParseCommandLine()
 {
     testMode    = GetTestMode();
     synchronous = CLITools.GetFlag("runSynchronously") || CLITools.GetFlag("sync") || CLITools.GetFlag("synchronous");
     silent      = CLITools.GetFlag("silent");
     verbose     = !silent && (CLITools.GetFlag("verbose") || CLITools.GetFlag("v"));
     runner      = ScriptableObject.CreateInstance <TestRunnerApi>();
 }
Ejemplo n.º 5
0
        private string GetBuildPath()
        {
            string buildPath = CLITools.GetArgument("dir");

            if (buildPath == "")
            {
                throw new Exception("dir argument is missing");
            }
            return(buildPath);
        }
Ejemplo n.º 6
0
        private BuildTarget GetBuildTarget()
        {
            targetName = CLITools.GetArgument("target");
            if (targetName.TryConvertToEnum(out BuildTarget target))
            {
                return(target);
            }

            return(BuildTarget.NoTarget);
        }
Ejemplo n.º 7
0
        private string GetBuildName()
        {
            string buildName = CLITools.GetArgument("name");

            Console.WriteLine(":: Received name " + buildName);
            if (buildName == "")
            {
                throw new Exception("name argument is missing");
            }
            return(buildName);
        }
Ejemplo n.º 8
0
        //-------------------------------------------------------------------------
        // Helper Methods
        //-------------------------------------------------------------------------
        private TestMode?GetTestMode()
        {
            if (CLITools.GetFlag("playMode"))
            {
                return(TestMode.PlayMode);
            }
            else if (CLITools.GetFlag("editMode"))
            {
                return(TestMode.EditMode);
            }

            return(null);
        }
Ejemplo n.º 9
0
 private static void HandleAndroidBundleVersionCode()
 {
     if (CLITools.TryGetEnv(ANDROID_BUNDLE_VERSION_CODE, out string value))
     {
         if (int.TryParse(value, out int version))
         {
             PlayerSettings.Android.bundleVersionCode = version;
             Console.WriteLine($":: {ANDROID_BUNDLE_VERSION_CODE} env var detected, set the bundle version code to {value}.");
         }
         else
         {
             Console.WriteLine($":: {ANDROID_BUNDLE_VERSION_CODE} env var detected but the version value \"{value}\" is not an integer.");
         }
     }
 }
Ejemplo n.º 10
0
 //-------------------------------------------------------------------------
 // Android Stuff
 //-------------------------------------------------------------------------
 private static void HandleAndroidAppBundle()
 {
     if (CLITools.TryGetEnv(ANDROID_APP_BUNDLE, out string value))
     {
         if (bool.TryParse(value, out bool buildAppBundle))
         {
             EditorUserBuildSettings.buildAppBundle = buildAppBundle;
             Console.WriteLine($":: {ANDROID_APP_BUNDLE} env var detected, set buildAppBundle to {value}.");
         }
         else
         {
             Console.WriteLine($":: {ANDROID_APP_BUNDLE} env var detected but the value \"{value}\" is not a boolean.");
         }
     }
 }
Ejemplo n.º 11
0
        private static void HandleAndroidKeystore()
        {
            PlayerSettings.Android.useCustomKeystore = false;

            if (!File.Exists(KEYSTORE))
            {
                Console.WriteLine($":: {KEYSTORE} not found, skipping setup, using Unity's default keystore");
                return;
            }

            PlayerSettings.Android.keystoreName = KEYSTORE;

            string keystorePass;
            string keystoreAliasPass;

            if (CLITools.TryGetEnv(KEY_ALIAS_NAME, out string keyaliasName))
            {
                PlayerSettings.Android.keyaliasName = keyaliasName;
                Console.WriteLine($":: using ${KEY_ALIAS_NAME} env var on PlayerSettings");
            }
            else
            {
                Console.WriteLine($":: ${KEY_ALIAS_NAME} env var not set, using Project's PlayerSettings");
            }

            if (!CLITools.TryGetEnv(KEYSTORE_PASS, out keystorePass))
            {
                Console.WriteLine($":: ${KEYSTORE_PASS} env var not set, skipping setup, using Unity's default keystore");
                return;
            }

            if (!CLITools.TryGetEnv(KEY_ALIAS_PASS, out keystoreAliasPass))
            {
                Console.WriteLine($":: ${KEY_ALIAS_PASS} env var not set, skipping setup, using Unity's default keystore");
                return;
            }

            PlayerSettings.Android.useCustomKeystore = true;
            PlayerSettings.Android.keystorePass      = keystorePass;
            PlayerSettings.Android.keyaliasPass      = keystoreAliasPass;
        }
Ejemplo n.º 12
0
        //-------------------------------------------------------------------------
        // Helper Methods
        //-------------------------------------------------------------------------
        private void PrintReport(BuildReport report)
        {
            CLITools.PrintInlineBanner("Steps");

            foreach (BuildStep step in report.steps)
            {
                int    depth   = step.depth;
                string message = "";
                if (depth == 0)
                {
                    message += "Step: ";
                }
                else
                {
                    message += new String(' ', (depth - 1) * 3);
                    message += " - ";
                }
                message += step.name + " - " + step.duration.TotalMilliseconds + "ms";
                Console.WriteLine(message);
            }

            CLITools.PrintInlineBanner("Build Complete");
        }
Ejemplo n.º 13
0
        private void SetScriptingBackendFromEnv(BuildTarget platform)
        {
            var targetGroup = BuildPipeline.GetBuildTargetGroup(platform);

            if (CLITools.TryGetEnv(SCRIPTING_BACKEND_ENV_VAR, out string scriptingBackend))
            {
                if (scriptingBackend.TryConvertToEnum(out ScriptingImplementation backend))
                {
                    Console.WriteLine($":: Setting ScriptingBackend to {backend}");
                    PlayerSettings.SetScriptingBackend(targetGroup, backend);
                }
                else
                {
                    string possibleValues = string.Join(", ", Enum.GetValues(typeof(ScriptingImplementation)).Cast <ScriptingImplementation>());
                    throw new Exception($"Could not find '{scriptingBackend}' in ScriptingImplementation enum. Possible values are: {possibleValues}");
                }
            }
            else
            {
                var defaultBackend = PlayerSettings.GetDefaultScriptingBackend(targetGroup);
                Console.WriteLine($":: Using project's configured ScriptingBackend (should be {defaultBackend} for tagetGroup {targetGroup}");
            }
        }