public int Execute(Execution execution)
        {
            var url    = execution.PackageUrl;
            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.Packages == null)
            {
                module.Packages = new List <PackageRef>();
            }

            var packageRef = _packageUrlParser.Parse(url);

            foreach (var package in module.Packages.ToArray())
            {
                if (package.Uri == packageRef.Uri)
                {
                    RedirectableConsole.WriteLine("Removing " + package.Uri + "...");
                    module.Packages.Remove(package);

                    // Save after each package remove in case something goes wrong deleting
                    // the directory.
                    module.Save(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

                    if (Directory.Exists(Path.Combine(module.Path, package.Folder)))
                    {
                        RedirectableConsole.WriteLine("Deleting folder '" + package.Folder + "'...");
                        PathUtils.AggressiveDirectoryDelete(Path.Combine(module.Path, package.Folder));
                    }
                }
            }

            return(0);
        }
Example #2
0
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml")))
            {
                _knownToolProvider.GetToolExecutablePath("Protobuild.Manager");

                var subexecution = new Execution();
                subexecution.WorkingDirectory        = execution.WorkingDirectory;
                subexecution.ExecuteProjectName      = "Protobuild.Manager";
                subexecution.ExecuteProjectArguments = new string[0];

                return(_executeCommand.Execute(subexecution));
            }

            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.DefaultAction == "automated-build")
            {
                return(_automatedBuildController.Execute(execution.WorkingDirectory, "automated.build"));
            }

            return(this.m_ActionDispatch.DefaultAction(
                       execution.WorkingDirectory,
                       module,
                       null,
                       execution.EnabledServices.ToArray(),
                       execution.DisabledServices.ToArray(),
                       execution.ServiceSpecificationPath,
                       execution.DebugServiceResolution,
                       execution.DisablePackageResolution,
                       execution.DisableHostProjectGeneration,
                       execution.UseTaskParallelisation,
                       execution.SafePackageResolution,
                       execution.DebugProjectGeneration) ? 0 : 1);
        }
        public int Execute(Execution execution)
        {
            var url    = execution.PackageUrl;
            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.Packages == null)
            {
                module.Packages = new List <PackageRef>();
            }

            var package = _packageUrlParser.Parse(url);

            if (module.Packages.Any(x => x.Uri == package.Uri))
            {
                RedirectableConsole.WriteLine("WARNING: Package with URI " + package.Uri + " is already present; ignoring request to add package.");
                return(0);
            }

            if (Directory.Exists(Path.Combine(module.Path, package.Folder)))
            {
                throw new InvalidOperationException(package.Folder + " already exists");
            }

            RedirectableConsole.WriteLine("Adding " + package.Uri + " as " + package.Folder + "...");
            module.Packages.Add(package);
            module.Save(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            return(0);
        }
Example #4
0
        public ModuleInfo[] GetSubmodules()
        {
            var modules = new List <ModuleInfo>();

            foreach (var directory in new DirectoryInfo(Path).GetDirectories())
            {
                var link = directory.GetFiles().FirstOrDefault(x => x.Name == "Link.xml");
                if (link != null)
                {
                    modules.AddRange(GetLinkedModules(link));
                }

                var build = directory.GetDirectories().FirstOrDefault(x => x.Name == "Build");
                if (build == null)
                {
                    continue;
                }
                var module = build.GetFiles().FirstOrDefault(x => x.Name == "Module.xml");
                if (module == null)
                {
                    continue;
                }
                modules.Add(ModuleInfo.Load(module.FullName));
            }
            return(modules.ToArray());
        }
Example #5
0
        private string CheckAbove(string modulePath, PackageRef package)
        {
            var module = ModuleInfo.Load(Path.Combine(modulePath, "Build", "Module.xml"));
            var found  = module.Packages.Select(x => (PackageRef?)x)
                         .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0);

            if (found != null)
            {
                return(Path.Combine(modulePath, found.Value.Folder));
            }

            var parent = this.GetParentModule(modulePath);

            if (parent != null)
            {
                var above = this.CheckAbove(parent, package);
                if (above != null)
                {
                    return(above);
                }

                var directoryName = new DirectoryInfo(modulePath).Name;
                var across        = this.CheckAcross(parent, package, directoryName);
                if (across != null)
                {
                    return(across);
                }
            }

            return(null);
        }
