public Project(Guid guid, Int64 projectHash, Solution ownerSolution, CompilerInstance compilerInstance) { ProjectSerial = nextProjectId++; Guid = guid; ProjectHash = projectHash; OwnerSolution = ownerSolution; Name = $"Project_{ProjectSerial:D4}"; CompilerInstance = compilerInstance; // initialize an empty set ProjectFiles = new HashSet <ProjectFile>(); ProjectFilters = new HashSet <String>(); }
public ProjectFile(Solution sln, AbsoluteCrosspath filePath, CompilerInstance compilerInstance) { CompilerOfFile = compilerInstance; IncludeDirectories = new IncludeDirectoryList(); DoNotUseStandardIncludeDirectories = false; Defines = new Dictionary <String, Define>(); SetOfDefines = new HashSet <Define>(DefineExactComparer.Instance); ForceIncludes = new HashSet <AbsoluteCrosspath>(); FilePath = filePath; OwnerSolution = sln; if (sln.config.BaseDir != null) { ProjectFolder = RelativeCrosspath.CreateRelativePath(filePath, sln.config.BaseDir, true).ToContainingDirectory() as RelativeCrosspath; } }
public Project(Guid guid, Int64 projectHash, Solution ownerSolution, CompilerInstance compilerInstance, IncludeDirectoryList includeDirectories , HashSet <Define> defines, HashSet <AbsoluteCrosspath> forcedIncludes) { ProjectSerial = nextProjectId++; Guid = guid; ProjectHash = projectHash; OwnerSolution = ownerSolution; Name = $"Project_{ProjectSerial:D4}"; CompilerInstance = compilerInstance; // copy references IncludeDirectories = includeDirectories; Defines = defines; ForcedIncludes = forcedIncludes; // initialize an empty set ProjectFiles = new HashSet <ProjectFile>(); ProjectFilters = new HashSet <String>(); }
public void ParseCompileDB(String filename) { // hope compiledb is not so large to eat all the memory String compiledbRaw = File.ReadAllText(filename); List <CompileDBEntry> entries = JsonConvert.DeserializeObject <List <CompileDBEntry> >(compiledbRaw); foreach (CompileDBEntry entry in entries) { // get full file path AbsoluteCrosspath workingDir = AbsoluteCrosspath.FromString(entry.directory); AbsoluteCrosspath xpath = AbsoluteCrosspath.FromString(entry.file, workingDir); // TODO: filter out entries by include and exclude lists // get compiler path // it can be absolute or relative Crosspath compilerPath = Crosspath.FromString(entry.arguments[0]); // TODO: filter out compilers by include and exclude lists Compiler compiler = null; foreach (Compiler solutionCompiler in solutionCompilers) { if (solutionCompiler.ExePath.ToString().Equals(compilerPath.ToString())) { // already registered compiler = solutionCompiler; break; } } if (compiler == null) { compiler = new Compiler(compilerPath); if (solutionCompilers.Add(compiler)) { Logger.WriteLine(LogLevel.Info, $"New compiler '{compiler.ExePath}'"); } } CompilerInstance compilerInstance = null; CompilerInstance compilerInstanceTmp = new CompilerInstance(compiler, entry.arguments); foreach (CompilerInstance compilerInstanceInUse in compiler.Instances) { if (compilerInstanceInUse.Equals(compilerInstanceTmp)) { compilerInstance = compilerInstanceInUse; break; } } if (compilerInstance == null) { compilerInstance = compilerInstanceTmp; compiler.Instances.Add(compilerInstanceTmp); Logger.WriteLine(LogLevel.Info, $"New compiler instance '{compilerInstanceTmp.BaseCompiler.ExePath} {compilerInstanceTmp}'"); } ProjectFile pf = new ProjectFile(this, xpath, compilerInstance); Logger.WriteLine(LogLevel.Trace, $"===== file {xpath} ====="); pf.AddInfoFromCommandLine(workingDir, entry.arguments); // put global override defines silently // TODO: write them to solution-wide props foreach (Define define in config.OverrideDefines) { pf.UnsetCppDefine(define.Name); pf.SetCppDefine(define.ToString()); } // add to project files now? //pf.DumpData(); Int64 projectHash = pf.HashProjectID(); if (!projects.ContainsKey(projectHash)) { projects.Add(projectHash, new Project(AllocateGuid(), projectHash, this, compilerInstance, pf.IncludeDirectories, pf.SetOfDefines, pf.ForceIncludes)); } // add file to project if (!projects[projectHash].TestWhetherProjectFileBelongs(pf)) { throw new ApplicationException( $"[x] Could not add '{pf.FilePath}' to project '{projectHash}' - hash function error"); } if (!projects[projectHash].AddProjectFile(pf)) { //throw new ApplicationException( // $"[x] Could not add '{pf.FilePath}' to project '{projectHash}' - already exists"); Logger.WriteLine(LogLevel.Error, $"[x] Could not add '{pf}' to project '{projectHash}' - already exists"); } TrackFile(pf); } Logger.WriteLine(LogLevel.Info, $"[i] Created a solution of {projects.Count} projects from {solutionFiles.Count} files"); if (Logger.Level == LogLevel.Trace) { foreach (var projectKvp in projects) { Logger.WriteLine(LogLevel.Trace, $"# Project ID {projectKvp.Key}"); foreach (var file in projectKvp.Value.ProjectFiles) { Logger.WriteLine(LogLevel.Trace, $"# > {file.FilePath}"); } using (var enumerator = projectKvp.Value.ProjectFiles.GetEnumerator()) { if (!enumerator.MoveNext()) { break; } if (enumerator.Current != null) { enumerator.Current.DumpData(); } } Logger.WriteLine(LogLevel.Trace, "============================================"); } } }