Пример #1
0
        static int Main()
        {
            // Setup
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
            var culture = CultureInfo.InvariantCulture;

            CultureInfo.DefaultThreadCurrentCulture   = culture;
            CultureInfo.DefaultThreadCurrentUICulture = culture;
            Thread.CurrentThread.CurrentCulture       = culture;

            // Show help option
            if (CommandLine.HasOption("help"))
            {
                Console.WriteLine(CommandLine.GetHelp(typeof(Configuration)));
                return(0);
            }

            Mutex     singleInstanceMutex = null;
            Stopwatch stopwatch           = Stopwatch.StartNew();
            bool      failed = false;

            try
            {
                // Setup
                CommandLine.Configure(typeof(Configuration));
                foreach (var option in CommandLine.GetOptions())
                {
                    if (option.Name.Length > 1 && option.Name[0] == 'D')
                    {
                        var define = option.Name.Substring(1);
                        if (!string.IsNullOrEmpty(option.Value))
                        {
                            define += "=" + option.Value;
                        }
                        Configuration.CustomDefines.Add(define);
                    }
                }
                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;
                }
                stopwatch.Stop();
                Log.Info(string.Format("Total time: {0}", stopwatch.Elapsed));
                Log.Verbose("End.");
                Log.Dispose();
            }

            return(failed ? 1 : 0);
        }
Пример #2
0
        private static void SetupProjectConfigurations(Project project, ProjectInfo projectInfo)
        {
            project.Configurations.Clear();

            // Generate a set of configurations to build all targets for all platforms/configurations/architectures
            var rules = GenerateRulesAssembly();

            foreach (var target in project.Targets)
            {
                string targetName = target.ConfigurationName ?? target.Name;

                // When using custom project file try to extract configurations from there
                if (!string.IsNullOrEmpty(target.CustomExternalProjectFilePath))
                {
                    // TODO: implement it in a proper way by parsing the project file to extract the configurations
                    if (target.CustomExternalProjectFilePath.EndsWith(".csproj"))
                    {
                        var targetPlatform   = TargetPlatform.Windows;
                        var platformName     = targetPlatform.ToString();
                        var platform         = Platform.BuildPlatform;
                        var architecture     = TargetArchitecture.AnyCPU;
                        var architectureName = "AnyCPU";
                        var toolchain        = platform.HasRequiredSDKsInstalled ? platform.GetToolchain(architecture) : null;

                        var configuration      = TargetConfiguration.Debug;
                        var configurationName  = "Debug";
                        var configurationText  = configurationName;
                        var targetBuildOptions = GetBuildOptions(target, platform, toolchain, architecture, configuration, project.WorkspaceRootPath);
                        var modules            = CollectModules(rules, platform, target, targetBuildOptions, toolchain, architecture, configuration);
                        foreach (var module in modules)
                        {
                            // This merges private module build options into global target - not the best option but helps with syntax highlighting and references collecting
                            module.Key.Setup(targetBuildOptions);
                            module.Key.SetupEnvironment(targetBuildOptions);
                        }
                        project.Configurations.Add(new Project.ConfigurationData
                        {
                            Name               = configurationText + '|' + architectureName,
                            Text               = configurationText,
                            Platform           = targetPlatform,
                            PlatformName       = platformName,
                            Architecture       = architecture,
                            ArchitectureName   = architectureName,
                            Configuration      = configuration,
                            ConfigurationName  = configurationName,
                            Target             = target,
                            TargetBuildOptions = targetBuildOptions,
                            Modules            = modules,
                        });
                        configuration      = TargetConfiguration.Release;
                        configurationName  = "Release";
                        configurationText  = configurationName;
                        targetBuildOptions = GetBuildOptions(target, platform, toolchain, architecture, configuration, project.WorkspaceRootPath);
                        modules            = CollectModules(rules, platform, target, targetBuildOptions, toolchain, architecture, configuration);
                        foreach (var module in modules)
                        {
                            // This merges private module build options into global target - not the best option but helps with syntax highlighting and references collecting
                            module.Key.Setup(targetBuildOptions);
                            module.Key.SetupEnvironment(targetBuildOptions);
                        }
                        project.Configurations.Add(new Project.ConfigurationData
                        {
                            Name               = configurationText + '|' + architectureName,
                            Text               = configurationText,
                            Platform           = targetPlatform,
                            PlatformName       = platformName,
                            Architecture       = architecture,
                            ArchitectureName   = architectureName,
                            Configuration      = configuration,
                            ConfigurationName  = configurationName,
                            Target             = target,
                            TargetBuildOptions = targetBuildOptions,
                            Modules            = modules,
                        });
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    continue;
                }

                foreach (var targetPlatform in target.Platforms)
                {
                    string platformName = targetPlatform.ToString();
                    foreach (var configuration in target.Configurations)
                    {
                        string configurationName = configuration.ToString();
                        foreach (var architecture in target.GetArchitectures(targetPlatform))
                        {
                            if (!Platform.IsPlatformSupported(targetPlatform, architecture))
                            {
                                continue;
                            }
                            var platform = Platform.GetPlatform(targetPlatform, true);
                            if (platform == null)
                            {
                                continue;
                            }
                            if (!platform.HasRequiredSDKsInstalled && (!projectInfo.IsCSharpOnlyProject || platform != Platform.BuildPlatform))
                            {
                                continue;
                            }

                            string configurationText = targetName + '.' + platformName + '.' + configurationName;
                            string architectureName  = architecture.ToString();
                            if (platform is IProjectCustomizer customizer)
                            {
                                customizer.GetProjectArchitectureName(project, platform, architecture, ref architectureName);
                            }

                            var toolchain          = platform.HasRequiredSDKsInstalled ? platform.GetToolchain(architecture) : null;
                            var targetBuildOptions = GetBuildOptions(target, platform, toolchain, architecture, configuration, project.WorkspaceRootPath);
                            var modules            = CollectModules(rules, platform, target, targetBuildOptions, toolchain, architecture, configuration);
                            foreach (var module in modules)
                            {
                                // This merges private module build options into global target - not the best option but helps with syntax highlighting and references collecting
                                module.Key.Setup(targetBuildOptions);
                                module.Key.SetupEnvironment(targetBuildOptions);
                            }

                            project.Configurations.Add(new Project.ConfigurationData
                            {
                                Name               = configurationText + '|' + architectureName,
                                Text               = configurationText,
                                Platform           = targetPlatform,
                                PlatformName       = platformName,
                                Architecture       = architecture,
                                ArchitectureName   = architectureName,
                                Configuration      = configuration,
                                ConfigurationName  = configurationName,
                                Target             = target,
                                TargetBuildOptions = targetBuildOptions,
                                Modules            = modules,
                            });
                        }
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Checks if the project that contains a given module (checks for modules located in the given project Source folder).
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="project">The project to check.</param>
 /// <returns>True if project contains that module inside, otherwise it's external or referenced.</returns>
 public static bool IsModuleFromProject(Module module, ProjectInfo project)
 {
     return(GetModuleProject(module, project) == project);
 }