private async Task ProjectBuild(Project project, string name, BuildType buildType) { try { var projectInfo = ProjectsInfo[name]; Tools.BuildTools buildTools = Config.Global.BuildTools.Create(); SourceFile sourceFile = new SourceFile(); List <string> LObj = new List <string>(); List <string> LInclude = projectInfo.Include.ToList(); List <string> LDefines = projectInfo.Defines.ToList(); LDefines.Add(String.Format("{0}_EXPORTS", name.ToUpper())); List <string> LLibrariesPath = projectInfo.LibrariesPath.ToList(); string LIntermediate = Path.Combine(Config.Global.IntermediateProjectPath, name); if (!Directory.Exists(LIntermediate)) { Directory.CreateDirectory(LIntermediate); } string PCH = null; string PCHH = null; string PCHSource = null; bool Rebuild = false; bool Build = false; bool Message = false; bool RebuildFull = false; buildTools.SetDefines(LDefines, GetOutFile(name, buildType), buildType); { string NameDefines = Path.Combine(LIntermediate, "defines.txt"); if (File.Exists(NameDefines)) { List <string> ListDefines = new List <string>(File.ReadAllLines(NameDefines)); if (ListDefines.Count == LDefines.Count) { ListDefines.Sort(); LDefines.Sort(); for (int i = 0; i < LDefines.Count; i++) { if (LDefines[i] != ListDefines[i]) { RebuildFull = true; File.WriteAllLines(NameDefines, LDefines); break; } } } else { RebuildFull = true; File.WriteAllLines(NameDefines, LDefines); } } else { RebuildFull = true; File.WriteAllLines(NameDefines, LDefines); } } DateTime dateTimeLibrary = FileSystem.GetLastWriteTime(Config.Global.ProjectsCSFile[name]); if (!String.IsNullOrEmpty(project.ResourceFile)) { string obj = Path.Combine(LIntermediate, Path.GetFileNameWithoutExtension(project.ResourceFile) + Config.Global.ObjectExtension); if (Config.Global.Rebuild || RebuildFull || !FileSystem.ExistsFile(obj) || FileSystem.GetLastWriteTime(project.ResourceFile) > FileSystem.GetLastWriteTime(obj)) { if (Message == false) { Console.WriteLine(String.Format("Сборка проекта {0}", name)); Message = true; } Console.WriteLine(String.Format("Сборка RES {0}", Path.GetFileName(project.ResourceFile))); buildTools.BuildResource(LInclude, LDefines, project.ResourceFile, obj, buildType); Build = true; } LObj.Add(obj); } if (project.PCHFile != null && project.PCHIncludeFile != null) { if (!FileSystem.ExistsFile(project.PCHFile)) { throw new Exception(String.Format("Не найден файл {0}", project.PCHFile)); } PCH = Path.Combine(LIntermediate, Path.GetFileNameWithoutExtension(project.PCHFile) + Config.Global.PCHExtension); PCHSource = Path.GetFullPath(project.PCHFile); PCHH = project.PCHIncludeFile; string obj = Path.Combine(LIntermediate, Path.GetFileNameWithoutExtension(PCHSource) + Config.Global.ObjectExtension); DateTime dateTime = DateTime.MinValue; bool reCreate = sourceFile.CheakSource(ref LInclude, LIntermediate, PCHSource, ref dateTime); if (Config.Global.Rebuild || RebuildFull || !FileSystem.ExistsFile(PCH) || !FileSystem.ExistsFile(obj) || reCreate || dateTime > FileSystem.GetLastWriteTime(obj) || dateTime > FileSystem.GetLastWriteTime(PCH) || dateTimeLibrary > FileSystem.GetLastWriteTime(PCH)) { if (Message == false) { Console.WriteLine(String.Format("Сборка проекта {0}", name)); Message = true; } Console.WriteLine(String.Format("Сборка PCH {0}", Path.GetFileName(PCHSource))); buildTools.BuildObject(name, LInclude, LDefines, PCH, PCHH, true, PCHSource, obj, buildType, project.Warning).Wait(); Rebuild = true; } LObj.Add(obj); } buildTools.BuildObjectsStart(name, LInclude, LDefines, PCH, PCHH, LIntermediate, buildType, project.Warning); foreach (string source in project.Sources) { bool C = source.Substring(source.Length - 2, 2).ToLower() == ".c"; if (C) { continue; } if (project.PCHFile != null && project.PCHIncludeFile != null && source.ToLower() == project.PCHFile.ToLower()) { continue; } string obj = Path.Combine(LIntermediate, Path.GetFileNameWithoutExtension(source) + Config.Global.ObjectExtension); { DateTime dateTime = DateTime.MinValue; bool reCreate = sourceFile.CheakSource(ref LInclude, LIntermediate, source, ref dateTime); if (dateTimeLibrary < dateTime) { dateTimeLibrary = dateTime; } if (Config.Global.Rebuild || RebuildFull || (Rebuild && !C) || !FileSystem.ExistsFile(obj) || reCreate || dateTime > FileSystem.GetLastWriteTime(obj)) { if (Message == false) { Console.WriteLine(String.Format("Сборка проекта {0}", name)); Message = true; } buildTools.BuildObjectPush(source); Build = true; } } LObj.Add(obj); } buildTools.BuildObjectsEnd(true); buildTools.BuildObjectsStart(name, LInclude, LDefines, null, null, LIntermediate, buildType, project.Warning); foreach (string source in project.Sources) { bool C = source.Substring(source.Length - 2, 2).ToLower() == ".c"; if (!C) { continue; } if (project.PCHFile != null && project.PCHIncludeFile != null && source.ToLower() == project.PCHFile.ToLower()) { continue; } string obj = Path.Combine(LIntermediate, Path.GetFileNameWithoutExtension(source) + Config.Global.ObjectExtension); { DateTime dateTime = DateTime.MinValue; bool reCreate = sourceFile.CheakSource(ref LInclude, LIntermediate, source, ref dateTime); if (dateTimeLibrary < dateTime) { dateTimeLibrary = dateTime; } if (Config.Global.Rebuild || RebuildFull || (Rebuild && !C) || !FileSystem.ExistsFile(obj) || reCreate || dateTime > FileSystem.GetLastWriteTime(obj)) { if (Message == false) { Console.WriteLine(String.Format("Сборка проекта {0}", name)); Message = true; } buildTools.BuildObjectPush(source); Build = true; } } LObj.Add(obj); } buildTools.BuildObjectsEnd(true); { Dictionary <string, bool> pairs = new Dictionary <string, bool>(); int cnt = 0; while (cnt != project.Projects.Public.Count + project.Projects.Private.Count) { cnt = 0; foreach (string projectName in project.Projects.Public) { if (pairs.ContainsKey(projectName)) { cnt++; } else if (IsCompleted(projectName)) { pairs.Add(projectName, true); if (ProjectsInfo[projectName].LibraryFile != null) { projectInfo.LibrariesStatic.Public.Add(Path.GetFileName(ProjectsInfo[projectName].LibraryFile)); } projectInfo.LibrariesStatic.Append(ProjectsInfo[projectName].LibrariesStatic); cnt++; } } foreach (string projectName in project.Projects.Private) { if (pairs.ContainsKey(projectName)) { cnt++; } else if (IsCompleted(projectName)) { pairs.Add(projectName, true); if (ProjectsInfo[projectName].LibraryFile != null) { projectInfo.LibrariesStatic.Private.Add(Path.GetFileName(ProjectsInfo[projectName].LibraryFile)); } projectInfo.LibrariesStatic.AppendInPrivate(ProjectsInfo[projectName].LibrariesStatic); cnt++; } } } } List <string> LLibraries = null; if (buildType == BuildType.StaticLibrary) { LLibraries = new List <string>(); } else { LLibraries = projectInfo.LibrariesStatic.ToList(); } LLibrariesPath.Add(Config.Global.IntermediateProjectPath); if (Config.Platform.Linux == Config.Global.Platform || Config.Platform.MinGW == Config.Global.Platform) { LLibrariesPath.Add(Config.Global.BinariesPlatformPath); } Dictionary <string, bool> LibPairs = new Dictionary <string, bool>(); foreach (string lib in LLibraries) { if (!LibPairs.ContainsKey(lib)) { LibPairs.Add(lib, true); } else { #if DEBUG Console.WriteLine(String.Format("Уже иммеется {0}", lib)); #endif continue; } string file = GetLib(lib, ref LLibrariesPath); if (file != null) { DateTime dateTime = FileSystem.GetLastWriteTime(file); if (dateTime > dateTimeLibrary) { dateTimeLibrary = dateTime; } continue; } else { if (Config.Platform.Linux == Config.Global.Platform) { throw new Exception(string.Format("Не найдена библиотека {0}", lib)); } } } LLibraries.Clear(); LLibraries.AddRange(LibPairs.Keys); string OutFile = GetOutFile(name, buildType); string OutFileTemp = OutFile; if (project.Sources.Count != 0) { projectInfo.LibraryFile = GetOutStaticLibrary(name, buildType); if (Config.Platform.MinGW == Config.Global.Platform) { switch (buildType) { case BuildType.StaticLibrary: OutFileTemp = Path.Combine(Path.GetDirectoryName(OutFile), "lib" + Path.GetFileName(OutFile)); break; case BuildType.DynamicLibrary: OutFileTemp = Path.Combine(Path.GetDirectoryName(OutFile), "lib" + Path.GetFileName(OutFile)); break; } } else if (Config.Platform.Linux == Config.Global.Platform) { switch (buildType) { case BuildType.StaticLibrary: OutFileTemp = Path.Combine(Path.GetDirectoryName(OutFile), "lib" + Path.GetFileName(OutFile) + ".a"); break; case BuildType.DynamicLibrary: OutFileTemp = Path.Combine(Path.GetDirectoryName(OutFile), "lib" + Path.GetFileName(OutFile) + ".so"); break; } } if (Config.Global.Rebuild || (Build || !FileSystem.ExistsFile(OutFileTemp)) || FileSystem.GetLastWriteTime(OutFileTemp) < dateTimeLibrary) { if (Config.Platform.MinGW == Config.Global.Platform) { Console.WriteLine(String.Format("Сборка {0}", OutFile)); } else { switch (buildType) { case BuildType.Executable: Console.WriteLine(String.Format("Сборка {0}.exe", OutFile)); break; default: Console.WriteLine(String.Format("Сборка {0}", OutFile)); break; } } Config.Global.CountBuild++; switch (buildType) { case BuildType.Executable: case BuildType.ConsoleExecutable: buildTools.SetLibraries(LLibraries, buildType); buildTools.BuildExecutable(LObj, LLibraries, LLibrariesPath, OutFile, GetOutStaticLibrary(name), buildType == BuildType.ConsoleExecutable); break; case BuildType.StaticLibrary: buildTools.BuildStaticLibrary(LObj, LLibraries, LLibrariesPath, OutFile); break; case BuildType.DynamicLibrary: buildTools.SetLibraries(LLibraries, buildType); buildTools.BuildDynamicLibrary(LObj, LLibraries, LLibrariesPath, OutFile, GetOutStaticLibrary(name)); break; } } } ProjectsInfo[name] = projectInfo; CountThread--; return; } catch (Exception ex) { CountThread--; throw ex; } }