Example #6
0
        public int Execute(Execution execution)
        {
            if (Directory.Exists(Path.Combine(execution.WorkingDirectory, "Build")))
            {
                var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));
                return(this.m_ActionDispatch.PerformAction(
                           execution.WorkingDirectory,
                           module,
                           "resync",
                           execution.Platform,
                           execution.EnabledServices.ToArray(),
                           execution.DisabledServices.ToArray(),
                           execution.ServiceSpecificationPath,
                           execution.DebugServiceResolution,
                           execution.DisablePackageResolution,
                           execution.DisableHostProjectGeneration,
                           execution.UseTaskParallelisation,
                           execution.SafePackageResolution,
                           execution.DebugProjectGeneration)
                    ? 0
                    : 1);
            }

            return(1);
        }
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml")))
            {
                throw new InvalidOperationException("No module present.");
            }

            var platform = execution.Platform ?? this.m_HostPlatformDetector.DetectPlatform();
            var module   = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            var done = false;

            foreach (var submodule in module.Packages)
            {
                if (submodule.Uri == execution.PackageUrl)
                {
                    RedirectableConsole.WriteLine("Switching to binary: " + submodule.Uri);
                    this.m_PackageManager.Resolve(execution.WorkingDirectory, module, submodule, platform, null, false, false, execution.SafePackageResolution);
                    done = true;
                    break;
                }
            }

            if (!done)
            {
                RedirectableConsole.WriteLine("No package registered with URL " + execution.PackageUrl);
                return(1);
            }

            return(0);
        }
Example #8
0
        public int Execute(Execution execution)
        {
            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.Packages == null)
            {
                throw new InvalidOperationException("No such package has been added");
            }

            var package = _packageUrlParser.Parse(execution.PackageUrl);

            var packageRef = _packageNameLookup.LookupPackageByName(module, package.Uri);

            _packageManager.Resolve(
                execution.WorkingDirectory,
                module,
                packageRef,
                execution.Platform ?? _hostPlatformDetector.DetectPlatform(),
                null,
                null,
                true,
                execution.SafePackageResolution);

            return(0);
        }
Example #9
0
        public int Execute(Execution execution)
        {
            var url    = execution.PackageUrl;
            var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));

            if (module.Packages == null)
            {
                throw new InvalidOperationException("No such package has been added");
            }

            var branch = "master";

            if (url.LastIndexOf('@') > url.LastIndexOf('/'))
            {
                // A branch / commit ref is specified.
                branch = url.Substring(url.LastIndexOf('@') + 1);
                url    = url.Substring(0, url.LastIndexOf('@'));
            }

            var packageRef = _packageNameLookup.LookupPackageByName(module, url);

            _packageManager.Resolve(
                module,
                packageRef,
                execution.Platform ?? _hostPlatformDetector.DetectPlatform(),
                null,
                null,
                true);

            return(0);
        }
        private string CheckAcross(string modulePath, PackageRef package, string originalDirectoryName, string platform)
        {
            var directory = new DirectoryInfo(modulePath);

            foreach (var subdirectory in directory.GetDirectories())
            {
                if (string.Compare(subdirectory.Name, originalDirectoryName, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    // This directory is either the original directory or
                    // a directory with a later alphabetical order.  We ignore
                    // it (this is how we resolve whether A should use B's package
                    // or B should use A's package).
                    continue;
                }

                if (File.Exists(Path.Combine(subdirectory.FullName, "Build", "Module.xml")))
                {
                    var module = ModuleInfo.Load(Path.Combine(subdirectory.FullName, "Build", "Module.xml"));
                    var found  = module.Packages.Select(x => (PackageRef?)x)
                                 .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0);
                    if (found != null)
                    {
                        return(Path.Combine(subdirectory.FullName, found.Value.Folder));
                    }

                    var submodules = module.GetSubmodules();
                    foreach (var submodule in submodules)
                    {
                        var below = this.CheckBelow(submodule.Path, package, platform);
                        if (below != null)
                        {
                            return(below);
                        }
                    }
                }

                if (File.Exists(Path.Combine(subdirectory.FullName, platform, "Build", "Module.xml")))
                {
                    var module = ModuleInfo.Load(Path.Combine(subdirectory.FullName, platform, "Build", "Module.xml"));
                    var found  = module.Packages.Select(x => (PackageRef?)x)
                                 .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0);
                    if (found != null)
                    {
                        return(Path.Combine(subdirectory.FullName, platform, found.Value.Folder));
                    }

                    var submodules = module.GetSubmodules();
                    foreach (var submodule in submodules)
                    {
                        var below = this.CheckBelow(submodule.Path, package, platform);
                        if (below != null)
                        {
                            return(below);
                        }
                    }
                }
            }

            return(null);
        }
