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; 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.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) { sharedProfile.Properties.CopyTo(context.PackageProperties, true); } // Copy properties from build profile buildProfile.Properties.CopyTo(context.PackageProperties, true); var gameSettingsAsset = context.Package.GetGameSettingsAsset(); if (gameSettingsAsset == null) { builderOptions.Logger.Error("Could not find game settings asset at location [{0}]", GameSettingsAsset.GameSettingsLocation); return(BuildResultCode.BuildError); } context.SetGameSettingsAsset(gameSettingsAsset); 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); return(result); } finally { if (builder != null) { builder.Dispose(); } // Flush and close logger GlobalLogger.GlobalMessageLogged -= assetLogger; assetLogger.Dispose(); } }
private BuildResultCode BuildMaster() { // Only querying graphics platform, let's load package, print it and exit if (builderOptions.GetGraphicsPlatform) { return(BuildGetGraphicsPlatform()); } AssetCompilerContext context = null; 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 = GameSettingsFactory.Create(); } // Create context context = new AssetCompilerContext { Profile = builderOptions.BuildProfile, Platform = builderOptions.Platform, BuildConfiguration = builderOptions.ProjectConfiguration }; // Command line properties foreach (var property in builderOptions.Properties) { context.OptionProperties.Add(property.Key, property.Value); } // Set current game settings 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); } // Add specific steps to generate shaders // TODO: This doesn't really belong here, where should we move it? //assetBuildResult.BuildSteps.Add(new WaitBuildStep()); //assetBuildResult.BuildSteps.Add(new CompileDefaultSceneEffectCommand(context, package, assetBuildResult)); // Create the builder var indexName = "index." + builderOptions.BuildProfile; builder = new Builder(builderOptions.Logger, buildDirectory, builderOptions.BuildProfile, indexName) { 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 { builder?.Dispose(); // Dispose the session (in order to unload assemblies) projectSession?.Dispose(); context?.Dispose(); } }
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 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 }; // If a build profile is available, output the properties context.Properties.Set(SiliconStudio.Paradox.Assets.ParadoxConfig.GraphicsPlatform, builderOptions.GraphicsPlatform.HasValue ? builderOptions.GraphicsPlatform.Value : builderOptions.GetDefaultGraphicsPlatform()); 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); }