示例#1
0
        private static void Dfs(Dep dep, Dictionary <Dep, List <Dep> > graph, HashSet <Dep> visitedConfigurations)
        {
            dep.UpdateConfigurationIfNull();

            if (Yaml.Exists(dep.Name) && !Yaml.ConfigurationParser(dep.Name).ConfigurationExists(dep.Configuration))
            {
                ConsoleWriter.WriteWarning($"Configuration '{dep.Configuration}' was not found in {dep.Name}. Will take full-build config");
                dep.Configuration = "full-build";
            }

            visitedConfigurations.Add(dep);
            graph[dep] = new List <Dep>();
            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, dep.Name)))
            {
                throw new CementBuildException("Failed to find module '" + dep.Name + "'");
            }
            var currentDeps = new DepsParser(Path.Combine(Helper.CurrentWorkspace, dep.Name)).Get(dep.Configuration).Deps ?? new List <Dep>();

            currentDeps = currentDeps.Select(d => new Dep(d.Name, null, d.Configuration)).ToList();
            foreach (var d in currentDeps)
            {
                d.UpdateConfigurationIfNull();
                graph[dep].Add(d);
                if (!visitedConfigurations.Contains(d))
                {
                    Dfs(d, graph, visitedConfigurations);
                }
            }
        }
示例#2
0
        private void GetAndBuild(Dep module)
        {
            using (new DirectoryJumper(Helper.CurrentWorkspace))
            {
                ConsoleWriter.WriteInfo("cm get " + module);
                if (new Get().Run(new[] { "get", module.ToYamlString() }) != 0)
                {
                    throw new CementException("Failed get module " + module);
                }
                ConsoleWriter.ResetProgress();
            }

            module.Configuration = module.Configuration ?? Yaml.ConfigurationParser(module.Name).GetDefaultConfigurationName();

            using (new DirectoryJumper(Path.Combine(Helper.CurrentWorkspace, module.Name)))
            {
                ConsoleWriter.WriteInfo("cm build-deps " + module);
                if (new BuildDeps().Run(new[] { "build-deps", "-c", module.Configuration }) != 0)
                {
                    throw new CementException("Failed to build deps for " + dep);
                }
                ConsoleWriter.ResetProgress();
                ConsoleWriter.WriteInfo("cm build " + module);
                if (new Build().Run(new[] { "build", "-c", module.Configuration }) != 0)
                {
                    throw new CementException("Failed to build " + dep);
                }
                ConsoleWriter.ResetProgress();
            }
            Console.WriteLine();
        }
示例#3
0
文件: RefFix.cs 项目: Fr1z2r/cement
        private List <string> GetAllInstallFiles(string module)
        {
            if (!File.Exists(Path.Combine(Helper.CurrentWorkspace, module, Helper.YamlSpecFile)))
            {
                return(new List <string>());
            }
            var configs = Yaml.ConfigurationParser(module).GetConfigurations();
            var result  = configs.Select(config => Yaml.InstallParser(module).Get(config)).SelectMany(parser => parser.Artifacts);

            return(result.Distinct().Select(file => Path.Combine(module, file)).ToList());
        }
示例#4
0
        protected override int Execute()
        {
            var currentDirectory = Directory.GetCurrentDirectory();
            var moduleName       = ResolveModuleName(currentDirectory);
            var workspace        = Helper.GetWorkspaceDirectory(currentDirectory);

            if (workspace == null)
            {
                throw new CementException("Cement workspace directory not found.");
            }
            if (moduleName == null)
            {
                throw new CementException("Specify module name, or use command inside module directory.");
            }
            if (!Helper.DirectoryContainsModule(workspace, moduleName))
            {
                throw new CementException($"Module {moduleName} not found.");
            }

            Helper.SetWorkspace(workspace);
            if (!Yaml.Exists(moduleName))
            {
                throw new CementException($"No module.yaml in {moduleName}.");
            }
            var configYamlParser = Yaml.ConfigurationParser(moduleName);
            var defaultConfig    = configYamlParser.GetDefaultConfigurationName();

            foreach (var config in configYamlParser.GetConfigurations())
            {
                var sb      = new StringBuilder(config);
                var parents = configYamlParser.GetParentConfigurations(config);
                if (parents != null && parents.Count > 0)
                {
                    sb.Append(" > ");
                    sb.Append(string.Join(", ", parents));
                }

                if (config == defaultConfig)
                {
                    sb.Append("  *default");
                    ConsoleWriter.Shared.PrintLn(sb.ToString(), ConsoleColor.Green);
                }
                else
                {
                    ConsoleWriter.Shared.WriteLine(sb.ToString());
                }
            }

            return(0);
        }
