Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicBuilder"/> class.
 /// </summary>
 /// <param name="name">The name of this instance. Used to name the created thread.</param>
 /// <param name="builder">The builder to use.</param>
 /// <param name="buildStepProvider">The build step provider to use.</param>
 public DynamicBuilder(Builder builder, IBuildStepProvider buildStepProvider, string name = null)
 {
     this.builder = builder;
     dynamicBuildStep = new DynamicBuildStep(buildStepProvider, builder.ThreadCount);
     builderThread = new Thread(SafeAction.Wrap(BuilderThread)) { IsBackground = true };
     if (!string.IsNullOrEmpty(name))
     {
         builderThread.Name = name;
     }
 }
Exemple #2
0
        //private static PluginResolver pluginManager;
        private static void BuildStepsRecursively(Builder builder, ICollection<BuildStep> steps, int stepsPerLevel, int maxLevel, BuildStep curParent = null, int curLevel = 0)
        {
            if (curLevel == maxLevel)
                return;

            for (var i = 0; i < stepsPerLevel; ++i)
            {
                BuildStep step = builder.Root.Add(new DoNothingCommand());
                if (curParent != null)
                    BuildStep.LinkBuildSteps(curParent, step);
                BuildStepsRecursively(builder, steps, stepsPerLevel, maxLevel, step, curLevel + 1);
                steps.Add(step);
            }
        }
Exemple #3
0
        public static void TestVeryLargeNumberOfEmptyCommands(Logger logger)
        {
            string appPath = VirtualFileSystem.GetAbsolutePath("/data/TestVeryLargeNumberOfEmptyCommands");
            string dbPath = appPath + "/TestVeryLargeNumberOfEmptyCommands";

            if (Directory.Exists(dbPath))
                Directory.Delete(dbPath, true);

            Directory.CreateDirectory(dbPath);
            VirtualFileSystem.MountFileSystem("/data/db", dbPath);

            logger.ActivateLog(LogMessageType.Debug);
            var builder = new Builder(appPath, "Windows", "index", "inputHashes", logger) { BuilderName = "TestBuilder" };
            var steps = new List<BuildStep>();
            const int StepsPerLevel = 5;
            const int MaxLevel = 5;

            BuildStepsRecursively(builder, steps, StepsPerLevel, MaxLevel);
            int stepCount = 0;
            for (var i = 0; i < MaxLevel; ++i)
            {
                stepCount += (int)Math.Pow(StepsPerLevel, i + 1);
            }
            Debug.Assert(steps.Count == stepCount);

            logger.Info(stepCount + " steps registered.");
            logger.Info("Starting builder (logger disabled)");
            logger.ActivateLog(LogMessageType.Fatal);
            builder.Run(Builder.Mode.Build);
            logger.ActivateLog(LogMessageType.Debug);
            logger.Info("Build finished (logger re-enabled)");

            foreach (BuildStep step in steps)
            {
                Debug.Assert(step.Status == ResultStatus.Successful);
            }
        }