Example #11
0
        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())
            {
                submodule.RunProtobuild("-sync " + this.Platform);
            }

            var definitions = module.GetDefinitions();

            foreach (var definition in definitions)
            {
                // Read the project file in.
                var path = Path.Combine(module.Path, definition.Name, definition.Name + "." + this.Platform + ".csproj");
                if (File.Exists(path))
                {
                    this.LogMessage("Synchronising: " + definition.Name);
                    var project      = CSharpProject.Load(path);
                    var synchroniser = new DefinitionSynchroniser(definition, project);
                    synchroniser.Synchronise(this.Platform);
                }
            }

            this.LogMessage(
                "Synchronisation complete.");

            return(true);
        }
 public void LoadFeaturesFromSpecificModule(string path)
 {
     if (File.Exists(path))
     {
         LoadFeaturesFromSpecificModule(ModuleInfo.Load(path));
     }
 }
        public int Execute(Execution execution)
        {
            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.Packages == null)
            {
                return(0);
            }

            var platform = execution.Platform ?? _hostPlatformDetector.DetectPlatform();

            foreach (var package in module.Packages)
            {
                _packageManager.Resolve(
                    execution.WorkingDirectory,
                    module,
                    package,
                    platform,
                    null,
                    null,
                    true,
                    execution.SafePackageResolution);
            }

            return(0);
        }
Example #14
0
        public int Execute(Execution execution)
        {
            if (File.Exists(Path.Combine("Build", "Module.xml")))
            {
                throw new InvalidOperationException("This directory already has a module setup.");
            }

            var url    = execution.StartProjectTemplateURL;
            var branch = "master";

            if (url.LastIndexOf('@') > url.LastIndexOf('/'))
            {
                // A branch / commit ref is specified.
                branch = url.Substring(url.LastIndexOf('@') + 1);
                url    = url.Substring(0, url.LastIndexOf('@'));
            }

            var packageRef = new PackageRef
            {
                Uri    = url,
                GitRef = branch,
                Folder = string.Empty
            };

            // If no project name is specified, use the name of the current directory.
            if (string.IsNullOrWhiteSpace(execution.StartProjectName))
            {
                var dir = new DirectoryInfo(Environment.CurrentDirectory);
                execution.StartProjectName = dir.Name;
                Console.WriteLine("Using current directory name '" + dir.Name + "' as name of new module.");
            }

            // The module can not be loaded before this point because it doesn't
            // yet exist.
            this.m_PackageManager.Resolve(null, packageRef, "Template", execution.StartProjectName, false);

            if (execution.DisableProjectGeneration)
            {
                Console.WriteLine("Module has been initialized.");
                return(0);
            }

            Console.WriteLine("Module has been initialized.  Performing --generate to create projects.");

            var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));

            return(this.m_ActionDispatch.PerformAction(
                       module,
                       "generate",
                       execution.Platform,
                       execution.EnabledServices.ToArray(),
                       execution.DisabledServices.ToArray(),
                       execution.ServiceSpecificationPath,
                       execution.DebugServiceResolution,
                       execution.DisablePackageResolution,
                       execution.DisableHostProjectGeneration)
                ? 0 : 1);
        }
Example #15
0
        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);
        }
Example #16
0
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine("Build", "Module.xml")))
            {
                throw new InvalidOperationException("No module present.");
            }

            var platform = execution.Platform ?? this.m_HostPlatformDetector.DetectPlatform();
            var module   = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));

            this.m_PackageManager.ResolveAll(module, platform);
            return(0);
        }
Example #17
0
        public int Execute(Execution execution)
        {
            if (File.Exists(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml")))
            {
                throw new InvalidOperationException("This directory already has a module setup.");
            }

            var package = _packageUrlParser.Parse(execution.StartProjectTemplateURL);

            package.Folder = string.Empty;

            // If no project name is specified, use the name of the current directory.
            if (string.IsNullOrWhiteSpace(execution.StartProjectName))
            {
                var dir = new DirectoryInfo(execution.WorkingDirectory);
                execution.StartProjectName = dir.Name;
                RedirectableConsole.WriteLine("Using current directory name '" + dir.Name + "' as name of new module.");
            }

            // The module can not be loaded before this point because it doesn't
            // yet exist.
            this.m_PackageManager.Resolve(execution.WorkingDirectory, null, package, "Template", execution.StartProjectName, false, false, execution.SafePackageResolution);

            if (execution.DisableProjectGeneration)
            {
                RedirectableConsole.WriteLine("Module has been initialized.");
                return(0);
            }

            RedirectableConsole.WriteLine("Module has been initialized.  Performing --generate to create projects.");

            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            return(this.m_ActionDispatch.PerformAction(
                       execution.WorkingDirectory,
                       module,
                       "generate",
                       execution.Platform,
                       execution.EnabledServices.ToArray(),
                       execution.DisabledServices.ToArray(),
                       execution.ServiceSpecificationPath,
                       execution.DebugServiceResolution,
                       execution.DisablePackageResolution,
                       execution.DisableHostProjectGeneration,
                       execution.UseTaskParallelisation,
                       execution.SafePackageResolution,
                       execution.DebugProjectGeneration)
                ? 0 : 1);
        }
Example #18
0
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine("Build", "Module.xml")))
            {
                Directory.CreateDirectory("Build");
                ResourceExtractor.ExtractAll(Path.Combine(Environment.CurrentDirectory, "Build"), "MyProject");
                Console.WriteLine("Build" + Path.DirectorySeparatorChar + "Module.xml has been created.");
                ExecEnvironment.Exit(0);
            }

            return(this.m_ActionDispatch.DefaultAction(
                       ModuleInfo.Load(Path.Combine("Build", "Module.xml")),
                       enabledServices: execution.EnabledServices.ToArray(),
                       disabledServices: execution.DisabledServices.ToArray(),
                       serviceSpecPath: execution.ServiceSpecificationPath) ? 0 : 1);
        }
        public int Execute(Execution execution)
        {
            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.Packages == null)
            {
                module.Packages = new List <PackageRef>();
            }

            foreach (var package in module.Packages)
            {
                RedirectableConsole.WriteLine(package.Uri);
            }

            return(0);
        }
