diff --git a/sources/buildengine/Stride.Core.BuildEngine/AndroidAdbUtilities.cs b/sources/buildengine/Stride.Core.BuildEngine/AndroidAdbUtilities.cs deleted file mode 100644 index 135b74698e..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/AndroidAdbUtilities.cs +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Stride.Framework.Diagnostics; -using Stride.Framework.Serialization; - -namespace Stride.BuildEngine -{ - public static class AndroidAdbUtilities - { - private static readonly string AdbExecutable = FindAdbExecutable(); - - public static string GetExternalStoragePath(string device) - { - var sdcardPath = RunAdb(device, "shell \"echo $EXTERNAL_STORAGE\""); - return sdcardPath[0]; - } - - public static string[] GetDevices() - { - var devices = RunAdb(null, "devices"); - - // Skip first line "List of devices attached", - // and then take first part of string (device id). - return devices.Skip(1).Select(x => x.Split(' ', '\t').First()).ToArray(); - } - - /// - /// Synchronizes files to an android device. - /// - /// The logger. - /// The device. - /// The file mapping (relative target path, source HDD filename). - /// The android path. - /// The cache file. - public static void Synchronize(Logger logger, string device, Dictionary fileMapping, string androidPath, string cacheFile) - { - // Ensure android path ends up with directory separator - if (!androidPath.EndsWith("/")) - androidPath = androidPath + "/"; - - // Search files - var currentVersions = fileMapping - .ToDictionary(x => x.Key, x => new FileVersion(x.Value)); - - // Try to read previous cache file - var previousVersions = new Dictionary(); - try - { - using (var file = File.OpenRead(cacheFile)) - { - var binaryReader = new BinarySerializationReader(file); - binaryReader.Serialize(ref previousVersions, ArchiveMode.Deserialize); - } - } - catch (IOException) - { - } - - var filesToRemove = new List(); - var filesToUpload = new List(); - - // Remove unecessary files (in previousVersions but not in currentVersions) - foreach (var file in previousVersions.Where(x => !currentVersions.ContainsKey(x.Key))) - { - filesToRemove.Add(file.Key); - } - - // Upload files that are either not uploaded yet, or not up to date - foreach (var file in currentVersions) - { - FileVersion fileVersion; - if (!previousVersions.TryGetValue(file.Key, out fileVersion) - || fileVersion.FileSize != file.Value.FileSize - || fileVersion.LastModifiedDate != file.Value.LastModifiedDate) - { - filesToUpload.Add(file.Key); - } - } - - // Upload files - foreach (var file in filesToUpload) - { - if (logger != null) - logger.Verbose("Copying file {0}", file); - RunAdb(device, string.Format("push \"{0}\" \"{1}\"", fileMapping[file], androidPath + file.Replace('\\', '/'))); - } - - // Remove files - foreach (var file in filesToRemove) - { - if (logger != null) - logger.Verbose("Deleting file {0}", file); - RunAdb(device, string.Format("shell \"rm {0}\"", androidPath + file.Replace('\\', '/'))); - } - - // Write new cache file - using (var file = File.Create(cacheFile)) - { - var binaryWriter = new BinarySerializationWriter(file); - binaryWriter.Write(currentVersions); - } - } - - private static string FindAdbExecutable() - { - var androidSdkDir = Environment.GetEnvironmentVariable("ANDROID_SDK"); - var androidAdbExecutable = androidSdkDir != null ? androidSdkDir + @"\platform-tools\adb" : "adb"; - - return androidAdbExecutable; - } - - private static string[] RunAdb(string device, string arguments) - { - // Add device to argument list if necessary - if (device != null) - arguments = "-s " + device + ' ' + arguments; - - var processStartInfo = new ProcessStartInfo() - { - FileName = AdbExecutable, - Arguments = arguments, - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardOutput = true, - }; - - var lines = new List(); - - var adbProcess = Process.Start(processStartInfo); - adbProcess.OutputDataReceived += (sender, args) => - { - if (!string.IsNullOrEmpty(args.Data)) - { - lock (adbProcess) - { - lines.Add(args.Data); - } - } - }; - adbProcess.BeginOutputReadLine(); - adbProcess.WaitForExit(); - - return lines.ToArray(); - } - - [Serializable] - public struct FileVersion - { - public DateTime LastModifiedDate; - public long FileSize; - - public FileVersion(string fileName) - { - LastModifiedDate = DateTime.MinValue; - FileSize = -1; - - if (File.Exists(fileName)) - { - var fileInfo = new FileInfo(fileName); - LastModifiedDate = fileInfo.LastWriteTime; - FileSize = fileInfo.Length; - } - } - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/AndroidDeployAssetTask.cs b/sources/buildengine/Stride.Core.BuildEngine/AndroidDeployAssetTask.cs deleted file mode 100644 index e03dff8d17..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/AndroidDeployAssetTask.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using Microsoft.Build.Framework; -using Stride.Framework.Build.Storage; -using Stride.Framework.Diagnostics; - -namespace Stride.BuildTool -{ - public class AndroidDeployAssetTask : Microsoft.Build.Utilities.Task - { - public ITaskItem[] Files { get; set; } - - public string DeploymentPath { get; set; } - - public override bool Execute() - { - var logger = Logger.GetLogger("AndroidDeployAssetTask"); - - var fileMapping = new Dictionary(); - for (int i = 0; i < Files.Length; ++i) - { - fileMapping[Files[i].GetMetadata("TargetPath")] = Files[i].ItemSpec; - } - - var device = AndroidAdbUtilities.GetDevices().First(); - var externalStoragePath = AndroidAdbUtilities.GetExternalStoragePath(device); - AndroidAdbUtilities.Synchronize(logger, device, fileMapping, externalStoragePath + "/" + DeploymentPath, "android-cache-" + device + ".tmp"); - - return true; - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/BuildEngineCommands.cs b/sources/buildengine/Stride.Core.BuildEngine/BuildEngineCommands.cs deleted file mode 100644 index 592fcb0bbc..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/BuildEngineCommands.cs +++ /dev/null @@ -1,287 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.ServiceModel; - -using Mono.Options; -using Stride.Core.Storage; -using Stride.Core.Diagnostics; -using Stride.Core.IO; -using Stride.Core.MicroThreading; -using Stride.Core.Serialization; -using Stride.Core.Serialization.Assets; -using Stride.Core.Serialization.Contents; -using System.Threading; - -namespace Stride.Core.BuildEngine -{ - public static class BuildEngineCommands - { - public static BuildResultCode Build(BuilderOptions options) - { - BuildResultCode result; - - if (options.IsValidForSlave()) - { - // Sleeps one second so that debugger can attach - //Thread.Sleep(1000); - - result = BuildSlave(options); - } - else if (options.IsValidForMaster()) - { - result = BuildLocal(options); - - if (!string.IsNullOrWhiteSpace(options.OutputDirectory) && options.BuilderMode == Builder.Mode.Build) - { - CopyBuildToOutput(options); - } - } - else - { - throw new OptionException("Insufficient parameters, no action taken", "build-path"); - } - - return result; - } - - private static void PrepareDatabases(BuilderOptions options) - { - AssetManager.GetDatabaseFileProvider = () => IndexFileCommand.DatabaseFileProvider.Value; - } - - 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); - } - - private static void RegisterRemoteLogger(IProcessBuilderRemote processBuilderRemote) - { - // The pipe might be broken while we try to output log, so let's try/catch the call to prevent program for crashing here (it should crash at a proper location anyway if the pipe is broken/closed) - // ReSharper disable EmptyGeneralCatchClause - GlobalLogger.MessageLogged += msg => { try { processBuilderRemote.ForwardLog(msg); } catch { } }; - // ReSharper restore EmptyGeneralCatchClause - } - - public static BuildResultCode BuildSlave(BuilderOptions options) - { - // Mount build path - ((FileSystemProvider)VirtualFileSystem.ApplicationData).ChangeBasePath(options.BuildDirectory); - - PrepareDatabases(options); - - try - { - VirtualFileSystem.CreateDirectory("/data/"); - VirtualFileSystem.CreateDirectory("/data/db/"); - } - catch (Exception) - { - throw new OptionException("Invalid Build database path", "database"); - } - - // Open WCF channel with master builder - var namedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { SendTimeout = TimeSpan.FromSeconds(300.0) }; - var processBuilderRemote = ChannelFactory.CreateChannel(namedPipeBinding, new EndpointAddress(options.SlavePipe)); - - try - { - RegisterRemoteLogger(processBuilderRemote); - - // Create scheduler - var scheduler = new Scheduler(); - - var status = ResultStatus.NotProcessed; - - // Schedule command - string buildPath = options.BuildDirectory; - Logger logger = options.Logger; - MicroThread microthread = scheduler.Add(async () => - { - // Deserialize command and parameters - Command command = processBuilderRemote.GetCommandToExecute(); - BuildParameterCollection parameters = processBuilderRemote.GetBuildParameters(); - - // Run command - var inputHashes = new DictionaryStore(VirtualFileSystem.OpenStream("/data/db/InputHashes", VirtualFileMode.OpenOrCreate, VirtualFileAccess.ReadWrite, VirtualFileShare.ReadWrite)); - var builderContext = new BuilderContext(buildPath, inputHashes, parameters, 0, null); - - var commandContext = new RemoteCommandContext(processBuilderRemote, command, builderContext, logger); - command.PreCommand(commandContext); - status = await command.DoCommand(commandContext); - command.PostCommand(commandContext, status); - - // Returns result to master builder - processBuilderRemote.RegisterResult(commandContext.ResultEntry); - }); - - while (true) - { - scheduler.Run(); - - // Exit loop if no more micro threads - lock (scheduler.MicroThreads) - { - if (!scheduler.MicroThreads.Any()) - break; - } - - Thread.Sleep(0); - } - - // Rethrow any exception that happened in microthread - if (microthread.Exception != null) - { - options.Logger.Fatal(microthread.Exception.ToString()); - return BuildResultCode.BuildError; - } - - if (status == ResultStatus.Successful || status == ResultStatus.NotTriggeredWasSuccessful) - return BuildResultCode.Successful; - - return BuildResultCode.BuildError; - } - finally - { - // Close WCF channel - // ReSharper disable SuspiciousTypeConversion.Global - ((IClientChannel)processBuilderRemote).Close(); - // ReSharper restore SuspiciousTypeConversion.Global - } - } - - public static void CopyBuildToOutput(BuilderOptions options) - { - throw new InvalidOperationException(); - } - - private static void Collect(HashSet objectIds, ObjectId objectId, IAssetIndexMap assetIndexMap) - { - // Already added? - if (!objectIds.Add(objectId)) - return; - - using (var stream = AssetManager.FileProvider.OpenStream(DatabaseFileProvider.ObjectIdUrl + objectId, VirtualFileMode.Open, VirtualFileAccess.Read)) - { - // Read chunk header - var streamReader = new BinarySerializationReader(stream); - var header = ChunkHeader.Read(streamReader); - - // Only process chunks - if (header != null) - { - if (header.OffsetToReferences != -1) - { - // Seek to where references are stored and deserialize them - streamReader.NativeStream.Seek(header.OffsetToReferences, SeekOrigin.Begin); - - List references = null; - streamReader.Serialize(ref references, ArchiveMode.Deserialize); - - foreach (var reference in references) - { - ObjectId refObjectId; - var databaseFileProvider = DatabaseFileProvider.ResolveObjectId(reference.Location, out refObjectId); - if (databaseFileProvider != null) - { - Collect(objectIds, refObjectId, databaseFileProvider.AssetIndexMap); - } - } - } - } - } - } - - public static void Cancel(Builder builder, ConsoleCancelEventArgs e) - { - if (builder != null && builder.IsRunning) - { - e.Cancel = true; - builder.CancelBuild(); - } - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/BuilderOptions.cs b/sources/buildengine/Stride.Core.BuildEngine/BuilderOptions.cs deleted file mode 100644 index e666254fa0..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/BuilderOptions.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.Collections.Generic; -using System.IO; - -using Mono.Options; -using Stride.Core.Diagnostics; - -namespace Stride.Core.BuildEngine -{ - public class BuilderOptions - { - public readonly PluginResolver Plugins; - public readonly Logger Logger; - - public bool Verbose = false; - public bool Debug = false; - // This should not be a list - public List InputFiles = new List(); - public Builder.Mode BuilderMode; - public string BuildDirectory; - public List MonitorPipeNames = new List(); - public string OutputDirectory; - public string Configuration; - public bool EnableFileLogging; - public bool Append; - public string CustomLogFileName; - public string SourceBaseDirectory; - public string MetadataDatabaseDirectory; - public string SlavePipe; - - public int ThreadCount = Environment.ProcessorCount; - - public string TestName; - - public BuilderOptions(Logger logger) - { - Logger = logger; - Plugins = new PluginResolver(logger); - BuilderMode = Builder.Mode.Build; - } - - /// - /// This function indicate if the current builder options mean to execute a master session - /// - /// true if the options mean to execute a master session - public bool IsValidForMaster() - { - return InputFiles.Count == 1; - } - - /// - /// This function indicate if the current builder options mean to execute a slave session - /// - /// true if the options mean to execute a slave session - public bool IsValidForSlave() - { - return !string.IsNullOrEmpty(SlavePipe) && !string.IsNullOrEmpty(BuildDirectory); - } - - /// - /// Ensure every parameter is correct for a master execution. Throw an OptionException if a parameter is wrong - /// - /// This tool requires one input file.;filename - /// or - /// The given working directory \ + workingDir + \ does not exist.;workingdir - public void ValidateOptionsForMaster() - { - if (InputFiles.Count != 1) - throw new OptionException("This tool requires one input file.", "filename"); - - if (SourceBaseDirectory != null) - { - if (!Directory.Exists(SourceBaseDirectory)) - throw new OptionException("The given working directory does not exist.", "workingdir"); - } - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/PluginManager.cs b/sources/buildengine/Stride.Core.BuildEngine/PluginManager.cs deleted file mode 100644 index 203f453005..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/PluginManager.cs +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Stride.Core.Diagnostics; - -namespace Stride.Core.BuildEngine -{ - public class PluginManager - { - public IEnumerable PluginAssemblyLocations { get { return pluginAssemblyLocations; } } - - private readonly List pluginAssemblyLocations = new List(); - - private readonly Logger logger; - - public PluginManager(Logger logger = null) - { - this.logger = logger; - } - - public void Register() - { - AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => LoadAssembly(new AssemblyName(e.Name)); - } - - public Assembly LoadAssembly(AssemblyName assemblyName) - { - return LoadAssembly(assemblyName.Name); - } - - public Assembly LoadAssembly(string assemblyName) - { - foreach (string pluginLocation in pluginAssemblyLocations) - { - if (pluginLocation != assemblyName) - { - string fileName = Path.GetFileNameWithoutExtension(pluginLocation); - if (fileName != assemblyName) - continue; - } - - if (logger != null) - logger.Debug("Loading plugin: {0}", pluginLocation); - return Assembly.LoadFrom(pluginLocation); - } - return null; - } - - public string FindAssembly(string assemblyFileName) - { - foreach (string pluginLocation in pluginAssemblyLocations) - { - if (pluginLocation != assemblyFileName) - { - string fileName = Path.GetFileName(pluginLocation); - if (fileName != assemblyFileName) - continue; - } - - if (logger != null) - logger.Debug("Loading plugin: {0}", pluginLocation); - return pluginLocation; - } - return null; - } - - public void AddPlugin(string filePath) - { - pluginAssemblyLocations.Add(filePath); - } - - public void AddPluginFolder(string folder) - { - if (!Directory.Exists(folder)) - return; - - foreach (string filePath in Directory.EnumerateFiles(folder, "*.dll")) - { - if (logger != null) - logger.Debug("Detected plugin: {0}", Path.GetFileNameWithoutExtension(filePath)); - pluginAssemblyLocations.Add(filePath); - } - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/Program.cs b/sources/buildengine/Stride.Core.BuildEngine/Program.cs deleted file mode 100644 index e8205a7f00..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/Program.cs +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. - -using System; -using System.IO; -using Mono.Options; -using System.Reflection; -using System.Text; -using System.Diagnostics; -using Stride.Core.Diagnostics; - -namespace Stride.Core.BuildEngine -{ - class Program - { - private static string FormatLog(LogMessage message) - { - var builder = new StringBuilder(); - TimeSpan timestamp = DateTime.Now - Process.GetCurrentProcess().StartTime; - builder.Append((timestamp.TotalMilliseconds * 0.001).ToString("0.000 ")); - builder.Append(message.Module); - builder.Append(": "); - builder.Append(message.Text); - return builder.ToString(); - } - - private static int Main(string[] args) - { - var exeName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); - var showHelp = false; - var options = new BuilderOptions(Logger.GetLogger("BuildEngine")); - - var p = new OptionSet - { - "Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) All Rights Reserved", - "Stride Build Tool - Version: " - + - String.Format( - "{0}.{1}.{2}", - typeof(Program).Assembly.GetName().Version.Major, - typeof(Program).Assembly.GetName().Version.Minor, - typeof(Program).Assembly.GetName().Version.Build) + string.Empty, - string.Format("Usage: {0} [options]* inputfile -o outputfile", exeName), - string.Empty, - "=== Options ===", - string.Empty, - { "h|help", "Show this message and exit", v => showHelp = v != null }, - { "v|verbose", "Show more verbose progress logs", v => options.Verbose = v != null }, - { "d|debug", "Show debug logs (imply verbose)", v => options.Debug = v != null }, - { "c|clean", "Clean the command cache, forcing to rebuild everything at the next build.", v => options.BuilderMode = Builder.Mode.Clean }, - { "cd|clean-delete", "Clean the command cache and delete output objects", v => options.BuilderMode = Builder.Mode.CleanAndDelete }, - { "b|build-path=", "Build path", v => options.BuildDirectory = v }, - { "mdb|metadata-database=", "Optional ; indicate the directory containing the Metadata database, if used.", v => { if (!string.IsNullOrEmpty(v)) options.MetadataDatabaseDirectory = v; } }, - { "o|output-path=", "Optional ; indicate an output path to copy the built assets in.", v => options.OutputDirectory = v }, - { "cfg|config=", "Configuration name", v => options.Configuration = v }, - { "log", "Enable file logging", v => options.EnableFileLogging = v != null }, - { "log-file=", "Log build in a custom file.", v => - { - options.EnableFileLogging = v != null; - options.CustomLogFileName = v; - } }, - { "monitor-pipe=", "Monitor pipe.", v => - { - if (!string.IsNullOrEmpty(v)) - options.MonitorPipeNames.Add(v); - } }, - { "slave=", "Slave pipe", v => options.SlavePipe = v }, // Benlitz: I don't think this should be documented - { "s|sourcebase=", "Optional ; Set the base directory for the source files. Not required if all source paths are absolute", v => options.SourceBaseDirectory = v }, - { "a|append", "If set, the existing asset mappings won't be deleted.", v => options.Append = v != null }, - { "t|threads=", "Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) }, - { "p|plugin=", "Add plugin directory.", v => - { - if (!string.IsNullOrEmpty(v)) - options.Plugins.AddPluginFolder(v); - } }, - { "test=", "Run a test session.", v => options.TestName = v } - }; - - TextWriterLogListener fileLogListener = null; - - // Output logs to the console with colored messages - if (options.SlavePipe == null) - { - var consoleLogListener = new ConsoleLogListener { TextFormatter = FormatLog }; - GlobalLogger.MessageLogged += consoleLogListener; - } - - // Setting up plugin manager - options.Plugins.AddPluginFolder(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? "", "BuildPlugins")); - options.Plugins.Register(); - - BuildResultCode exitCode; - - try - { - options.InputFiles = p.Parse(args); - - // Also write logs from master process into a file - if (options.SlavePipe == null) - { - if (options.EnableFileLogging) - { - string logFileName = options.CustomLogFileName; - if (string.IsNullOrEmpty(logFileName)) - { - string inputName = "NoInput"; - if (options.InputFiles.Count > 0) - inputName = Path.GetFileNameWithoutExtension(options.InputFiles[0]); - - logFileName = "Logs/Build-" + inputName + "-" + DateTime.Now.ToString("yy-MM-dd-HH-mm") + ".txt"; - } - - string dirName = Path.GetDirectoryName(logFileName); - if (dirName != null) - Directory.CreateDirectory(dirName); - - fileLogListener = new TextWriterLogListener(new FileStream(logFileName, FileMode.Create)) { TextFormatter = FormatLog }; - GlobalLogger.MessageLogged += fileLogListener; - } - options.Logger.Info("BuildEngine arguments: " + string.Join(" ", args)); - options.Logger.Info("Starting builder."); - } - - if (showHelp) - { - p.WriteOptionDescriptions(Console.Out); - exitCode = BuildResultCode.Successful; - } - else if (!string.IsNullOrEmpty(options.TestName)) - { - var test = new TestSession(); - test.RunTest(options.TestName, options.Logger); - exitCode = BuildResultCode.Successful; - } - else - { - exitCode = BuildEngineCommands.Build(options); - } - } - catch (OptionException e) - { - options.Logger.Error("{0}", e); - exitCode = BuildResultCode.CommandLineError; - } - catch (Exception e) - { - options.Logger.Error("{0}", e); - exitCode = BuildResultCode.BuildError; - } - finally - { - if (fileLogListener != null) - fileLogListener.LogWriter.Close(); - - } - return (int)exitCode; - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/Properties/AssemblyInfo.cs b/sources/buildengine/Stride.Core.BuildEngine/Properties/AssemblyInfo.cs deleted file mode 100644 index 8edd158206..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -#if !DEBUG -[assembly: ObfuscateAssembly(false)] -[assembly: Obfuscation(Feature = "embed Stride.Effects.Modules.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed Stride.Engine.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed Stride.Framework.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed Stride.Framework.Graphics.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed Stride.Importer.FBX.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed Stride.Importer.Assimp.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed Mono.Options.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.D3DCompiler.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.DXGI.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.Direct3D11.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.DirectInput.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.RawInput.dll", Exclude = false)] -[assembly: Obfuscation(Feature = "embed SharpDX.XInput.dll", Exclude = false)] -#endif - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("bc6f5b23-4e4b-49e6-b9bd-c090076fd732")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/sources/buildengine/Stride.Core.BuildEngine/RemoteCommandContext.cs b/sources/buildengine/Stride.Core.BuildEngine/RemoteCommandContext.cs deleted file mode 100644 index 8753a10f7e..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/RemoteCommandContext.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Stride.Core.Diagnostics; -using Stride.Core.Serialization.Assets; -using Stride.Core.Storage; - -namespace Stride.Core.BuildEngine -{ - public class RemoteCommandContext : CommandContextBase - { - public override Logger Logger { get { return logger; } } - - internal new CommandResultEntry ResultEntry { get { return base.ResultEntry; } } - - private readonly Logger logger; - private readonly IProcessBuilderRemote processBuilderRemote; - - public RemoteCommandContext(IProcessBuilderRemote processBuilderRemote, Command command, BuilderContext builderContext, Logger logger) : base(command, builderContext) - { - this.processBuilderRemote = processBuilderRemote; - this.logger = logger; - } - - public override IEnumerable> GetOutputObjectsGroups() - { - yield return processBuilderRemote.GetOutputObjects().ToDictionary(x => x.Key, x => new OutputObject(x.Key, x.Value)); - } - - protected override Task ScheduleAndExecuteCommandInternal(Command command) - { - // Send serialized command - return processBuilderRemote.SpawnCommand(command); - } - - protected override ObjectId ComputeInputHash(UrlType type, string filePath) - { - return processBuilderRemote.ComputeInputHash(type, filePath); - } - } -} diff --git a/sources/buildengine/Stride.Core.BuildEngine/Stride.Core.BuildEngine.csproj b/sources/buildengine/Stride.Core.BuildEngine/Stride.Core.BuildEngine.csproj deleted file mode 100644 index ba708c6406..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/Stride.Core.BuildEngine.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - Windows - - - - 8.0.30703 - 2.0 - Exe - x86 - true - $(StrideEditorTargetFramework) - --auto-module-initializer --serialization - - - AnyCPU - - - - - - - - - - - - - \ No newline at end of file diff --git a/sources/buildengine/Stride.Core.BuildEngine/TestSession.cs b/sources/buildengine/Stride.Core.BuildEngine/TestSession.cs deleted file mode 100644 index 5bbd74489c..0000000000 --- a/sources/buildengine/Stride.Core.BuildEngine/TestSession.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -using Stride.Core.Diagnostics; -using Stride.Core.IO; -using Stride.Core.Serialization; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Threading.Tasks; - -namespace Stride.Core.BuildEngine -{ - public class DoNothingCommand : Command - { - /// - public override string Title { get { return "Do nothing!"; } } - - private static int commandCounter; - private readonly int commandId; - - protected override Task DoCommandOverride(ICommandContext commandContext) - { - return Task.Run(() => ResultStatus.Successful); - } - - public static void ResetCounter() - { - commandCounter = 0; - } - - public DoNothingCommand() - { - commandId = ++commandCounter; - } - - public override string ToString() - { - return GetType().Name + " " + commandId; - } - - protected override void ComputeParameterHash(Stream stream) - { - base.ComputeParameterHash(stream); - - var writer = new BinarySerializationWriter(stream); - writer.Write(commandId); - } - } - - public class TestSession - { - public void RunTest(string testName, Logger logger) - { - foreach (MethodInfo method in typeof(TestSession).GetMethods()) - { - if (method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(Logger)) - { - if (string.Compare(method.Name, testName, StringComparison.OrdinalIgnoreCase) == 0) - method.Invoke(this, new object[] { logger }); - } - } - } - - //private static PluginResolver pluginManager; - private static void BuildStepsRecursively(Builder builder, ICollection 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); - } - } - - 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("TestBuilder", appPath, Builder.Mode.Build, logger); - var steps = new List(); - 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(); - logger.ActivateLog(LogMessageType.Debug); - logger.Info("Build finished (logger re-enabled)"); - - foreach (BuildStep step in steps) - { - Debug.Assert(step.Status == ResultStatus.Successful); - } - } - - } -}