public static bool InstallAll(Log log, IEnumerable <string> files, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null) { try { var tasks = new List <Task>(); var retval = true; foreach (var file in files) { tasks.Add(Task.Factory.StartNew( () => { try { if (!Install(log, file, flags, optionalDefines)) { retval = false; } } catch (Exception e) { log.Error(file.ToRelativePath() + ": " + e.Message); retval = false; } })); } Task.WaitAll(tasks.ToArray()); return(retval); } finally { DownloadCache.AutoCollect(log); } }
Installer(string filename, StuffFlags flags, IEnumerable <string> optionalDefines) { _stuffFile = Path.GetFullPath(filename); _parentDirectory = Path.GetDirectoryName(_stuffFile); _flags = flags; _optionalVars = optionalDefines; }
public static bool Install(Log log, string filename, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null) { try { return(new Installer(log, filename, flags, optionalDefines).Install()); } finally { DownloadCache.AutoCollect(log); } }
public void Generate(string filename, StuffFlags flags, IEnumerable <string> defines, string outName = null, string buildNumber = null, string commitNumber = null, string version = null) { filename = Path.GetFullPath(filename); outName = outName != null ? Path.GetFullPath(outName) : Path.Combine( Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename) + ".sln"); _relativeHead = Path.GetDirectoryName(outName) + Path.DirectorySeparatorChar; var versionFile = Path.Combine( Path.GetDirectoryName(outName), ".stuff", Path.GetFileNameWithoutExtension(outName), "version"); var versionValue = commitNumber + "." + buildNumber + "." + version; try { if (!flags.HasFlag(StuffFlags.Force) && File.Exists(outName) && File.Exists(versionFile) && File.GetLastWriteTimeUtc(filename) <= File.GetLastWriteTimeUtc(versionFile) && File.ReadAllText(versionFile) == versionValue) { Log.Verbose(filename.Relative() + ": Up-to-date"); return; } } catch (Exception e) { Log.Warning(filename.Relative() + ": " + e.Message); } Emit(versionFile, versionValue, true); EmitSolution(filename, outName, flags, defines); EmitAssemblyInfo(filename, buildNumber, commitNumber, version); }
void EmitSolution(string filename, string outName, StuffFlags flags, IEnumerable <string> defines) { _sln.AppendLine(); _sln.AppendLine("Microsoft Visual Studio Solution File, Format Version 12.00"); _sln.AppendLine("# Visual Studio 14"); _sln.AppendLine("VisualStudioVersion = 14.0.24720.0"); _sln.AppendLine("MinimumVisualStudioVersion = 10.0.40219.1"); LoadStuff(filename, flags, defines); _sln.AppendLine("Global"); _sln.AppendLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"); _sln.AppendLine("\t\tDebug|Any CPU = Debug|Any CPU"); _sln.AppendLine("\t\tRelease|Any CPU = Release|Any CPU"); _sln.AppendLine("\tEndGlobalSection"); _sln.AppendLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution"); foreach (var p in _projectGuids) { _sln.AppendLine("\t\t" + p + ".Debug|Any CPU.ActiveCfg = Debug|Any CPU"); _sln.AppendLine("\t\t" + p + ".Debug|Any CPU.Build.0 = Debug|Any CPU"); _sln.AppendLine("\t\t" + p + ".Release|Any CPU.ActiveCfg = Release|Any CPU"); _sln.AppendLine("\t\t" + p + ".Release|Any CPU.Build.0 = Release|Any CPU"); } _sln.AppendLine("\tEndGlobalSection"); _sln.AppendLine("\tGlobalSection(SolutionProperties) = preSolution"); _sln.AppendLine("\t\tHideSolutionNode = FALSE"); _sln.AppendLine("\tEndGlobalSection"); _sln.AppendLine("\tGlobalSection(NestedProjects) = preSolution"); foreach (var e in _nestedProjects) { _sln.AppendLine("\t\t" + e.Key + " = " + e.Value); } _sln.AppendLine("\tEndGlobalSection"); _sln.AppendLine("EndGlobal"); Emit(outName, _sln.ToString()); }
void LoadStuff(string filename, StuffFlags flags, IEnumerable <string> defines) { var solutionDir = Path.GetDirectoryName(filename); foreach (var solutionFolder in StuffObject.Load(filename, flags, defines)) { if (solutionFolder.Key.StartsWith("AssemblyInfo.")) { var key = solutionFolder.Key; var property = key.Substring(key.IndexOf('.') + 1); _assemblyInfo[property] = solutionFolder.Value?.ToString(); continue; } var folderGuid = GetFolderGuid(solutionFolder.Key); foreach (var projectPath in solutionFolder.Value.Lines() .Select(x => Path.Combine(solutionDir, x))) { if (Directory.Exists(projectPath)) { foreach (var projectFile in Directory.EnumerateFiles(projectPath, "*.csproj")) { AddProject(projectFile, folderGuid); } } else if (File.Exists(projectPath)) { AddProject(projectPath, folderGuid); } else { Log.Warning(projectPath.Relative() + ": No C# project(s) found"); } } } }
public static bool IsUpToDate(Log log, string filename, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null) { try { var parentDir = Path.GetDirectoryName(filename); foreach (var item in StuffObject.Load(filename, flags, optionalDefines)) { var itemKey = item.Key.Replace('/', Path.DirectorySeparatorChar); var itemFile = Path.Combine(parentDir, ".uno", "stuff", itemKey); var targetDir = Path.Combine(parentDir, itemKey); if (!IsItemUpToDate(log, targetDir, itemFile, item.Value?.ToString(), flags)) { return(false); } } return(true); } finally { DownloadCache.AutoCollect(log); } }
static bool IsItemUpToDate(Log log, string targetDir, string itemFile, string itemValue, StuffFlags flags) { if (!(flags.HasFlag(StuffFlags.Force) || !Directory.Exists(targetDir) || !File.Exists(itemFile) || File.ReadAllText(itemFile) != itemValue ) || File.Exists(Path.Combine(targetDir, ".stuffignore")) || Directory.Exists(Path.Combine(targetDir, ".git")) || File.Exists(Path.Combine(targetDir, ".git"))) { DownloadCache.UpdateTimestamp(log, itemValue); return(true); } return(false); }
public static StuffObject Load(string filename, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null) { return(Parse(filename, File.ReadAllText(filename), File.ReadAllText, flags, optionalDefines)); }
public static StuffObject Parse(string filename, string stuff, Func <string, string> requireResolver = null, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null) { var file = new StuffFile( filename, flags.HasFlag(StuffFlags.AcceptAll) ? null : new HashSet <string>( (optionalDefines ?? StuffFile.DefaultDefines) .Select(x => x.ToUpperInvariant()))); file.Parse(stuff, flags.HasFlag(StuffFlags.Print)); var result = file.Flatten(requireResolver).ToObject(); // Workaround to avoid side-effect when StuffFlags.AcceptAll is set if (flags.HasFlag(StuffFlags.AcceptAll)) { foreach (var e in Parse(filename, stuff, requireResolver, 0, optionalDefines)) { if (!result.ContainsKey(e.Key) || result[e.Key]?.ToString().IndexOf('\n') == -1) { result[e.Key] = e.Value; } } } if (flags.HasFlag(StuffFlags.Print)) { Log.WriteLine(result.StringifyStuff()); } return(result); }