/// <inheritdoc /> public override void Setup(BuildOptions options) { base.Setup(options); if (Name != "Core") { // All Engine modules include Core module options.PrivateDependencies.Add("Core"); } if (options.Target.IsEditor) { // Use Debug module by default in Editor if (Name != "Debug") { options.PrivateDependencies.Add("Debug"); } options.ScriptingAPI.Defines.Add("FLAX_EDITOR"); } else { options.ScriptingAPI.Defines.Add("FLAX_GAME"); } BinaryModuleName = "FlaxEngine"; options.ScriptingAPI.Defines.Add("FLAX"); options.ScriptingAPI.Defines.Add("FLAX_ASSERTIONS"); options.ScriptingAPI.FileReferences.Add(Utilities.RemovePathRelativeParts(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "DotNet", "Newtonsoft.Json.dll"))); }
static int Main() { // Setup ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Show help option if (CommandLine.HasOption("help")) { Console.WriteLine(CommandLine.GetHelp(typeof(Configuration))); return(0); } Mutex singleInstanceMutex = null; var startTime = DateTime.Now; bool failed = false; try { // Setup CommandLine.Configure(typeof(Configuration)); if (Configuration.CurrentDirectory != null) { Environment.CurrentDirectory = Configuration.CurrentDirectory; } Globals.Root = Directory.GetCurrentDirectory(); var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Globals.EngineRoot = Utilities.RemovePathRelativeParts(Path.Combine(Path.GetDirectoryName(executingAssembly.Location), "..", "..")); Log.Init(); // Log basic info Version version = executingAssembly.GetName().Version; string versionString = string.Join(".", version.Major, version.Minor, version.Build); Log.Info(string.Format("Flax.Build {0}", versionString)); using (new LogIndentScope()) { Log.Verbose("Arguments: " + CommandLine.Get()); Log.Verbose("Workspace: " + Globals.Root); Log.Verbose("Engine: " + Globals.EngineRoot); } // Load project { var projectFiles = Directory.GetFiles(Globals.Root, "*.flaxproj", SearchOption.TopDirectoryOnly); if (projectFiles.Length == 1) { Globals.Project = ProjectInfo.Load(projectFiles[0]); } else if (projectFiles.Length > 1) { throw new Exception("Too many project files. Don't know which to pick."); } else { Log.Warning("Missing project file."); } } // Use mutex if required if (Configuration.Mutex) { singleInstanceMutex = new Mutex(true, "Flax.Build", out var oneInstanceMutexCreated); if (!oneInstanceMutexCreated) { try { if (!singleInstanceMutex.WaitOne(0)) { Log.Warning("Wait for another instance(s) of Flax.Build to end..."); singleInstanceMutex.WaitOne(); } } catch (AbandonedMutexException) { // Can occur if another Flax.Build is killed in the debugger } finally { Log.Info("Waiting done."); } } } // Collect all targets and modules from the workspace Builder.GenerateRulesAssembly(); // Print SDKs if (Configuration.PrintSDKs) { Log.Info("Printing SDKs..."); Sdk.Print(); } // Deps tool if (Configuration.BuildDeps || Configuration.ReBuildDeps) { Log.Info("Building dependencies..."); failed |= DepsBuilder.Run(); } // Clean if (Configuration.Clean || Configuration.Rebuild) { Log.Info("Cleaning build workspace..."); Builder.Clean(); } // Generate projects for the targets and solution for the workspace if (Configuration.GenerateProject) { Log.Info("Generating project files..."); Builder.GenerateProjects(); } // Build targets if (Configuration.Build || Configuration.Rebuild) { Log.Info("Building targets..."); failed |= Builder.BuildTargets(); } // Deploy tool if (Configuration.Deploy) { Log.Info("Running deployment..."); failed |= Deployer.Run(); } // Performance logging if (Configuration.PerformanceInfo) { Log.Info(string.Empty); Log.Info("Performance Summary"); Profiling.LogStats(); } if (Configuration.TraceEventFile != null) { Profiling.GenerateTraceEventFile(); } } catch (Exception ex) { Log.Exception(ex); return(1); } finally { if (singleInstanceMutex != null) { singleInstanceMutex.Dispose(); singleInstanceMutex = null; } var endTime = DateTime.Now; Log.Info(string.Format("Total time: {0}", endTime - startTime)); Log.Verbose("End."); Log.Dispose(); } return(failed ? 1 : 0); }
/// <summary> /// Loads the project from the specified file. /// </summary> /// <param name="path">The path.</param> /// <returns>The loaded project.</returns> public static ProjectInfo Load(string path) { // Try to reuse loaded file path = Utilities.RemovePathRelativeParts(path); if (_projectsCache == null) { _projectsCache = new List <ProjectInfo>(); } for (int i = 0; i < _projectsCache.Count; i++) { if (_projectsCache[i].ProjectPath == path) { return(_projectsCache[i]); } } try { // Load Log.Verbose("Loading project file from \"" + path + "\"..."); var contents = File.ReadAllText(path); var project = JsonConvert.DeserializeObject <ProjectInfo>(contents); project.ProjectPath = path; project.ProjectFolderPath = Path.GetDirectoryName(path); // Process project data if (string.IsNullOrEmpty(project.Name)) { throw new Exception("Missing project name."); } if (project.Version == null) { project.Version = new Version(1, 0); } if (project.Version.Revision == 0) { project.Version = new Version(project.Version.Major, project.Version.Minor, project.Version.Build); } if (project.Version.Build == 0 && project.Version.Revision == -1) { project.Version = new Version(project.Version.Major, project.Version.Minor); } foreach (var reference in project.References) { string referencePath; if (reference.Name.StartsWith("$(EnginePath)")) { // Relative to engine root referencePath = Path.Combine(Globals.EngineRoot, reference.Name.Substring(14)); } else if (reference.Name.StartsWith("$(ProjectPath)")) { // Relative to project root referencePath = Path.Combine(project.ProjectFolderPath, reference.Name.Substring(15)); } else if (Path.IsPathRooted(reference.Name)) { // Relative to workspace referencePath = Path.Combine(Environment.CurrentDirectory, reference.Name); } else { // Absolute referencePath = reference.Name; } referencePath = Utilities.RemovePathRelativeParts(referencePath); // Load referenced project reference.Project = Load(referencePath); } // Project loaded Log.Verbose($"Loaded project {project.Name}, version {project.Version}"); _projectsCache.Add(project); return(project); } catch { // Failed to load project Log.Error("Failed to load project \"" + path + "\"."); throw; } }