Exemplo n.º 1
0
		/// <summary>
		/// Parse the command line and create a list of commands to execute.
		/// </summary>
		/// <param name="Arguments">Command line</param>
		/// <param name="OutCommandsToExecute">List containing the names of commands to execute</param>
		/// <param name="OutAdditionalScriptsFolders">Optional list of additional paths to look for scripts in</param>
		private static void ParseCommandLine(string[] Arguments, List<CommandInfo> OutCommandsToExecute, out string OutScriptsForProjectFileName, List<string> OutAdditionalScriptsFolders)
		{
			// Initialize global command line parameters
			GlobalCommandLine.Init();

			ParseProfile(ref Arguments);

			Log.TraceInformation("Parsing command line: {0}", CommandUtils.FormatCommandLine(Arguments));

			OutScriptsForProjectFileName = null;

			CommandInfo CurrentCommand = null;
			for (int Index = 0; Index < Arguments.Length; ++Index)
			{
				var Param = Arguments[Index];
				if (Param.StartsWith("-") || Param.Contains("="))
				{
					ParseParam(Arguments[Index], CurrentCommand, ref OutScriptsForProjectFileName, OutAdditionalScriptsFolders);
				}
				else
				{
					CurrentCommand = new CommandInfo();
					CurrentCommand.CommandName = Arguments[Index];
					OutCommandsToExecute.Add(CurrentCommand);
				}
			}

			// Validate
			var Result = OutCommandsToExecute.Count > 0 || GlobalCommandLine.Help || GlobalCommandLine.CompileOnly || GlobalCommandLine.List;
			if (OutCommandsToExecute.Count > 0)
			{
				Log.TraceVerbose("Found {0} scripts to execute:", OutCommandsToExecute.Count);
				foreach (var Command in OutCommandsToExecute)
				{
					Log.TraceVerbose("  " + Command.ToString());
				}
			}
			else if (!Result)
			{
				throw new AutomationException("Failed to find scripts to execute in the command line params.");
			}
			if (GlobalCommandLine.NoP4 && GlobalCommandLine.P4)
			{
				throw new AutomationException("{0} and {1} can't be set simultaneously.", GlobalCommandLine.NoP4.Name, GlobalCommandLine.P4.Name);
			}
			if (GlobalCommandLine.NoSubmit && GlobalCommandLine.Submit)
			{
				throw new AutomationException("{0} and {1} can't be set simultaneously.", GlobalCommandLine.NoSubmit.Name, GlobalCommandLine.Submit.Name);
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// Parse the command line and create a list of commands to execute.
		/// </summary>
		/// <param name="CommandLine">Command line</param>
		/// <param name="OutCommandsToExecute">List containing the names of commands to execute</param>
		/// <param name="OutAdditionalScriptsFolders">Optional list of additional paths to look for scripts in</param>
		private static void ParseCommandLine(string[] CommandLine, List<CommandInfo> OutCommandsToExecute, List<string> OutAdditionalScriptsFolders)
		{
			// Initialize global command line parameters
			GlobalCommandLine.Init();

			Log.TraceInformation("Parsing command line: {0}", String.Join(" ", CommandLine));

			CommandInfo CurrentCommand = null;
			for (int Index = 0; Index < CommandLine.Length; ++Index)
			{
				var Param = CommandLine[Index];
				if (Param.StartsWith("-") || Param.Contains("="))
				{
					ParseParam(CommandLine[Index], CurrentCommand, OutAdditionalScriptsFolders);
				}
				else
				{
					CurrentCommand = new CommandInfo();
					CurrentCommand.CommandName = CommandLine[Index];
					OutCommandsToExecute.Add(CurrentCommand);
				}
			}

			// Validate
			var Result = OutCommandsToExecute.Count > 0 || GlobalCommandLine.Help || GlobalCommandLine.CompileOnly || GlobalCommandLine.List;
			if (OutCommandsToExecute.Count > 0)
			{
				Log.TraceVerbose("Found {0} scripts to execute:", OutCommandsToExecute.Count);
				foreach (var Command in OutCommandsToExecute)
				{
					Log.TraceVerbose("  " + Command.ToString());
				}
			}
			else if (!Result)
			{
				throw new AutomationException("Failed to find scripts to execute in the command line params.");
			}
			if (GlobalCommandLine.NoP4 && GlobalCommandLine.P4)
			{
				throw new AutomationException("{0} and {1} can't be set simultaneously.", GlobalCommandLine.NoP4.Name, GlobalCommandLine.P4.Name);
			}
			if (GlobalCommandLine.NoSubmit && GlobalCommandLine.Submit)
			{
				throw new AutomationException("{0} and {1} can't be set simultaneously.", GlobalCommandLine.NoSubmit.Name, GlobalCommandLine.Submit.Name);
			}

			if (GlobalCommandLine.Rocket)
			{
				UnrealBuildTool.UnrealBuildTool.bRunningRocket = true;
			}
		}
Exemplo n.º 3
0
		/// <summary>
		/// Parses command line parameter.
		/// </summary>
		/// <param name="ParamIndex">Parameter index</param>
		/// <param name="CommandLine">Command line</param>
		/// <param name="CurrentCommand">Recently parsed command</param>
		/// <param name="OutScriptsForProjectFileName">The only project to build scripts for</param>
		/// <param name="OutAdditionalScriptsFolders">Additional script locations</param>
		/// <returns>True if the parameter has been successfully parsed.</returns>
		private static void ParseParam(string CurrentParam, CommandInfo CurrentCommand, ref string OutScriptsForProjectFileName, List<string> OutAdditionalScriptsFolders)
		{
			bool bGlobalParam = false;
			foreach (var RegisteredParam in GlobalCommandLine.RegisteredArgs)
			{
				if (String.Compare(CurrentParam, RegisteredParam.Key, StringComparison.InvariantCultureIgnoreCase) == 0)
				{
					// Register and exit, we're done here.
					RegisteredParam.Value.Set();
					bGlobalParam = true;
					break;
				}
			}

			// The parameter was not found in the list of global parameters, continue looking...
			if (CurrentParam.StartsWith("-ScriptsForProject=", StringComparison.InvariantCultureIgnoreCase))
			{
				if(OutScriptsForProjectFileName != null)
				{
					throw new AutomationException("The -ProjectScripts argument may only be specified once");
				}
				var ProjectFileName = CurrentParam.Substring(CurrentParam.IndexOf('=') + 1).Replace("\"", "");
				if(!File.Exists(ProjectFileName))
				{
					throw new AutomationException("Project '{0}' does not exist", ProjectFileName);
				}
				OutScriptsForProjectFileName = Path.GetFullPath(ProjectFileName);
			}
			else if (CurrentParam.StartsWith("-ScriptDir=", StringComparison.InvariantCultureIgnoreCase))
			{
				var ScriptDir = CurrentParam.Substring(CurrentParam.IndexOf('=') + 1);
				if (Directory.Exists(ScriptDir))
				{
					OutAdditionalScriptsFolders.Add(ScriptDir);
					Log.TraceVerbose("Found additional script dir: {0}", ScriptDir);
				}
				else
				{
					throw new AutomationException("Specified ScriptDir doesn't exist: {0}", ScriptDir);
				}
			}
			else if (CurrentParam.StartsWith("-"))
			{
				if (CurrentCommand != null)
				{
					CurrentCommand.Arguments.Add(CurrentParam.Substring(1));
				}
				else if (!bGlobalParam)
				{
					throw new AutomationException("Unknown parameter {0} in the command line that does not belong to any command.", CurrentParam);
				}
			}
			else if (CurrentParam.Contains("="))
			{
				// Environment variable
				int ValueStartIndex = CurrentParam.IndexOf('=') + 1;
				string EnvVarName = CurrentParam.Substring(0, ValueStartIndex - 1);
				if (String.IsNullOrEmpty(EnvVarName))
				{
					throw new AutomationException("Unable to parse environment variable that has no name. Error when parsing command line param {0}", CurrentParam);
				}
				string EnvVarValue = CurrentParam.Substring(ValueStartIndex);
				CommandUtils.SetEnvVar(EnvVarName, EnvVarValue);
			}
		}
Exemplo n.º 4
0
        /// <summary>
        /// Parses command line parameter.
        /// </summary>
        /// <param name="ParamIndex">Parameter index</param>
        /// <param name="CommandLine">Command line</param>
        /// <param name="CurrentCommand">Recently parsed command</param>
        /// <param name="OutScriptsForProjectFileName">The only project to build scripts for</param>
        /// <param name="OutAdditionalScriptsFolders">Additional script locations</param>
        /// <returns>True if the parameter has been successfully parsed.</returns>
        private static void ParseParam(string CurrentParam, CommandInfo CurrentCommand, ref string OutScriptsForProjectFileName, List <string> OutAdditionalScriptsFolders)
        {
            bool bGlobalParam = false;

            foreach (var RegisteredParam in GlobalCommandLine.RegisteredArgs)
            {
                if (String.Compare(CurrentParam, RegisteredParam.Key, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    // Register and exit, we're done here.
                    RegisteredParam.Value.Set();
                    bGlobalParam = true;
                    break;
                }
            }

            // The parameter was not found in the list of global parameters, continue looking...
            if (CurrentParam.StartsWith("-ScriptsForProject=", StringComparison.InvariantCultureIgnoreCase))
            {
                if (OutScriptsForProjectFileName != null)
                {
                    throw new AutomationException("The -ProjectScripts argument may only be specified once");
                }
                var ProjectFileName = CurrentParam.Substring(CurrentParam.IndexOf('=') + 1).Replace("\"", "");
                if (!File.Exists(ProjectFileName))
                {
                    throw new AutomationException("Project '{0}' does not exist", ProjectFileName);
                }
                OutScriptsForProjectFileName = Path.GetFullPath(ProjectFileName);
            }
            else if (CurrentParam.StartsWith("-ScriptDir=", StringComparison.InvariantCultureIgnoreCase))
            {
                var ScriptDir = CurrentParam.Substring(CurrentParam.IndexOf('=') + 1);
                if (Directory.Exists(ScriptDir))
                {
                    OutAdditionalScriptsFolders.Add(ScriptDir);
                    Log.TraceVerbose("Found additional script dir: {0}", ScriptDir);
                }
                else
                {
                    throw new AutomationException("Specified ScriptDir doesn't exist: {0}", ScriptDir);
                }
            }
            else if (CurrentParam.StartsWith("-"))
            {
                if (CurrentCommand != null)
                {
                    CurrentCommand.Arguments.Add(CurrentParam.Substring(1));
                }
                else if (!bGlobalParam)
                {
                    throw new AutomationException("Unknown parameter {0} in the command line that does not belong to any command.", CurrentParam);
                }
            }
            else if (CurrentParam.Contains("="))
            {
                // Environment variable
                int    ValueStartIndex = CurrentParam.IndexOf('=') + 1;
                string EnvVarName      = CurrentParam.Substring(0, ValueStartIndex - 1);
                if (String.IsNullOrEmpty(EnvVarName))
                {
                    throw new AutomationException("Unable to parse environment variable that has no name. Error when parsing command line param {0}", CurrentParam);
                }
                string EnvVarValue = CurrentParam.Substring(ValueStartIndex);
                CommandUtils.SetEnvVar(EnvVarName, EnvVarValue);
            }
        }