Exemple #4
0
        private BuildResultCode BuildMaster()
        {
            // Only querying graphics platform, let's load package, print it and exit
            if (builderOptions.GetGraphicsPlatform)
            {
                return BuildGetGraphicsPlatform();
            }

            assetLogger = new RemoteLogForwarder(builderOptions.Logger, builderOptions.LogPipeNames);
            GlobalLogger.GlobalMessageLogged += assetLogger;
            PackageSession projectSession = null;
            try
            {
                // TODO handle solution file + package-id ?

                // When the current platform is not on windows, we need to make sure that all plugins are build, so we
                // setup auto-compile when loading the session
                var sessionLoadParameters = new PackageLoadParameters
                {
                    AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || !builderOptions.DisableAutoCompileProjects,
                    ExtraCompileProperties = builderOptions.ExtraCompileProperties,
                };

                // Loads the root Package
                var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters);
                if (projectSessionResult.HasErrors)
                {
                    projectSessionResult.CopyTo(builderOptions.Logger);
                    return BuildResultCode.BuildError;
                }

                projectSession = projectSessionResult.Session;

                // Check build configuration
                var package = projectSession.LocalPackages.Last();

                // Check build profile
                var sharedProfile = package.Profiles.FindSharedProfile();
                var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile);
                if (buildProfile == null)
                {
                    builderOptions.Logger.Error("Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath);
                    return BuildResultCode.BuildError;
                }

                // Setup variables
                var buildDirectory = builderOptions.BuildDirectory;
                var outputDirectory = builderOptions.OutputDirectory;

                // Process game settings asset
                var gameSettingsAsset = package.GetGameSettingsAsset();
                if (gameSettingsAsset == null)
                {
                    builderOptions.Logger.Warning("Could not find game settings asset at location [{0}]. Use a Default One", GameSettingsAsset.GameSettingsLocation);
                    gameSettingsAsset = new GameSettingsAsset();
                }

                // Create context
                var context = new AssetCompilerContext
                {
                    Profile = builderOptions.BuildProfile,
                    Platform = builderOptions.Platform
                };
                context.SetGameSettingsAsset(gameSettingsAsset);

                // Copy properties from shared profiles to context properties
                if (sharedProfile != null)
                {
                    sharedProfile.Properties.CopyTo(context.PackageProperties, true);
                }

                // Copy properties from build profile
                buildProfile.Properties.CopyTo(context.PackageProperties, true);

                // Builds the project
                var assetBuilder = new PackageCompiler(new RootPackageAssetEnumerator(package));
                assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler;

                var assetBuildResult = assetBuilder.Compile(context);
                assetBuildResult.CopyTo(builderOptions.Logger);
                if (assetBuildResult.HasErrors)
                    return BuildResultCode.BuildError;

                // Create the builder
                var indexName = "index." + builderOptions.BuildProfile;
                builder = new Builder(buildDirectory, builderOptions.BuildProfile, indexName, builderOptions.Logger) { ThreadCount = builderOptions.ThreadCount };
                builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames);

                // Add build steps generated by AssetBuilder
                builder.Root.Add(assetBuildResult.BuildSteps);

                // Run builder
                var result = builder.Run(Builder.Mode.Build);
                builder.WriteIndexFile(false);

                // Fill list of bundles
                var bundlePacker = new BundlePacker();
                bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds);

                return result;
            }
            finally
            {
                if (builder != null)
                {
                    builder.Dispose();
                }

                // Dispose the session (in order to unload assemblies)
                if (projectSession != null)
                {
                    projectSession.Dispose();
                }

                // Flush and close logger
                GlobalLogger.GlobalMessageLogged -= assetLogger;
                assetLogger.Dispose();
            }
        }
        public static BuildResultCode BuildLocal(BuilderOptions options)
        {
            string inputFile = options.InputFiles[0];
            string sdkDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../..");

            BuildScript buildScript = BuildScript.LoadFromFile(sdkDir, inputFile);
            buildScript.Compile(options.Plugins);

            if (buildScript.GetWarnings().FirstOrDefault() != null)
            {
                foreach (string warning in buildScript.GetWarnings())
                {
                    options.Logger.Warning(warning);
                }
            }

            if (buildScript.HasErrors)
            {
                foreach (string error in buildScript.GetErrors())
                {
                    options.Logger.Error(error);
                }
                throw new InvalidOperationException("Can't compile the provided build script.");
            }

            string inputDir = Path.GetDirectoryName(inputFile) ?? Environment.CurrentDirectory;
            options.SourceBaseDirectory = options.SourceBaseDirectory ?? Path.Combine(inputDir, buildScript.SourceBaseDirectory ?? "");
            options.BuildDirectory = options.BuildDirectory ?? Path.Combine(inputDir, buildScript.BuildDirectory ?? "");
            options.OutputDirectory = options.OutputDirectory ?? (buildScript.OutputDirectory != null ? Path.Combine(inputDir, buildScript.OutputDirectory) : "");
            options.MetadataDatabaseDirectory = options.MetadataDatabaseDirectory ?? (buildScript.MetadataDatabaseDirectory != null ? Path.Combine(inputDir, buildScript.MetadataDatabaseDirectory) : "");
            if (!string.IsNullOrWhiteSpace(options.SourceBaseDirectory))
            {
                if (!Directory.Exists(options.SourceBaseDirectory))
                {
                    string error = string.Format("Source base directory \"{0}\" does not exists.", options.SourceBaseDirectory);
                    options.Logger.Error(error);
                    throw new OptionException(error, "sourcebase");
                }
                Environment.CurrentDirectory = options.SourceBaseDirectory;
            }

            if (string.IsNullOrWhiteSpace(options.BuildDirectory))
            {
                throw new OptionException("This tool requires a build path.", "build-path");
            }

            // Mount build path
            ((FileSystemProvider)VirtualFileSystem.ApplicationData).ChangeBasePath(options.BuildDirectory);

            options.ValidateOptionsForMaster();

            // assets is always added by default
            //options.Databases.Add(new DatabaseMountInfo("/assets"));
            PrepareDatabases(options);

            try
            {
                VirtualFileSystem.CreateDirectory("/data/");
                VirtualFileSystem.CreateDirectory("/data/db/");
            }
            catch (Exception)
            {
                throw new OptionException("Invalid Build database path", "database");
            }

            // Create builder
            LogMessageType logLevel = options.Debug ? LogMessageType.Debug : (options.Verbose ? LogMessageType.Verbose : LogMessageType.Info);
            var logger = Logger.GetLogger("builder");
            logger.ActivateLog(logLevel);
            var builder = new Builder("builder", options.BuildDirectory, options.BuilderMode, logger) { ThreadCount = options.ThreadCount };
            builder.MonitorPipeNames.AddRange(options.MonitorPipeNames);
            builder.ActivateConfiguration(options.Configuration);
            foreach (var sourceFolder in buildScript.SourceFolders)
            {
                builder.InitialVariables.Add(("SourceFolder:" + sourceFolder.Key).ToUpperInvariant(), sourceFolder.Value); 
            }
            Console.CancelKeyPress += (sender, e) => Cancel(builder, e);

            buildScript.Execute(builder);

            // Run builder
            return builder.Run(options.Append == false);
        }
 public static void Cancel(Builder builder, ConsoleCancelEventArgs e)
 {
     if (builder != null && builder.IsRunning)
     {
         e.Cancel = true;
         builder.CancelBuild();
     }
 }
