示例#1
0
        /// <summary>
        /// Compile the required build step necessary to produce the desired output item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="compilationResult">The compilation result.</param>
        /// <param name="assetItem">The asset item.</param>
        protected BuildStep CompileItem(CompilerContext context, AssetCompilerResult compilationResult, AssetItem assetItem)
        {
            // First try to find an asset compiler for this particular asset.
            IAssetCompiler compiler;

            try
            {
                compiler = compilerRegistry.GetCompiler(assetItem.Asset.GetType());
            }
            catch (Exception ex)
            {
                compilationResult.Error("Cannot find a compiler for asset [{0}] from path [{1}]", ex, assetItem.Id,
                                        assetItem.Location);
                return(null);
            }

            if (compiler == null)
            {
                return(null);
            }

            // Second we are compiling the asset (generating a build step)
            try
            {
                var resultPerAssetType = compiler.Compile(context, assetItem);

                // Raise the AssetCompiled event.
                var handler = AssetCompiled;
                if (handler != null)
                {
                    handler(this, new AssetCompiledArgs(assetItem, resultPerAssetType));
                }

                resultPerAssetType.CopyTo(compilationResult);

                if (resultPerAssetType.BuildSteps == null)
                {
                    return(null);
                }

                // Build the module string
                var assetAbsolutePath = assetItem.FullPath;
                assetAbsolutePath = Path.GetFullPath(assetAbsolutePath);
                var module = string.Format("{0}(1,1)", assetAbsolutePath);

                // Assign module string to all command build steps
                SetModule(resultPerAssetType.BuildSteps, module);

                // Add a wait command to the build steps if required by the item build
                if (resultPerAssetType.ShouldWaitForPreviousBuilds)
                {
                    compilationResult.BuildSteps.Add(new WaitBuildStep());
                }

                foreach (var buildStep in resultPerAssetType.BuildSteps)
                {
                    buildStep.Priority = latestPriority++;
                }

                // Add the item result build steps the item list result build steps
                return(resultPerAssetType.BuildSteps);
            }
            catch (Exception ex)
            {
                compilationResult.Error("Unexpected exception while compiling asset [{0}] from path [{1}]", ex, assetItem.Id,
                                        assetItem.Location);
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Compile the required build step necessary to produce the desired output item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="compilationResult">The compilation result.</param>
        /// <param name="assetItem">The asset item.</param>
        protected ListBuildStep CompileItem(CompilerContext context, AssetCompilerResult compilationResult, AssetItem assetItem)
        {
            // First try to find an asset compiler for this particular asset.
            IAssetCompiler compiler;

            try
            {
                compiler = compilerRegistry.GetCompiler(assetItem.Asset.GetType());
            }
            catch (Exception ex)
            {
                compilationResult.Error("Cannot find a compiler for asset [{0}] from path [{1}]", ex, assetItem.Id,
                                        assetItem.Location);
                return(null);
            }

            if (compiler == null)
            {
                return(null);
            }

            // Second we are compiling the asset (generating a build step)
            try
            {
                var resultPerAssetType = compiler.Compile(context, assetItem);

                // Raise the AssetCompiled event.
                var handler = AssetCompiled;
                if (handler != null)
                {
                    handler(this, new AssetCompiledArgs(assetItem, resultPerAssetType));
                }

                // TODO: See if this can be unified with PackageBuilder.BuildStepProcessed
                foreach (var message in resultPerAssetType.Messages)
                {
                    var assetMessage = new AssetLogMessage(null, assetItem.ToReference(), message.Type, AssetMessageCode.CompilationMessage, assetItem.Location, message.Text)
                    {
                        Exception = message is LogMessage ? ((LogMessage)message).Exception : null
                    };
                    // Forward log messages to compilationResult
                    compilationResult.Log(assetMessage);

                    // Forward log messages to build step logger
                    resultPerAssetType.BuildSteps.Logger.Log(assetMessage);
                }

                // Make the build step fail if there was an error during compiling (only when we are compiling the build steps of an asset)
                if (resultPerAssetType.BuildSteps is AssetBuildStep && resultPerAssetType.BuildSteps.Logger.HasErrors)
                {
                    resultPerAssetType.BuildSteps.Add(new CommandBuildStep(new FailedCommand(assetItem.Location)));
                }

                // Build the module string
                var assetAbsolutePath = assetItem.FullPath;
                assetAbsolutePath = Path.GetFullPath(assetAbsolutePath);
                var module = string.Format("{0}(1,1)", assetAbsolutePath);

                // Assign module string to all command build steps
                SetModule(resultPerAssetType.BuildSteps, module);

                // Add a wait command to the build steps if required by the item build
                if (resultPerAssetType.ShouldWaitForPreviousBuilds)
                {
                    compilationResult.BuildSteps.Add(new WaitBuildStep());
                }

                foreach (var buildStep in resultPerAssetType.BuildSteps)
                {
                    buildStep.Priority = latestPriority++;
                }

                // Add the item result build steps the item list result build steps
                return(resultPerAssetType.BuildSteps);
            }
            catch (Exception ex)
            {
                compilationResult.Error("Unexpected exception while compiling asset [{0}] from path [{1}]", ex, assetItem.Id,
                                        assetItem.Location);
                return(null);
            }
        }