public static IAssemblyInfo BuildLoadAndAddReferenceToSharpmakeFilesAssembly(this IAssemblerContext context, params string[] files) { var assemblyInfo = context.BuildAndLoadSharpmakeFiles(files); context.AddReference(assemblyInfo); return(assemblyInfo); }
public static void AddReferences(this IAssemblerContext context, IEnumerable <string> files) { foreach (string file in files) { context.AddReference(file); } }
public static void AddSourceAttributeParsers(this IAssemblerContext context, IEnumerable <ISourceAttributeParser> parsers) { foreach (var parser in parsers) { context.AddSourceAttributeParser(parser); } }
public static void AddReferences(this IAssemblerContext context, IEnumerable <IAssemblyInfo> infos) { foreach (var info in infos) { context.AddReference(info); } }
internal void ParseSourceAttributesFromLine( string line, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context ) { ParseSourceAttributesFromLine(line, sourceFilePath, lineNumber, ComputeParsers(), context); }
public void ParseLine(string line, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { foreach (Regex attributeRegex in _attributeRegexes) { Match match = attributeRegex.Match(line); if (match.Success) { ParseParameter(match.Groups.Cast <Group>().Skip(1).Select(group => group.Captures[0].Value).ToArray(), sourceFilePath, lineNumber, context); } } }
internal void ParseSourceAttributesFromLine( string line, FileInfo sourceFilePath, int lineNumber, IEnumerable <ISourceAttributeParser> parsers, IAssemblerContext context ) { foreach (var parser in parsers) { parser.ParseLine(line, sourceFilePath, lineNumber, context); } }
public void ParseLine(string line, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { string trimmedLine = line.TrimStart(); if (!trimmedLine.StartsWith("#")) { return; } // Are we in a #if block ? Match match = s_ifRegex.Match(trimmedLine); if (match.Success) { PushNewConditionBlock(); TestConditionBlockBranch(match.Groups["symbolName"].Value); return; } // Are we in a #elif block ? match = s_elifRegex.Match(trimmedLine); if (match.Success) { TestConditionBlockBranch(match.Groups["symbolName"].Value); return; } // Are we in a #else block ? match = s_elseRegex.Match(trimmedLine); if (match.Success) { TestConditionBlockBranch(null); return; } // Are we in a #endif block ? match = s_endifRegex.Match(trimmedLine); if (match.Success) { PopConditionBlock(); return; } }
public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { string includeFilename = parameters[0]; IncludeType matchType = IncludeType.Relative; if (parameters.Length > 1) { string incType = parameters[1].Replace("Sharpmake.", ""); incType = incType.Replace("IncludeType.", ""); if (!Enum.TryParse <IncludeType>(incType, out matchType)) { throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include invalid include type used ({0})", parameters[1]); } } string includeAbsolutePath = Path.IsPathRooted(includeFilename) ? includeFilename : null; if (Util.IsPathWithWildcards(includeFilename)) { if (matchType != IncludeType.Relative) { throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include with non-relative match types, wildcards are not supported ({0})", includeFilename); } includeAbsolutePath = includeAbsolutePath ?? Path.Combine(sourceFilePath.DirectoryName, includeFilename); context.AddSourceFiles(Util.DirectoryGetFilesWithWildcards(includeAbsolutePath)); } else { includeAbsolutePath = includeAbsolutePath ?? Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename); if (matchType == IncludeType.Relative) { if (!Util.FileExists(includeAbsolutePath)) { includeAbsolutePath = Util.GetCapitalizedPath(includeAbsolutePath); } } else { string matchIncludeInParentPath = MatchIncludeInParentPath(includeFilename, sourceFilePath.DirectoryName, matchType); if (matchIncludeInParentPath == null) { throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found '{0}'[{1}]. Search started from '{2}'", includeFilename, matchType, sourceFilePath.DirectoryName); } includeAbsolutePath = Util.GetCapitalizedPath(matchIncludeInParentPath); } if (!Util.FileExists(includeAbsolutePath)) { throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Include file not found {0}", includeFilename); } context.AddSourceFile(includeAbsolutePath); } }
public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { context.SetDebugProjectName(parameters[0]); }
public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { string includeFilename = parameters[0]; string includeAbsolutePath; if (Path.IsPathRooted(includeFilename)) { includeAbsolutePath = includeFilename; } else if (Util.IsPathWithWildcards(includeFilename)) { includeAbsolutePath = Path.Combine(sourceFilePath.DirectoryName, includeFilename); } else { includeAbsolutePath = Util.PathGetAbsolute(sourceFilePath.DirectoryName, includeFilename); } IAssemblyInfo assemblyInfo; if (s_assemblies.TryGetValue(includeAbsolutePath, out assemblyInfo)) { if (assemblyInfo == null) { throw new Error($"Circular Sharpmake.Package dependency on {includeFilename}"); } context.AddReference(assemblyInfo); return; } s_assemblies[includeAbsolutePath] = null; string[] files; if (Util.IsPathWithWildcards(includeFilename)) { files = Util.DirectoryGetFilesWithWildcards(includeAbsolutePath); } else { if (!Util.FileExists(includeAbsolutePath)) { includeAbsolutePath = Util.GetCapitalizedPath(includeAbsolutePath); } if (!Util.FileExists(includeAbsolutePath)) { throw new Error("\t" + sourceFilePath.FullName + "(" + lineNumber + "): error: Sharpmake.Package file not found {0}", includeFilename); } files = new string[] { includeAbsolutePath }; } assemblyInfo = context.BuildLoadAndAddReferenceToSharpmakeFilesAssembly(files); s_assemblies[includeAbsolutePath] = assemblyInfo; }
public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { string reference = parameters[0]; if (Util.IsPathWithWildcards(reference)) { string referenceAbsolutePath = Path.IsPathRooted(reference) ? reference : null; referenceAbsolutePath = referenceAbsolutePath ?? Path.Combine(sourceFilePath.DirectoryName, reference); context.AddReferences(Util.DirectoryGetFilesWithWildcards(referenceAbsolutePath)); } else { bool foundReference = false; foundReference = Assembler.DefaultReferences.Any( defaultReference => FileSystemStringComparer.StaticCompare(defaultReference, reference) == 0 ); if (!foundReference) { foreach (string candidateReferenceLocation in EnumerateReferencePathCandidates(sourceFilePath, reference)) { if (Util.FileExists(candidateReferenceLocation)) { context.AddReference(candidateReferenceLocation); foundReference = true; break; } } } else if (Builder.Instance.Diagnostics) { Util.LogWrite("{0}({1}): Warning: Reference '{2}' is redundant and can be removed since it is in the default reference list.", sourceFilePath.FullName, lineNumber, reference); } if (!foundReference) { throw new Error( "\t{0}({1}): error: Sharpmake.Reference file not found: {2}{3}Those paths were evaluated as candidates:{3} - {4}", sourceFilePath.FullName, lineNumber, reference, Environment.NewLine, string.Join(Environment.NewLine + " - ", EnumerateReferencePathCandidates(sourceFilePath, reference)) ); } } }
private void AnalyseSourceFile(string sourceFile, IEnumerable <ISourceAttributeParser> parsers, IEnumerable <IParsingFlowParser> flowParsers, IAssemblerContext context) { using (StreamReader reader = new StreamReader(sourceFile)) { FileInfo sourceFilePath = new FileInfo(sourceFile); List <IParsingFlowParser> flowParsersList = flowParsers.ToList(); foreach (IParsingFlowParser parsingFlowParser in flowParsersList) { parsingFlowParser.FileParsingBegin(sourceFile); } int lineNumber = 0; string line = reader.ReadLine()?.TrimStart(); while (line != null) { ++lineNumber; if (!string.IsNullOrEmpty(line) && line.StartsWith("namespace", StringComparison.Ordinal)) { break; } // First, update the parsing flow with the current line foreach (IParsingFlowParser parsingFlowParser in flowParsersList) { parsingFlowParser.ParseLine(line, sourceFilePath, lineNumber, context); } // We only want to parse the lines inside valid blocks if (!flowParsersList.Any() || flowParsersList.All(p => p.ShouldParseLine())) { ParseSourceAttributesFromLine(line, sourceFilePath, lineNumber, parsers, context); } line = reader.ReadLine()?.TrimStart(); } foreach (IParsingFlowParser parsingFlowParser in flowParsersList) { parsingFlowParser.FileParsingEnd(sourceFile); } } }
private void AnalyseSourceFile(string sourceFile, IEnumerable <ISourceAttributeParser> parsers, IAssemblerContext context) { using (StreamReader reader = new StreamReader(sourceFile)) { FileInfo sourceFilePath = new FileInfo(sourceFile); int lineNumber = 0; string line = reader.ReadLine(); while (line != null) { ++lineNumber; ParseSourceAttributesFromLine(line, sourceFilePath, lineNumber, parsers, context); line = reader.ReadLine()?.TrimStart(); if (!string.IsNullOrEmpty(line) && line.StartsWith("namespace", StringComparison.Ordinal)) { break; } } } }
public abstract void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context);
public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { string reference = parameters[0]; if (Util.IsPathWithWildcards(reference)) { string referenceAbsolutePath = Path.IsPathRooted(reference) ? reference : null; referenceAbsolutePath = referenceAbsolutePath ?? Path.Combine(sourceFilePath.DirectoryName, reference); context.AddReferences(Util.DirectoryGetFilesWithWildcards(referenceAbsolutePath)); } else { bool foundReference = false; foreach (string candidateReferenceLocation in EnumerateReferencePathCandidates(sourceFilePath, reference)) { if (Util.FileExists(candidateReferenceLocation)) { context.AddReference(candidateReferenceLocation); foundReference = true; break; } } if (!foundReference) { throw new Error( "\t{0}({1}): error: Sharpmake.Reference file not found: {2}{3}Those paths were evaluated as candidates:{3} - {4}", sourceFilePath.FullName, lineNumber, reference, Environment.NewLine, string.Join(Environment.NewLine + " - ", EnumerateReferencePathCandidates(sourceFilePath, reference)) ); } } }