4 using System.Collections.Generic;
7 using System.Text.RegularExpressions;
8 using SiliconStudio.Assets.Analysis;
9 using SiliconStudio.BuildEngine;
10 using SiliconStudio.Core;
11 using SiliconStudio.Core.IO;
13 namespace SiliconStudio.Assets.Compiler
30 var uri =
new UriBuilder(codeBase);
31 var path = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));
32 SdkDirectory = Path.GetFullPath(Path.Combine(path,
@"..\.."));
36 : base(assetCompilerRegistry)
38 if (session == null)
throw new ArgumentNullException(
"session");
39 this.session = session;
46 public static string SdkDirectory {
get; set; }
58 packageAnalysis.Run(result);
65 RecursiveCompile(result, compilerContext,
new HashSet<Package>());
75 if (result == null)
throw new ArgumentNullException(
"result");
76 if (context == null)
throw new ArgumentNullException(
"context");
77 if (context.
Package == null)
throw new ArgumentException(
"context.Package cannot be null",
"context");
79 if (processed.Contains(context.
Package))
83 processed.Add(context.Package);
85 var
package = context.Package;
86 GenerateRawImportBuildSteps(context, result);
89 foreach (var packageDependency
in package.Meta.Dependencies)
91 var subPackage = session.Packages.Find(packageDependency);
92 if (subPackage != null)
95 var contextCopy = (AssetCompilerContext)context.
Clone();
96 contextCopy.Package = subPackage;
97 RecursiveCompile(result, contextCopy, processed);
101 result.Error(
"Unable to find package [{0}]", packageDependency);
106 foreach (var subPackageReference
in package.LocalDependencies)
108 var subPackage = session.Packages.Find(subPackageReference.Id);
109 if (subPackage != null)
112 var contextCopy = (AssetCompilerContext)context.
Clone();
113 contextCopy.Package = subPackage;
114 RecursiveCompile(result, contextCopy, processed);
118 result.Error(
"Unable to find package [{0}]", subPackageReference);
122 result.Info(
"Compiling package [{0}]", package.FullPath);
125 var assets = package.Assets.ToList();
126 assets.Sort((item1, item2) => item1.Asset != null && item2.Asset != null ? item1.Asset.BuildOrder.CompareTo(item2.Asset.BuildOrder) : 0);
129 Compile(context, assets, result);
137 private void GenerateRawImportBuildSteps(AssetCompilerContext context, AssetCompilerResult result)
139 if (context.Package.RootDirectory == null)
142 foreach (var profile
in context.Package.Profiles)
144 foreach (var sourceFolder
in profile.AssetFolders)
146 var baseDirectory = Path.GetFullPath(context.Package.RootDirectory);
148 baseDirectory = Path.Combine(baseDirectory, sourceFolder.Path);
150 if (!Directory.Exists(baseDirectory))
155 var baseUDirectory =
new UDirectory(baseDirectory);
156 var hashSet =
new HashSet<string>();
159 foreach (var rawImport
in sourceFolder.RawImports)
161 var sourceDirectory = baseUDirectory;
162 if (!
string.IsNullOrEmpty(rawImport.SourceDirectory))
163 sourceDirectory =
UPath.Combine(sourceDirectory, rawImport.SourceDirectory);
165 if (!Directory.Exists(sourceDirectory))
167 result.Error(
"Unable to find raw import directory [{0}]", sourceDirectory);
171 var files = Directory.EnumerateFiles(sourceDirectory,
"*.*", SearchOption.AllDirectories).ToList();
172 var importRegexes = rawImport.Patterns.Select(x =>
new Regex(Selectors.PathSelector.TransformToRegex(x))).ToArray();
173 foreach (var file
in files)
175 var pathToFileRelativeToProject =
new UFile(file).MakeRelative(sourceDirectory);
176 var outputPath = pathToFileRelativeToProject;
177 if (!
string.IsNullOrEmpty(rawImport.TargetLocation))
178 outputPath =
UPath.Combine(rawImport.TargetLocation, outputPath);
180 foreach (var importRegex
in importRegexes)
182 if (importRegex.Match(pathToFileRelativeToProject).Success && hashSet.Add(outputPath))
187 Location = outputPath,
198 private static readonly Regex ChangeWildcardToRegex =
new Regex(
@"(?<!\*)\*");
200 private static Regex CompileRawImport(
string rawImport)
205 rawImport = rawImport.Replace(
".",
"\\.");
207 rawImport = ChangeWildcardToRegex.Replace(rawImport,
".*?");
208 return new Regex(rawImport, RegexOptions.IgnoreCase);
Result of a compilation of assets when using IAssetCompiler.Compile
A package assets compiler. Creates the build steps necessary to produce the assets of a package...
PackageAssetsCompiler(PackageSession session)
Package Package
Gets the package.
Class PackageAnalysisParameters. This class cannot be inherited.
The context used when compiling an asset in a Package.
A session for editing a package.
Defines a normalized directory path. See UPath for details. This class cannot be inherited.
A package analysis provides methods to validate the integrity of a whole package. ...
Base class that describes a uniform path and provides method to manipulate them. Concrete class are U...
The base class to compile a series of AssetItems using associated IAssetCompilers. An item list compiler only creates the build steps required to creates some output items. The result of a compilation has then to be executed by the build engine to effectively create the outputs items.
AssetCompilerResult Compile(AssetCompilerContext compilerContext)
Compile the current package session. That is generate the list of build steps to execute to create th...
A registry containing the asset compilers of the assets.
Defines a normalized file path. See UPath for details. This class cannot be inherited.