static void CommandLineBuildOnCheckinIOS() { const BuildTarget target = BuildTarget.iPhone; // Get build scenes. string[] levels = GetBuildScenes(); const string locationPathName = "iOSbuild"; const BuildOptions options = BuildOptions.None; // Get command line arguments (if passed in to build job). CommandLineData commandLineData = GetCommandLineData(IoSdefaultBundleId); PlayerSettings.iOS.scriptCallOptimization = ScriptCallOptimizationLevel.FastButNoExceptions; var shortBundleVersion = CommandLineReader.GetCustomArgument("ShortBundleVersion"); if (shortBundleVersion == String.Empty) { shortBundleVersion = commandLineData.BuildVersion; } PlayerSettings.shortBundleVersion = shortBundleVersion; if (commandLineData.StreamingAssetsEnabled == "true") { BuildPipelineBuildAssetBundle(BuildTarget.iPhone); DeleteMasterAssetResources(); } // Build all scenes. BuildPipelineBuildPlayer(levels, locationPathName, target, options, commandLineData); }
/// <summary> /// Command line parser. /// </summary> /// <param name="args">The command line arguments</param> /// <returns>A structure with information about the run</returns> private static CommandLineData ParseCommandLine(string[] args) { try { int i = 0; CommandLineData ret = new CommandLineData(); while (i < args.Length) { if (args[i].StartsWith("-")) { switch (args[i]) { //The partial trust PermissionSet case "-ps": PermSetNames permSet = (PermSetNames)Enum.Parse(typeof(PermSetNames), args[++i], true); ret.permission = PTRunnerLib.GetStandardPermission(permSet); break; //Add full trust assembly case "-af": Assembly asm = Assembly.LoadFrom(args[++i]); ret.fullTrustAssemblies.Add(asm); break; case "-xml": StreamReader sr = new StreamReader(args[++i]); SecurityElement elem = SecurityElement.FromString(sr.ReadToEnd()); ret.permission = new PermissionSet(PermissionState.None); ret.permission.FromXml(elem); break; default: Console.WriteLine("{0} - unknonw option", args[i]); Usage(); return null; } ++i; } else break; } if (i < args.Length) { //This are the arguments for the program that will be run ret.programName = args[i++]; int argsSize = args.Length - i; ret.arguments = new string[argsSize]; if (argsSize > 0) Array.Copy(args, i, ret.arguments, 0, argsSize); if (ret.permission == null) ret.permission = PTRunnerLib.GetStandardPermission(PermSetNames.Execution); return ret; } } catch (Exception ex) { Console.WriteLine(":RUNNER: Got exception while parsing command line: {0}", ex.Message); } Usage(); return null; }
/// <summary> /// Runs the test as an application with GUI /// </summary> /// <param name="data"></param> /// <param name="asserter"></param> /// <returns></returns> public IWorld CreateSelfTestInCommandLineContext(CommandLineData data, IAsserter asserter) { var holder = new NetworkServerData(); holder.Port = DefaultPort; holder.LoadingData = new LoadingData { AssemblyName = data.Unnamed[0], Level = data.Unnamed[1] }; var test = GetTest(holder.LoadingData, data.Unnamed[3]); new Action<ICvarcTest, IAsserter, NetworkServerData>(SelfTestClientThread).BeginInvoke(test, asserter, holder, null, null); var proposal = SettingsProposal.FromCommandLineData(data); CreateSelfTestServer(holder, proposal); return holder.World; }
private void Update() { CommandLineHandler.ApplicationName = Application.productName; lock (CommandLineHandler.m_MainThreadCommandLines) { while (CommandLineHandler.m_MainThreadCommandLines.Count > 0) { CommandLineData commandLine = CommandLineHandler.m_MainThreadCommandLines.Dequeue(); CommandLineHandler.CallMethod(commandLine); } } }
public static bool CallCommandLine(string command) { string[] commandAndArgs = command.Split(' '); if (!m_CommandLines.ContainsKey(commandAndArgs[0])) { return(false); } CommandLineData commandData = ParseArguments(commandAndArgs, m_CommandLines[commandAndArgs[0]]); return(DispatchCommandLineToMainThread(commandData)); }
private static void CommandLineBuildOnCheckinAndroid() { const BuildTarget target = BuildTarget.Android; // Get build scenes. string[] levels = GetBuildScenes(); string locationPathName = CommandLineReader.GetCustomArgument("APKPath"); const BuildOptions options = BuildOptions.None; // Android specific command line arguments parsed first. string versionCode = CommandLineReader.GetCustomArgument("VersionCode"); int verCode; if (Int32.TryParse(versionCode, out verCode)) { PlayerSettings.Android.bundleVersionCode = verCode; } // Get command line arguments (if passed in to build job). CommandLineData commandLineData = GetCommandLineData(AndroidDefaultBundleId); string homeDirectory = CommandLineReader.GetCustomArgument("HomeDirectory"); if (!homeDirectory.EndsWith("Assets")) { homeDirectory += "\\Assets"; } //ensure deployment script is up to date with correct version code and bundle info. string apkName = Path.GetFileNameWithoutExtension(locationPathName); //WriteVersionCodeAndAPKNameToScript(commandLineData.Environment, verCode, apkName, homeDirectory); if (commandLineData.StreamingAssetsEnabled == "true") { BuildPipelineBuildAssetBundle(BuildTarget.Android); DeleteMasterAssetResources(); } // Build all scenes. BuildPipelineBuildPlayer(levels, locationPathName, target, options, commandLineData); }
/// <summary> /// Creates a world that will play the log file. Controllers, settings and state will be obtained from the log file. /// </summary> /// <param name="cmdLineData"></param> /// <returns></returns> public IWorld CreateLogPlayer(CommandLineData cmdLineData) { Log log; try { log = Log.Load(cmdLineData.Unnamed[0]); } catch { throw new Exception("Could not load file '" + cmdLineData.Unnamed[0] + "'"); } var configuration = log.Configuration; var proposal = SettingsProposal.FromCommandLineData(cmdLineData); proposal.Push(configuration.Settings, false, z => z.SpeedUp); configuration.Settings.EnableLog = false; configuration.Settings.LogFile = null; var factory = new LogPlayerControllerFactory(log); return CreateWorld(configuration, factory, log.WorldState); }
private static CommandLineData ParseArguments(string[] commandAndArgs, CommandLineData data) { CommandLineData lineData = null; if (data.IsMethodCommand) { lineData = new CommandLineData(data.CommandLine, data.Method, (object[])data.Arguments.Clone(), data.HelpText); ParameterInfo[] parameters = data.Method.GetParameters(); object[] newArguments = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { if (commandAndArgs.Length <= i + 1) { newArguments[i] = ParseArgument(null, parameters[i].ParameterType); } else { newArguments[i] = ParseArgument(commandAndArgs[i + 1], parameters[i].ParameterType); } } lineData.MergeNewArguments(newArguments); } else if (data.IsFieldCommand) { lineData = new CommandLineData(data.CommandLine, data.Field, data.Arguments[0], data.HelpText); if (commandAndArgs.Length > 1) { lineData.SetNewFieldValue(ParseArgument(commandAndArgs[1], data.Field.FieldType)); } else { lineData.SetNewFieldValue(ParseArgument(null, data.Field.FieldType)); } } return(lineData); }
public static bool CallMethod(CommandLineData command) { try { if (command.IsMethodCommand) { command.Method.Invoke(null, command.Arguments); } else if (command.IsFieldCommand) { if (command.Arguments[0] != null) { command.Field.SetValue(null, command.Arguments[0]); } else { Console.Log("Command '" + command.CommandLine + "' couldn't be called, missing argument of type " + command.Field.FieldType.ToString(), "red"); } } return(true); } catch (Exception e) { string commandExample = command.CommandLine; if (command.IsMethodCommand) { ParameterInfo[] parameters = command.Method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { commandExample += " " + parameters[i].ParameterType.ToString(); } } Console.Log("Command '" + command.CommandLine + "' couldn't be called. Command should be: " + commandExample, "red"); Debug.Log(e); return(false); } }
static int Main(string[] args) { //Parse the command line CommandLineData commands = ParseCommandLine(args); if (commands == null) { return(1); } AssemblyRunner runner = null; try { //Create the sandbox runner = PTRunnerLib.GetPartialTrustInstance <AssemblyRunner>(commands.permission, commands.fullTrustAssemblies.ToArray()); } catch (InvalidOperationException ex) { Console.WriteLine("ERROR: {0}", ex.Message); return(-1); } //And we execute the assembly!!! return(runner.ExecuteAssembly(commands.programName, commands.arguments)); }
/// <summary> /// Creates the world for non-networking case: BotDemo or Tutorial modes. Automatically obtains all the parameters from CommandLineData /// </summary> /// <param name="cmdLineData"></param> /// <returns></returns> public IWorld CreateSimpleMode(CommandLineData cmdLineData) { var proposal = SettingsProposal.FromCommandLineData(cmdLineData); ControllerFactory factory = CreateControllerFactory(cmdLineData.Unnamed[2], proposal); var loadingData = new LoadingData { AssemblyName = cmdLineData.Unnamed[0], Level = cmdLineData.Unnamed[1] }; return CreateSimpleMode(loadingData, proposal, factory); }
/// <summary> /// Creates world for a solo network mode from a command line arguments. /// </summary> /// <param name="data"></param> /// <returns></returns> public IWorld CreateSoloNetwork(CommandLineData data) { int port; if (data.Unnamed.Count > 1) { try { port = int.Parse(data.Unnamed[1]); } catch { throw new Exception("Port number '" + data.Unnamed[1] + "' is incorrect: integer expected"); } } else port = DefaultPort; var nsdata = new NetworkServerData(); nsdata.Port = port; CreateSoloNetworkWithData(nsdata); return nsdata.World; }
private static void GatherMethodsFromAssembly(Assembly assembly) { Type[] assemblyTypes = assembly.GetTypes(); for (int i = 0; i < assemblyTypes.Length; i++) { MethodInfo[] methods = assemblyTypes[i].GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] fields = assemblyTypes[i].GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); for (int j = 0; j < methods.Length; j++) { object[] customAttributes = methods[j].GetCustomAttributes(typeof(CommandLineAttribute), true); if (customAttributes.Length > 0) { for (int attributeIndex = 0; attributeIndex < customAttributes.Length; attributeIndex++) { CommandLineAttribute line = (CommandLineAttribute)customAttributes[attributeIndex]; if (line != null) { ParameterInfo[] parameters = methods[j].GetParameters(); object[] args = new object[parameters.Length]; for (int parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++) { if (line.m_Arguments != null && parameterIndex < line.m_Arguments.Length) { if (line.m_Arguments[parameterIndex] == null) { args[parameterIndex] = parameters[parameterIndex].DefaultValue; } else { args[parameterIndex] = line.m_Arguments[parameterIndex]; } } else { args[parameterIndex] = parameters[parameterIndex].DefaultValue; } } CommandLineData newLine = new CommandLineData(line.CommandLine, methods[j], args, line.m_HelpText); m_CommandLines.Add(line.CommandLine, newLine); } } } } for (int j = 0; j < fields.Length; j++) { object[] customAttributes = fields[j].GetCustomAttributes(typeof(CommandLineAttribute), true); if (customAttributes.Length > 0) { for (int attributeIndex = 0; attributeIndex < customAttributes.Length; attributeIndex++) { CommandLineAttribute line = (CommandLineAttribute)customAttributes[attributeIndex]; if (line != null) { object value = null; if (line.m_Arguments != null && line.m_Arguments.Length > 0 && line.m_Arguments[0].GetType().Equals(fields[j].FieldType)) { value = line.m_Arguments[0]; } CommandLineData newLine = new CommandLineData(line.CommandLine, fields[j], value, line.m_HelpText); m_CommandLines.Add(line.CommandLine, newLine); } } } } } }
private static bool DispatchCommandLineToMainThread(CommandLineData command) { m_MainThreadCommandLines.Enqueue(command); return(true); }
private static void BuildPipelineBuildPlayer(string[] levels, string locationPathName, BuildTarget target, BuildOptions options, CommandLineData commandLineData) { string environment = commandLineData.Environment; string svnrevision = commandLineData.SvnRevision; string version = commandLineData.BuildVersion; string bundleId = commandLineData.BundleIdent; string streaminAssetsEnabled = commandLineData.StreamingAssetsEnabled; if (levels == null || levels.Length == 0 || locationPathName == null) { return; } Debug.Log(String.Format("Path: \"{0}\"", locationPathName)); for (int i = 0; i < levels.Length; ++i) { Debug.Log(String.Format("Scene[{0}]: \"{1}\"", i, levels[i])); } string fileRoot = Application.streamingAssetsPath; // Check environment settings. string enviromentText = "PlayerSettings Environment=\"" + environment + "\""; if (0 == environment.Length) { environment = "127.0.0.1"; enviromentText += " " + environment; } // Environment specific. if (0 != environment.Length) { // Persist environment in local file for client to load at runtime. string fullPath = fileRoot + "/GameServer.txt"; File.WriteAllText(fullPath, environment); } // SvnRevision specific. string svnRevisionText = "PlayerSettings SVNrevision=\"" + svnrevision + "\""; if (0 == svnrevision.Length) { svnrevision = "0"; svnRevisionText += " [client will default to \"" + "\"0]"; } if (0 != svnrevision.Length) { // Persist svnrevision in local file for client to load at runtime. string fullPath = fileRoot + "/SvnRevision.txt"; File.WriteAllText(fullPath, svnrevision); } if (0 != version.Length) { // Persist build version in local file for client to load at runtime. string fullPath = fileRoot + "/BuildVersion.txt"; File.WriteAllText(fullPath, version); } if (0 != streaminAssetsEnabled.Length) { // Persist build version in local file for client to load at runtime. string fullPath = fileRoot + "/StreamingAssetsEnabled.txt"; File.WriteAllText(fullPath, streaminAssetsEnabled); } PlayerSettings.bundleIdentifier = bundleId; string bundleVersion = (0 == version.Length) ? "1.0" : version; PlayerSettings.bundleVersion = bundleVersion; //SetIcon(target, environment); Debug.Log(enviromentText); Debug.Log(svnRevisionText); Debug.Log("Streaming Assets Enabled: " + streaminAssetsEnabled); Debug.Log("PlayerSettings Version=\"" + bundleVersion + "\""); Debug.Log("PlayerSettings BundleID=\"" + bundleId + "\""); Debug.Log("Starting Build!"); String error = BuildPipeline.BuildPlayer(levels, locationPathName, target, options); if (!String.IsNullOrEmpty(error)) { throw new System.Exception("Build failed: " + error); } Debug.Log("Complete Build!"); }
/// <summary> /// Command line parser. /// </summary> /// <param name="args">The command line arguments</param> /// <returns>A structure with information about the run</returns> private static CommandLineData ParseCommandLine(string[] args) { try { int i = 0; CommandLineData ret = new CommandLineData(); while (i < args.Length) { if (args[i].StartsWith("-")) { switch (args[i]) { //The partial trust PermissionSet case "-ps": PermSetNames permSet = (PermSetNames)Enum.Parse(typeof(PermSetNames), args[++i], true); ret.permission = PTRunnerLib.GetStandardPermission(permSet); break; //Add full trust assembly case "-af": Assembly asm = Assembly.LoadFrom(args[++i]); ret.fullTrustAssemblies.Add(asm); break; case "-xml": StreamReader sr = new StreamReader(args[++i]); SecurityElement elem = SecurityElement.FromString(sr.ReadToEnd()); ret.permission = new PermissionSet(PermissionState.None); ret.permission.FromXml(elem); break; default: Console.WriteLine("{0} - unknonw option", args[i]); Usage(); return(null); } ++i; } else { break; } } if (i < args.Length) { //This are the arguments for the program that will be run ret.programName = args[i++]; int argsSize = args.Length - i; ret.arguments = new string[argsSize]; if (argsSize > 0) { Array.Copy(args, i, ret.arguments, 0, argsSize); } if (ret.permission == null) { ret.permission = PTRunnerLib.GetStandardPermission(PermSetNames.Execution); } return(ret); } } catch (Exception ex) { Console.WriteLine(":RUNNER: Got exception while parsing command line: {0}", ex.Message); } Usage(); return(null); }