Example #20
0
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml")))
            {
                throw new InvalidOperationException("No module present.");
            }

            var module    = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));
            var platforms = execution.Platform ?? this.m_HostPlatformDetector.DetectPlatform();

            foreach (var platform in platforms.Split(','))
            {
                this.m_PackageManager.ResolveAll(execution.WorkingDirectory, module, platform, execution.UseTaskParallelisation, false, execution.SafePackageResolution, null);
            }
            return(0);
        }
        public int Execute(Execution execution)
        {
            var url    = execution.PackageUrl;
            var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));

            if (module.Packages == null)
            {
                module.Packages = new List <PackageRef>();
            }

            var branch = "master";

            if (url.LastIndexOf('@') > url.LastIndexOf('/'))
            {
                // A branch / commit ref is specified.
                branch = url.Substring(url.LastIndexOf('@') + 1);
                url    = url.Substring(0, url.LastIndexOf('@'));
            }

            var uri = new Uri(url);

            var package = new PackageRef
            {
                Uri    = url,
                GitRef = branch,
                Folder = uri.AbsolutePath.Trim('/').Split('/').Last()
            };

            if (Directory.Exists(package.Folder))
            {
                throw new InvalidOperationException(package.Folder + " already exists");
            }

            if (module.Packages.Any(x => x.Uri == package.Uri))
            {
                Console.WriteLine("WARNING: Package with URI " + package.Uri + " is already present; ignoring request to add package.");
                return(0);
            }

            Console.WriteLine("Adding " + url + " as " + package.Folder + "...");
            module.Packages.Add(package);
            module.Save(Path.Combine("Build", "Module.xml"));

            return(0);
        }
Example #22
0
        public int Execute(Execution execution)
        {
            if (Directory.Exists("Build"))
            {
                var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
                return(this.m_ActionDispatch.PerformAction(
                           module,
                           "clean",
                           execution.Platform,
                           execution.EnabledServices.ToArray(),
                           execution.DisabledServices.ToArray(),
                           execution.ServiceSpecificationPath)
                    ? 0
                    : 1);
            }

            return(1);
        }
Example #23
0
        public IEnumerable <ModuleInfo> GetLinkedModules(FileInfo linkFile)
        {
            List <ModuleInfo> mi = new List <ModuleInfo>();
            var linkDoc          = new XmlDocument();

            linkDoc.Load(linkFile.FullName);
            foreach (var element in linkDoc
                     .DocumentElement
                     .ChildNodes
                     .Cast <XmlElement>()
                     .Where(x => x.Name == "Module"))
            {
                string path = System.IO.Path.Combine(linkFile.DirectoryName, element.GetAttribute("Path"), "Build", "Module.xml");
                if (System.IO.File.Exists(path))
                {
                    mi.Add(ModuleInfo.Load(path));
                }
            }
            return(mi);
        }
