public override bool Execute() { this.LogMessage( "Starting clean of projects for " + this.Platform); var module = ModuleInfo.Load(Path.Combine(this.RootPath, "Build", "Module.xml")); var definitions = module.GetDefinitionsRecursively(this.Platform).ToArray(); // Run Protobuild in batch mode in each of the submodules // where it is present. foreach (var submodule in module.GetSubmodules(Platform)) { _moduleExecution.RunProtobuild( submodule, _featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule) + "-clean " + Platform); } foreach (var definition in definitions.Select(x => x.Name)) { this.LogMessage("Cleaning: " + definition); var projectDoc = new XmlDocument(); projectDoc.Load(Path.Combine( this.SourcePath, definition + ".definition")); if (projectDoc == null || projectDoc.DocumentElement.Name != "Project") { continue; } var path = Path.Combine( this.RootPath, projectDoc.DocumentElement.Attributes["Path"].Value .Replace('\\', Path.DirectorySeparatorChar) .Replace('/', Path.DirectorySeparatorChar), projectDoc.DocumentElement.Attributes["Name"].Value + "." + this.Platform + ".csproj"); if (File.Exists(path)) { File.Delete(path); } } var solution = Path.Combine( this.RootPath, this.ModuleName + "." + this.Platform + ".sln"); this.LogMessage("Cleaning: (solution)"); if (File.Exists(solution)) { File.Delete(solution); } this.LogMessage( "Clean complete."); return(true); }
public override bool Execute() { this.LogMessage( "Synchronising projects for " + this.Platform); var module = ModuleInfo.Load(Path.Combine(this.RootPath, "Build", "Module.xml")); // Run Protobuild in batch mode in each of the submodules // where it is present. foreach (var submodule in module.GetSubmodules(this.Platform)) { if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.OptimizationSkipSynchronisationOnNoStandardProjects)) { if (submodule.GetDefinitionsRecursively(this.Platform).All(x => !x.IsStandardProject)) { // Do not invoke this submodule. this.LogMessage( "Skipping submodule synchronisation for " + submodule.Name + " (there are no projects to synchronise)"); continue; } } this.LogMessage( "Invoking submodule synchronisation for " + submodule.Name); _moduleExecution.RunProtobuild( submodule, _featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule) + "-sync " + this.Platform); this.LogMessage( "Finished submodule synchronisation for " + submodule.Name); } var definitions = module.GetDefinitions(); foreach (var definition in definitions) { if (definition.Type == "External" || definition.Type == "Content" || definition.RelativePath == null) { continue; } // Read the project file in. var path = Path.Combine(module.Path, definition.RelativePath, definition.Name + "." + this.Platform + ".csproj"); if (File.Exists(path)) { this.LogMessage("Synchronising: " + definition.Name); var project = CSharpProject.Load(path); var synchroniser = new DefinitionSynchroniser(module, definition, project); synchroniser.Synchronise(this.Platform); } } this.LogMessage( "Synchronisation complete."); return(true); }
public void ResolveAll(ModuleInfo module, string platform) { if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement)) { return; } Console.WriteLine("Starting resolution of packages for " + platform + "..."); if (module.Packages != null && module.Packages.Count > 0) { foreach (var submodule in module.Packages) { if (submodule.IsActiveForPlatform(platform)) { Console.WriteLine("Resolving: " + submodule.Uri); this.Resolve(module, submodule, platform, null, null); } else { Console.WriteLine("Skipping resolution for " + submodule.Uri + " because it is not active for this target platform"); } } } foreach (var submodule in module.GetSubmodules(platform)) { if (submodule.Packages.Count == 0 && submodule.GetSubmodules(platform).Length == 0) { if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.OptimizationSkipResolutionOnNoPackagesOrSubmodules)) { Console.WriteLine( "Skipping package resolution in submodule for " + submodule.Name + " (there are no submodule or packages)"); continue; } } Console.WriteLine( "Invoking package resolution in submodule for " + submodule.Name); _moduleExecution.RunProtobuild( submodule, _featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule) + "-resolve " + platform + " " + packageRedirector.GetRedirectionArguments()); Console.WriteLine( "Finished submodule package resolution for " + submodule.Name); } Console.WriteLine("Package resolution complete."); }
public void ResolveAll(string workingDirectory, ModuleInfo module, string platform, bool?enableParallelisation, bool forceUpgrade, bool?safeResolve) { if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement)) { return; } RedirectableConsole.WriteLine("Starting resolution of packages for " + platform + "..."); var parallelisation = enableParallelisation ?? _hostPlatformDetector.DetectPlatform() == "Windows"; if (parallelisation) { RedirectableConsole.WriteLine("Enabled parallelisation; use --no-parallel to disable..."); } if (module.Packages != null && module.Packages.Count > 0) { var taskList = new List <Task <Tuple <string, Action> > >(); var resultList = new List <Tuple <string, Action> >(); foreach (var submodule in module.Packages) { if (submodule.IsActiveForPlatform(platform)) { RedirectableConsole.WriteLine("Querying: " + submodule.Uri); var submodule1 = submodule; if (parallelisation) { var task = new Func <Task <Tuple <string, Action> > >(async() => { var metadata = await Task.Run(() => Lookup(workingDirectory, module, submodule1, platform, null, null, forceUpgrade, safeResolve)); if (metadata == null) { return(new Tuple <string, Action>(submodule1.Uri, () => { })); } return(new Tuple <string, Action>(submodule1.Uri, () => { this.Resolve(workingDirectory, metadata, submodule1, null, null, forceUpgrade, safeResolve); })); }); taskList.Add(task()); } else { var metadata = Lookup(workingDirectory, module, submodule1, platform, null, null, forceUpgrade, safeResolve); if (metadata == null) { resultList.Add(new Tuple <string, Action>(submodule1.Uri, () => { })); } else { resultList.Add(new Tuple <string, Action>(submodule1.Uri, () => { this.Resolve(workingDirectory, metadata, submodule1, null, null, forceUpgrade, safeResolve); })); } } } else { RedirectableConsole.WriteLine("Skipping resolution for " + submodule.Uri + " because it is not active for this target platform"); } } if (parallelisation) { var taskArray = taskList.ToArray(); Task.WaitAll(taskArray); foreach (var tuple in taskArray) { RedirectableConsole.WriteLine("Resolving: " + tuple.Result.Item1); tuple.Result.Item2(); } } else { foreach (var tuple in resultList) { RedirectableConsole.WriteLine("Resolving: " + tuple.Item1); tuple.Item2(); } } } foreach (var submodule in module.GetSubmodules(platform)) { if (submodule.Packages.Count == 0 && submodule.GetSubmodules(platform).Length == 0) { if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.OptimizationSkipResolutionOnNoPackagesOrSubmodules)) { RedirectableConsole.WriteLine( "Skipping package resolution in submodule for " + submodule.Name + " (there are no submodule or packages)"); continue; } } RedirectableConsole.WriteLine( "Invoking package resolution in submodule for " + submodule.Name); string parallelMode = null; if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.TaskParallelisation)) { if (parallelisation) { parallelMode += "-parallel "; } else { parallelMode += "-no-parallel "; } } _moduleExecution.RunProtobuild( submodule, _featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule) + parallelMode + "-resolve " + platform + " " + packageRedirector.GetRedirectionArguments()); RedirectableConsole.WriteLine( "Finished submodule package resolution for " + submodule.Name); } RedirectableConsole.WriteLine("Package resolution complete."); }
public override bool Execute() { if (string.Compare(Platform, "Web", StringComparison.InvariantCultureIgnoreCase) == 0) { // Trigger JSIL provider download if needed. string jsilDirectory, jsilCompilerFile; if (!m_JSILProvider.GetJSIL(out jsilDirectory, out jsilCompilerFile)) { return(false); } } var module = ModuleInfo.Load(Path.Combine(RootPath, "Build", "Module.xml")); LogMessage( "Starting generation of projects for " + Platform); var definitions = module.GetDefinitionsRecursively(Platform).ToArray(); var loadedProjects = new List <LoadedDefinitionInfo>(); if (_hostPlatformDetector.DetectPlatform() == "Windows") { var concurrentProjects = new ConcurrentBag <LoadedDefinitionInfo>(); Parallel.ForEach(definitions, definition => { LogMessage("Loading: " + definition.Name); concurrentProjects.Add( m_ProjectLoader.Load( Platform, module, definition)); }); // Do this so we maintain order with the original definitions list. foreach (var definition in definitions) { var loadedProject = concurrentProjects.FirstOrDefault(x => x.Definition == definition); if (loadedProject != null) { loadedProjects.Add(loadedProject); } } } else { foreach (var definition in definitions) { LogMessage("Loading: " + definition.Name); loadedProjects.Add( m_ProjectLoader.Load( Platform, module, definition)); } } var serviceManager = new ServiceManager(Platform); List <Service> services; TemporaryServiceSpec serviceSpecPath; if (ServiceSpecPath == null) { serviceManager.SetRootDefinitions(module.GetDefinitions()); if (EnableServices == null) { EnableServices = new string[0]; } if (DisableServices == null) { DisableServices = new string[0]; } foreach (var service in EnableServices) { serviceManager.EnableService(service); } foreach (var service in DisableServices) { serviceManager.DisableService(service); } if (DebugServiceResolution) { serviceManager.EnableDebugInformation(); } try { services = serviceManager.CalculateDependencyGraph(loadedProjects.Select(x => x.Project).ToList()); } catch (InvalidOperationException ex) { RedirectableConsole.WriteLine("Error during service resolution: " + ex.Message); return(false); } serviceSpecPath = serviceManager.SaveServiceSpec(services); foreach (var service in services) { if (service.ServiceName != null) { LogMessage("Enabled service: " + service.FullName); } } } else { services = serviceManager.LoadServiceSpec(ServiceSpecPath); serviceSpecPath = new TemporaryServiceSpec(ServiceSpecPath, true); } using (serviceSpecPath) { var submodulesToProcess = new List <ModuleInfo>(); var allSubmodules = module.GetSubmodules(Platform); if (_hostPlatformDetector.DetectPlatform() == "Windows") { var concurrentSubmodulesToProcess = new ConcurrentBag <ModuleInfo>(); Parallel.ForEach(allSubmodules, submodule => { if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.OptimizationSkipInvocationOnNoStandardProjects)) { if (submodule.GetDefinitionsRecursively(Platform).All(x => !x.IsStandardProject)) { // Do not invoke this submodule. LogMessage( "Skipping submodule generation for " + submodule.Name + " (there are no projects to generate)"); } else { concurrentSubmodulesToProcess.Add(submodule); } } }); // Do this so we maintain order with the original GetSubmodules list. foreach (var submodule in allSubmodules) { if (concurrentSubmodulesToProcess.Contains(submodule)) { submodulesToProcess.Add(submodule); } } } else { foreach (var submodule in module.GetSubmodules(Platform)) { if (_featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.OptimizationSkipInvocationOnNoStandardProjects)) { if (submodule.GetDefinitionsRecursively(Platform).All(x => !x.IsStandardProject)) { // Do not invoke this submodule. LogMessage( "Skipping submodule generation for " + submodule.Name + " (there are no projects to generate)"); } else { submodulesToProcess.Add(submodule); } } } } // Run Protobuild in batch mode in each of the submodules // where it is present. foreach (var submodule in submodulesToProcess) { LogMessage( "Invoking submodule generation for " + submodule.Name); var noResolve = _featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.PackageManagementNoResolve) ? " -no-resolve" : string.Empty; var noHostPlatform = DisableHostPlatformGeneration && _featureManager.IsFeatureEnabledInSubmodule(module, submodule, Feature.NoHostGenerate) ? " -no-host-generate" : string.Empty; _moduleExecution.RunProtobuild( submodule, _featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule) + "-generate " + Platform + " -spec " + serviceSpecPath + " " + m_PackageRedirector.GetRedirectionArguments() + noResolve + noHostPlatform); LogMessage( "Finished submodule generation for " + submodule.Name); } var repositoryPaths = new List <string>(); if (_hostPlatformDetector.DetectPlatform() == "Windows") { var concurrentRepositoryPaths = new ConcurrentBag <string>(); Parallel.ForEach(definitions.Where(x => x.ModulePath == module.Path), definition => { if (definition.PostBuildHook && RequiresHostPlatform != null) { // We require the host platform projects at this point. RequiresHostPlatform(); } string repositoryPath; var definitionCopy = definition; m_ProjectGenerator.Generate( definition, loadedProjects, WorkingDirectory, RootPath, definition.Name, Platform, services, out repositoryPath, () => LogMessage("Generating: " + definitionCopy.Name), DebugProjectGeneration); // Only add repository paths if they should be generated. if (module.GenerateNuGetRepositories && !string.IsNullOrEmpty(repositoryPath)) { concurrentRepositoryPaths.Add(repositoryPath); } }); repositoryPaths = concurrentRepositoryPaths.ToList(); } else { foreach (var definition in definitions.Where(x => x.ModulePath == module.Path)) { if (definition.PostBuildHook && RequiresHostPlatform != null) { // We require the host platform projects at this point. RequiresHostPlatform(); } string repositoryPath; var definitionCopy = definition; m_ProjectGenerator.Generate( definition, loadedProjects, WorkingDirectory, RootPath, definition.Name, Platform, services, out repositoryPath, () => LogMessage("Generating: " + definitionCopy.Name), DebugProjectGeneration); // Only add repository paths if they should be generated. if (module.GenerateNuGetRepositories && !string.IsNullOrEmpty(repositoryPath)) { repositoryPaths.Add(repositoryPath); } } } var solution = Path.Combine( RootPath, ModuleName + "." + Platform + ".sln"); LogMessage("Generating: (solution)"); m_SolutionGenerator.Generate( WorkingDirectory, module, loadedProjects.Select(x => x.Project).ToList(), Platform, solution, services, repositoryPaths, DebugProjectGeneration); // Only save the specification cache if we allow synchronisation if (module.DisableSynchronisation == null || !module.DisableSynchronisation.Value) { var serviceCache = Path.Combine(RootPath, ModuleName + "." + Platform + ".speccache"); LogMessage("Saving service specification"); File.Copy(serviceSpecPath.Path, serviceCache, true); } LogMessage( "Generation complete."); } return(true); }