/// <summary> /// Add to the current compilation result the compilation steps required to compile the <see cref="AssetItem"/> dependencies. /// </summary> /// <param name="context">A compiler context.</param> /// <param name="result">The current result of the compilation</param> protected BuildStep AddDependenciesBuildStepsToResult(AssetCompilerContext context, AssetCompilerResult result) { // create the fake package used to compile the dependences var dependenciesCompilePackage = AssetsSession.CreateCompilePackageFromAsset(AssetItem); // compile the fake package (create the build steps) var assetPackageCompiler = new PackageCompiler(); context.Package = dependenciesCompilePackage.LocalPackages.FirstOrDefault(); var dependenciesCompileResult = assetPackageCompiler.Compile(context); // Create the result build steps if not existing yet if (result.BuildSteps == null) { result.BuildSteps = new ListBuildStep(); } // Add the dependencies build steps to the current result result.BuildSteps.Add(dependenciesCompileResult.BuildSteps); // Copy log the dependencies result to the current result dependenciesCompileResult.CopyTo(result); return(dependenciesCompileResult.BuildSteps); }
/// <summary> /// Compiles the package contained in the given context and add the resulting build steps in the <see cref="AssetCompilerResult"/> /// </summary> /// <param name="context">The context which contains the package to compile.</param> /// <param name="result">The <see cref="AssetCompilerResult"/> where the build steps will be added.</param> /// <returns></returns> protected static BuildStep CompilePackage(AssetCompilerContext context, AssetCompilerResult result) { // compile the fake package (create the build steps) var assetPackageCompiler = new PackageCompiler(); var dependenciesCompileResult = assetPackageCompiler.Compile(context); // Create the result build steps if not existing yet if (result.BuildSteps == null) result.BuildSteps = new ListBuildStep(); // Add the dependencies build steps to the current result result.BuildSteps.Add(dependenciesCompileResult.BuildSteps); // Copy log the dependencies result to the current result dependenciesCompileResult.CopyTo(result); return dependenciesCompileResult.BuildSteps; }
/// <summary> /// Compiles the package contained in the given context and add the resulting build steps in the <see cref="AssetCompilerResult"/> /// </summary> /// <param name="context">The context which contains the package to compile.</param> /// <param name="result">The <see cref="AssetCompilerResult"/> where the build steps will be added.</param> /// <returns></returns> protected static BuildStep CompilePackage(AssetCompilerContext context, Package package, AssetCompilerResult result) { // compile the fake package (create the build steps) var assetPackageCompiler = new PackageCompiler(new PackageAssetEnumerator(package)); var dependenciesCompileResult = assetPackageCompiler.Compile(context); // Create the result build steps if not existing yet if (result.BuildSteps == null) { result.BuildSteps = new ListBuildStep(); } // Add the dependencies build steps to the current result result.BuildSteps.Add(dependenciesCompileResult.BuildSteps); // Copy log the dependencies result to the current result dependenciesCompileResult.CopyTo(result); return(dependenciesCompileResult.BuildSteps); }
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(); } }
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; }