Example #24
0
        public int Execute(Execution execution)
        {
            if (File.Exists(Path.Combine("Build", "Module.xml")))
            {
                throw new InvalidOperationException("This directory already has a module setup.");
            }

            var url    = execution.StartProjectTemplateURL;
            var branch = "master";

            if (url.LastIndexOf('@') > url.LastIndexOf('/'))
            {
                // A branch / commit ref is specified.
                branch = url.Substring(url.LastIndexOf('@') + 1);
                url    = url.Substring(0, url.LastIndexOf('@'));
            }

            var packageRef = new PackageRef
            {
                Uri    = url,
                GitRef = branch,
                Folder = string.Empty
            };

            // The module can not be loaded before this point because it doesn't
            // yet exist.
            this.m_PackageManager.Resolve(null, packageRef, "Template", execution.StartProjectName, false);

            Console.WriteLine("Module has been initialized.  Performing --generate to create projects.");

            var module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));

            return(this.m_ActionDispatch.PerformAction(
                       module,
                       "generate",
                       execution.Platform,
                       execution.EnabledServices.ToArray(),
                       execution.DisabledServices.ToArray(),
                       execution.ServiceSpecificationPath)
                ? 0 : 1);
        }
        public int Execute(Execution execution)
        {
            if (!File.Exists(Path.Combine("Build", "Module.xml")))
            {
                _knownToolProvider.GetToolExecutablePath("Protobuild.Manager");

                var subexecution = new Execution();
                subexecution.ExecuteProjectName      = "Protobuild.Manager";
                subexecution.ExecuteProjectArguments = new string[0];

                return(_executeCommand.Execute(subexecution));
            }

            return(this.m_ActionDispatch.DefaultAction(
                       ModuleInfo.Load(Path.Combine("Build", "Module.xml")),
                       enabledServices: execution.EnabledServices.ToArray(),
                       disabledServices: execution.DisabledServices.ToArray(),
                       serviceSpecPath: execution.ServiceSpecificationPath,
                       debugServiceResolution: execution.DebugServiceResolution,
                       disablePackageResolution: execution.DisablePackageResolution,
                       disableHostPlatformGeneration: execution.DisableHostProjectGeneration) ? 0 : 1);
        }
Example #26
0
        public int Execute(Execution execution)
        {
            var platforms = execution.Platform ?? this._hostPlatformDetector.DetectPlatform();

            var package = _packageUrlParser.Parse(execution.PackageUrl);

            foreach (var platform in platforms.Split(','))
            {
                // Create a temporary working directory where we can precache files.
                var tempDir = Path.Combine(Path.GetTempPath(), "precache-" + HashString(execution.PackageUrl + "|" + platform + "|" + (execution.PrecacheSource == null ? "null" : execution.PrecacheSource.Value ? "true" : "false")));
                if (Directory.Exists(tempDir))
                {
                    PathUtils.AggressiveDirectoryDelete(tempDir);
                }
                Directory.CreateDirectory(tempDir);

                try
                {
                    RedirectableConsole.WriteLine("Precaching " + package.Uri + "...");
                    var metadata = _packageManager.Lookup(tempDir, null, package, platform, null, execution.PrecacheSource, true, false);
                    _packageManager.Resolve(tempDir, metadata, package, "PRECACHE", execution.PrecacheSource, true, false);

                    // Also precache dependencies.
                    if (File.Exists(Path.Combine(tempDir, "Build", "Module.xml")))
                    {
                        var moduleInfo = ModuleInfo.Load(Path.Combine(tempDir, "Build", "Module.xml"));
                        _packageManager.ResolveAll(tempDir, moduleInfo, platform, execution.UseTaskParallelisation, true, false, execution.PrecacheSource);
                    }
                }
                finally
                {
                    PathUtils.AggressiveDirectoryDelete(tempDir);
                }
            }

            return(0);
        }
        private string CheckBelow(string modulePath, PackageRef package, string platform)
        {
            var module = ModuleInfo.Load(Path.Combine(modulePath, "Build", "Module.xml"));
            var found  = module.Packages.Select(x => (PackageRef?)x)
                         .FirstOrDefault(x => string.Compare(x.Value.Uri, package.Uri, StringComparison.InvariantCulture) == 0);

            if (found != null)
            {
                return(Path.Combine(modulePath, found.Value.Folder));
            }

            var submodules = module.GetSubmodules();

            foreach (var submodule in submodules)
            {
                var below = this.CheckBelow(submodule.Path, package, platform);
                if (below != null)
                {
                    return(below);
                }
            }

            return(null);
        }
