Esempio n. 1
0
 public static BuildScript LoadFromFile(string xenkoSdkDir, string filePath)
 {
     var script = new BuildScript(xenkoSdkDir) { ScriptPath = filePath, source = File.ReadAllText(filePath) };
     return script;
 }
        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));
        }