Exemple #7
0
 public void Execute(Builder builder)
 {
     // Execute the command C# makefile
     Type type = compilerResult.CompiledAssembly.GetType("BuildScript");
     object makefile = Activator.CreateInstance(type);
     MethodInfo executeMethod = type.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance);
     executeMethod.Invoke(makefile, new object[] { builder, builder.Root });
 }
Exemple #8
0
        private BuildResultCode BuildMaster()
        {
            assetLogger = new RemoteLogForwarder(builderOptions.Logger, builderOptions.LogPipeNames);
            GlobalLogger.GlobalMessageLogged += assetLogger;

            // TODO handle solution file + package-id ?

            // When the current platform is not on windows, we need to make sure that all plugins are build, so we
            // setup auto-compile when loading the session
            var sessionLoadParameters = new PackageLoadParameters
                {
                    AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || builderOptions.ProjectConfiguration != "Debug", // Avoid compiling if Windows|Debug
                    ExtraCompileProperties = builderOptions.ExtraCompileProperties,
                };

            // Loads the root Package
            var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters);
            if (projectSessionResult.HasErrors)
            {
                projectSessionResult.CopyTo(builderOptions.Logger);
                return BuildResultCode.BuildError;
            }

            var projectSession = projectSessionResult.Session;

            // Check build configuration
            var package = projectSession.LocalPackages.First();

            // Check build profile
            var sharedProfile = package.Profiles.FindSharedProfile();
            var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile);
            if (buildProfile == null)
            {
                builderOptions.Logger.Error("Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath);
                return BuildResultCode.BuildError;
            }

            // Setup variables
            var buildDirectory = builderOptions.BuildDirectory;
            var outputDirectory = builderOptions.OutputDirectory;

            // Builds the project
            var assetBuilder = new PackageCompiler();
            assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler;

            // Create context
            var context = new AssetCompilerContext
            {
                Package = package,
                Platform = builderOptions.Platform
            };

            // Copy properties from shared profiles to context properties
            if (sharedProfile != null)
            {
                foreach (var propertyValue in sharedProfile.Properties)
                    context.Properties.Set(propertyValue.Key, propertyValue.Value);
            }

            context.Properties.Set(Paradox.Assets.ParadoxConfig.GraphicsPlatform, builderOptions.GraphicsPlatform.HasValue ? builderOptions.GraphicsPlatform.Value : builderOptions.GetDefaultGraphicsPlatform());

            // Copy properties from build profile
            foreach (var propertyValue in buildProfile.Properties)
            {
                context.Properties.Set(propertyValue.Key, propertyValue.Value);
            }

            var assetBuildResult = assetBuilder.Compile(context);
            assetBuildResult.CopyTo(builderOptions.Logger);
            if (assetBuildResult.HasErrors)
                return BuildResultCode.BuildError;

            // Create the builder
            var indexName = "index." + builderOptions.BuildProfile;
            builder = new Builder(buildDirectory, builderOptions.BuildProfile, indexName, "InputHashes", builderOptions.Logger) { ThreadCount = builderOptions.ThreadCount };
            builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames);

            // Add build steps generated by AssetBuilder
            builder.Root.Add(assetBuildResult.BuildSteps);

            // Run builder
            var result = builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            // Fill list of bundles
            var bundlePacker = new BundlePacker();
            bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds);

            // Flush and close logger
            GlobalLogger.GlobalMessageLogged -= assetLogger;
            assetLogger.Dispose();
            
            return result;
        }
Exemple #9
0
 public ExecuteContext(Builder builder, BuilderContext builderContext, BuildStep buildStep)
 {
     Logger = new BuildStepLogger(buildStep, builder.Logger, builder.startTime);
     this.builderContext = builderContext;
     this.builder = builder;
     this.buildStep = buildStep;
     buildTransaction = new BuildTransaction(null, buildStep.GetOutputObjectsGroups());
 }
Exemple #10
0
 public ExecuteContext(Builder builder, BuilderContext builderContext, BuildStep buildStep, Logger logger)
 {
     Logger = logger;
     this.builderContext = builderContext;
     this.builder = builder;
     this.buildStep = buildStep;
     buildTransaction = new BuildTransaction(null, buildStep.GetOutputObjectsGroups());
 }