Example #28
0
        /// <summary>
        /// Loads all of the submodules present in this module.
        /// </summary>
        /// <returns>The loaded submodules.</returns>
        public ModuleInfo[] GetSubmodules(string platform = null)
        {
            if (!_cachedSubmodules.ContainsKey(platform ?? "<null>"))
            {
                var modules = new List <ModuleInfo>();
                foreach (var directoryInit in new DirectoryInfo(this.Path).GetDirectories())
                {
                    var directory = directoryInit;

                    if (File.Exists(System.IO.Path.Combine(directory.FullName, ".redirect")))
                    {
                        // This is a redirected submodule (due to package resolution).  Load the
                        // module from it's actual path.
                        using (var reader = new StreamReader(System.IO.Path.Combine(directory.FullName, ".redirect")))
                        {
                            var targetPath = reader.ReadToEnd().Trim();
                            directory = new DirectoryInfo(targetPath);
                        }
                    }

                    var build = directory.GetDirectories().FirstOrDefault(x => x.Name == "Build");
                    if (build == null)
                    {
                        continue;
                    }

                    var module = build.GetFiles().FirstOrDefault(x => x.Name == "Module.xml");
                    if (module == null)
                    {
                        continue;
                    }

                    modules.Add(ModuleInfo.Load(module.FullName));
                }

                if (platform != null)
                {
                    foreach (var directoryInit in new DirectoryInfo(this.Path).GetDirectories())
                    {
                        var directory = directoryInit;

                        if (File.Exists(System.IO.Path.Combine(directory.FullName, ".redirect")))
                        {
                            // This is a redirected submodule (due to package resolution).  Load the
                            // module from it's actual path.
                            using (
                                var reader = new StreamReader(System.IO.Path.Combine(directory.FullName, ".redirect")))
                            {
                                var targetPath = reader.ReadToEnd().Trim();
                                directory = new DirectoryInfo(targetPath);
                            }
                        }

                        var platformDirectory = new DirectoryInfo(System.IO.Path.Combine(directory.FullName, platform));

                        if (!platformDirectory.Exists)
                        {
                            continue;
                        }

                        var build = platformDirectory.GetDirectories().FirstOrDefault(x => x.Name == "Build");
                        if (build == null)
                        {
                            continue;
                        }

                        var module = build.GetFiles().FirstOrDefault(x => x.Name == "Module.xml");
                        if (module == null)
                        {
                            continue;
                        }

                        modules.Add(ModuleInfo.Load(module.FullName));
                    }
                }

                _cachedSubmodules[platform ?? "<null>"] = modules.ToArray();
            }

            return(_cachedSubmodules[platform ?? "<null>"]);
        }
Example #29
0
        public static void Main(string[] args)
        {
            Application.Init();

            MainWindow win = new MainWindow();

            // Detect if there is a Build directory in the local folder.  If not,
            // prompt to create a new module.
            if (!Directory.Exists("Build"))
            {
                var confirm = new MessageDialog(
                    win,
                    DialogFlags.Modal,
                    MessageType.Question,
                    ButtonsType.YesNo,
                    false,
                    "The current directory is not a Protobuild module.  Would " +
                    "you like to turn this directory into a module?");
                var result = (ResponseType)confirm.Run();
                if (result == ResponseType.No)
                {
                    // We can't run the module manager if the current directory
                    // isn't actually a module!
                    confirm.Destroy();
                    win.Destroy();
                    return;
                }
                confirm.Destroy();

                var create = new CreateProjectDialog(win, "Module", true);
                create.Modal = true;
                if ((ResponseType)create.Run() != ResponseType.Ok)
                {
                    create.Destroy();
                    win.Destroy();
                    return;
                }
                string error;
                if (!win.CreateProject(create.ProjectName, "Module", out error, true))
                {
                    var errorDialog = new MessageDialog(
                        win,
                        DialogFlags.Modal,
                        MessageType.Error,
                        ButtonsType.Ok,
                        "Unable to create module: " + error);
                    errorDialog.Run();
                    errorDialog.Destroy();
                    create.Destroy();
                    win.Destroy();
                    return;
                }
                Directory.CreateDirectory("Build");
                ResourceExtractor.ExtractAll(Path.Combine(
                                                 Environment.CurrentDirectory,
                                                 "Build"), create.ProjectName);
                create.Destroy();
            }

            // Load the module.
            win.Module = ModuleInfo.Load(Path.Combine("Build", "Module.xml"));
            win.InitializeToolbar();
            win.Update();

            win.Show();
            Application.Run();
        }