示例#5
0
        private void Fix()
        {
            oldYamlContent = Yaml.ReadAllText(rootModuleName);

            var modules = Helper.GetModules();

            var configs        = Yaml.ConfigurationParser(rootModuleName).GetConfigurations();
            var buildsInfo     = configs.SelectMany(config => Yaml.BuildParser(rootModuleName).Get(config));
            var processedFiles = new HashSet <string>();

            foreach (var buildInfo in buildsInfo)
            {
                Fix(buildInfo, modules, processedFiles);
            }
        }
示例#6
0
        private TokensList RefAddComplete()
        {
            var workspace = Helper.GetWorkspaceDirectory(Directory.GetCurrentDirectory()) ?? Directory.GetCurrentDirectory();

            Helper.SetWorkspace(workspace);

            var local = modules.Where(Yaml.Exists).ToList();

            if (lastToken.Contains("/") && local.Contains(lastToken.Split('/')[0]))
            {
                var name = lastToken.Split('/')[0];
                local.AddRange(
                    Yaml.ConfigurationParser(name).GetConfigurations().Select(c => $"{name}/{c}"));
            }

            return(TokensList.Create(local, MoudleCsprojs));
        }
示例#7
0
文件: RefFix.cs 项目: Fr1z2r/cement
        private void TryAddToDeps(string reference, string project)
        {
            var moduleDep = Helper.GetRootFolder(reference);

            var configs             = Yaml.ConfigurationParser(moduleDep).GetConfigurations();
            var configsWithArtifact =
                configs.Where(c =>
                              Yaml.InstallParser(moduleDep).GetAllInstallFilesFromConfig(c)
                              .Select(file => Path.Combine(moduleDep, file)).Any(file => Path.GetFullPath(file) == Path.GetFullPath(reference))).ToList();

            var toAdd = DepsPatcherProject.GetSmallerCementConfigs(Path.Combine(Helper.CurrentWorkspace, moduleDep), configsWithArtifact);

            foreach (var configDep in toAdd)
            {
                DepsPatcherProject.PatchDepsForProject(Directory.GetCurrentDirectory(), new Dep(moduleDep, null, configDep), project);
            }
        }
示例#8
0
        private static void CheckAndUpdateDepConfiguration(Dep dep)
        {
            dep.UpdateConfigurationIfNull();
            var key = dep.ToString();

            if (!DepConfigurationExistsCache.ContainsKey(key))
            {
                if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, dep.Name)))
                {
                    throw new CementBuildException("Failed to find module '" + dep.Name + "'");
                }
                DepConfigurationExistsCache[key] = !Yaml.Exists(dep.Name) ||
                                                   Yaml.ConfigurationParser(dep.Name).ConfigurationExists(dep.Configuration);
            }
            if (!DepConfigurationExistsCache[key])
            {
                ConsoleWriter.WriteWarning(
                    $"Configuration '{dep.Configuration}' was not found in {dep.Name}. Will take full-build config");
                dep.Configuration = "full-build";
            }
        }
示例#9
0
 private static TokensList ModuleConfigs(string moduleName)
 {
     return(TokensList.Create(
                Yaml.ConfigurationParser(moduleName).GetConfigurations()));
 }