Example #30
0
        public int Execute(Execution execution)
        {
            var    hostPlatform          = _hostPlatformDetector.DetectPlatform();
            string builderPathNativeArch = null;
            string builderPath64         = null;
            string builderPath32         = null;
            var    extraArgsNativeArch   = string.Empty;
            var    extraArgs64           = string.Empty;
            var    extraArgs32           = string.Empty;
            var    extraArgsGeneral      = string.Empty;

            var targetPlatforms = (execution.Platform ?? hostPlatform).Split(',');
            var module          = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (hostPlatform == "Windows")
            {
                // Newer installs of Visual Studio (like 2017) don't create registry entries for MSBuild, so we have to
                // use a tool called vswhere in order to find MSBuild on these systems.  This call will implicitly install
                // the vswhere package if it's not already installed.
                var           vswhere       = _knownToolProvider.GetToolExecutablePath("vswhere");
                List <string> installations = null;
                if (vswhere != null && File.Exists(vswhere))
                {
                    try
                    {
                        var processStartInfo = new ProcessStartInfo();
                        processStartInfo.FileName               = vswhere;
                        processStartInfo.Arguments              = "-products * -requires Microsoft.Component.MSBuild -property installationPath";
                        processStartInfo.UseShellExecute        = false;
                        processStartInfo.RedirectStandardOutput = true;
                        var process             = Process.Start(processStartInfo);
                        var installationsString = process.StandardOutput.ReadToEnd();
                        installations = installationsString.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                        process.WaitForExit();

                        if (process.ExitCode != 0)
                        {
                            RedirectableConsole.ErrorWriteLine("Unable to locate Visual Studio 2017 and later installations (non-zero exit code from vswhere)");
                        }
                    }
                    catch (Exception ex)
                    {
                        RedirectableConsole.ErrorWriteLine("Unable to locate Visual Studio 2017 and later installations: " + ex.Message);
                    }
                }

                if (installations != null)
                {
                    // Check if MSBuild is present in any of those installation paths.
                    foreach (var basePath in installations)
                    {
                        var msbuildLocation = Path.Combine(basePath, "MSBuild\\15.0\\Bin\\MSBuild.exe");
                        if (File.Exists(msbuildLocation))
                        {
                            builderPathNativeArch = msbuildLocation;
                            extraArgsNativeArch   = "/m /nodeReuse:false ";
                            builderPath32         = msbuildLocation;
                            extraArgs32           = "/m /nodeReuse:false ";

                            var x64Location = Path.Combine(basePath, "MSBuild\\15.0\\Bin\\amd64\\MSBuild.exe");
                            if (File.Exists(x64Location))
                            {
                                builderPath64 = x64Location;
                                extraArgs64   = "/m /nodeReuse:false ";
                            }

                            break;
                        }
                    }
                }

                if (builderPathNativeArch == null)
                {
                    // Try to find via the registry.
                    foreach (var arch in new[] { RegistryView.Default, RegistryView.Registry32, RegistryView.Registry64 })
                    {
                        // Find latest version of MSBuild.
                        var registryKey =
                            RegistryKey.OpenBaseKey(
                                RegistryHive.LocalMachine,
                                arch)
                            .OpenSubKey("SOFTWARE")?
                            .OpenSubKey("Microsoft")?
                            .OpenSubKey("MSBuild")?
                            .OpenSubKey("ToolsVersions");
                        if (registryKey == null)
                        {
                            if (arch == RegistryView.Registry64)
                            {
                                continue;
                            }

                            RedirectableConsole.ErrorWriteLine(
                                "ERROR: No versions of MSBuild were available " +
                                "according to the registry (or they were not readable).");
                            return(1);
                        }

                        var subkeys         = registryKey.GetSubKeyNames();
                        var orderedVersions =
                            subkeys.OrderByDescending(x => int.Parse(x.Split('.').First(), CultureInfo.InvariantCulture));
                        var builderPath = (from version in orderedVersions
                                           let path = (string)registryKey.OpenSubKey(version)?.GetValue("MSBuildToolsPath")
                                                      where path != null && Directory.Exists(path)
                                                      let msbuild = Path.Combine(path, "MSBuild.exe")
                                                                    where File.Exists(msbuild)
                                                                    select msbuild).FirstOrDefault();

                        if (builderPath == null)
                        {
                            if (arch == RegistryView.Registry64)
                            {
                                continue;
                            }

                            RedirectableConsole.ErrorWriteLine(
                                "ERROR: Unable to find installed MSBuild in any installed tools version.");
                            return(1);
                        }

                        var extraArgs = string.Empty;
                        if (!builderPath.Contains("v2.0.50727"))
                        {
                            extraArgs = "/m /nodeReuse:false ";
                        }

                        switch (arch)
                        {
                        case RegistryView.Default:
                            builderPathNativeArch = builderPath;
                            extraArgsNativeArch   = extraArgs;
                            break;

                        case RegistryView.Registry32:
                            builderPath32 = builderPath;
                            extraArgs32   = extraArgs;
                            break;

                        case RegistryView.Registry64:
                            builderPath64 = builderPath;
                            extraArgs64   = extraArgs;
                            break;
                        }
                    }
                }
            }
            else
            {
                // Find path to xbuild.
                var whichPaths = new[] { "/bin/which", "/usr/bin/which" };

                // We can only use the new MSBuild tool if no projects are C++ projects on Mac or Linux.
                var isAnyNativeProject = false;
                foreach (var def in module.GetDefinitionsRecursively())
                {
                    var document     = XDocument.Load(def.DefinitionPath);
                    var languageAttr = document?.Root?.Attributes()?.FirstOrDefault(x => x.Name.LocalName == "Language");
                    if (languageAttr != null && languageAttr.Value == "C++")
                    {
                        isAnyNativeProject = true;
                        break;
                    }
                }
                if (!isAnyNativeProject)
                {
                    foreach (var w in whichPaths)
                    {
                        if (File.Exists(w))
                        {
                            var whichProcess = Process.Start(new ProcessStartInfo(w, "msbuild")
                            {
                                RedirectStandardOutput = true,
                                UseShellExecute        = false
                            });
                            if (whichProcess == null)
                            {
                                continue;
                            }
                            var result = whichProcess.StandardOutput.ReadToEnd().Trim();
                            if (!string.IsNullOrWhiteSpace(result) && File.Exists(result))
                            {
                                builderPathNativeArch = result;
                                break;
                            }
                        }
                    }
                }

                if (builderPathNativeArch == null)
                {
                    foreach (var w in whichPaths)
                    {
                        if (File.Exists(w))
                        {
                            var whichProcess = Process.Start(new ProcessStartInfo(w, "xbuild")
                            {
                                RedirectStandardOutput = true,
                                UseShellExecute        = false
                            });
                            if (whichProcess == null)
                            {
                                continue;
                            }
                            var result = whichProcess.StandardOutput.ReadToEnd().Trim();
                            if (!string.IsNullOrWhiteSpace(result) && File.Exists(result))
                            {
                                builderPathNativeArch = result;
                                break;
                            }
                        }
                    }
                }

                if (builderPathNativeArch == null && _hostPlatformDetector.DetectPlatform() == "MacOS" && File.Exists("/usr/local/bin/xbuild"))
                {
                    // After upgrading to OSX El Capitan, the /usr/local/bin folder is no longer in
                    // the system PATH.  If we can't find xbuild with the which tool, manually set the
                    // path here in an attempt to find it.
                    builderPathNativeArch = "/usr/local/bin/xbuild";
                }

                if (builderPathNativeArch == null)
                {
                    RedirectableConsole.ErrorWriteLine("ERROR: Unable to find msbuild or xbuild on the current PATH.");
                    return(1);
                }

                builderPath32 = builderPathNativeArch;
                builderPath64 = builderPathNativeArch;
            }

            if (!string.IsNullOrWhiteSpace(execution.BuildTarget))
            {
                extraArgsGeneral += "/t:\"" + execution.BuildTarget + "\" ";
            }
            foreach (var prop in execution.BuildProperties)
            {
                extraArgsGeneral += "/p:\"" + prop.Key.Replace("\"", "\\\"") + "\"=\"" + (prop.Value ?? string.Empty).Replace("\"", "\\\"") + "\" ";
            }

            switch (execution.BuildProcessArchitecture)
            {
            case "x86":
                RedirectableConsole.WriteLine("INFO: Using " + builderPath32 + " (forced 32-bit) to perform this build.");
                break;

            case "x64":
                RedirectableConsole.WriteLine("INFO: Using " + builderPath64 + " (forced 64-bit) to perform this build.");
                break;

            case "Default":
            default:
                RedirectableConsole.WriteLine("INFO: Using " + builderPathNativeArch + " (32-bit: " + builderPath32 + ") to perform this build.");
                break;
            }

            foreach (var platform in targetPlatforms)
            {
                string builderPath;
                string extraArgs;

                switch (execution.BuildProcessArchitecture)
                {
                case "x86":
                    builderPath = builderPath32;
                    extraArgs   = extraArgs32 + extraArgsGeneral;
                    break;

                case "x64":
                    builderPath = builderPath64;
                    extraArgs   = extraArgs64 + extraArgsGeneral;
                    break;

                case "Default":
                default:
                    builderPath = platform == "WindowsPhone" ? builderPath32 : builderPathNativeArch;
                    extraArgs   = (platform == "WindowsPhone" ? extraArgs32 : extraArgsNativeArch) + extraArgsGeneral;
                    break;
                }

                var fileToBuild = module.Name + "." + platform + ".sln";

                RedirectableConsole.WriteLine("INFO: Executing " + builderPath + " with arguments: " + extraArgs + fileToBuild);

                var process =
                    Process.Start(new ProcessStartInfo(builderPath, extraArgs + fileToBuild)
                {
                    UseShellExecute = false
                });
                if (process == null)
                {
                    RedirectableConsole.ErrorWriteLine("ERROR: Build process did not start successfully.");
                    return(1);
                }
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    return(process.ExitCode);
                }
            }

            return(0);
        }