public void TryCreate() { var idt = new SymbolTable(); FullSymbol p; int characterWithError; XAssert.AreEqual(FullSymbol.ParseResult.Success, FullSymbol.TryCreate(idt, @"C.AAA.CCC", out p, out characterWithError)); XAssert.AreEqual(@"C.AAA.CCC", p.ToString(idt)); XAssert.AreEqual(FullSymbol.ParseResult.FailureDueToInvalidCharacter, FullSymbol.TryCreate(idt, @"C.::AAA", out p, out characterWithError)); XAssert.AreEqual(2, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.FailureDueToInvalidCharacter, FullSymbol.TryCreate(idt, @"AAA:", out p, out characterWithError)); XAssert.AreEqual(3, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.FailureDueToInvalidCharacter, FullSymbol.TryCreate(idt, @":AAA", out p, out characterWithError)); XAssert.AreEqual(0, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.LeadingOrTrailingDot, FullSymbol.TryCreate(idt, @"C...", out p, out characterWithError)); XAssert.AreEqual(2, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.LeadingOrTrailingDot, FullSymbol.TryCreate(idt, @"C......", out p, out characterWithError)); XAssert.AreEqual(2, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.LeadingOrTrailingDot, FullSymbol.TryCreate(idt, @"..", out p, out characterWithError)); XAssert.AreEqual(0, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.LeadingOrTrailingDot, FullSymbol.TryCreate(idt, @".", out p, out characterWithError)); XAssert.AreEqual(0, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.FailureDueToInvalidCharacter, FullSymbol.TryCreate(idt, @"C.:", out p, out characterWithError)); XAssert.AreEqual(2, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.FailureDueToInvalidCharacter, FullSymbol.TryCreate(idt, @"1..", out p, out characterWithError)); XAssert.AreEqual(1, characterWithError); XAssert.AreEqual(FullSymbol.ParseResult.FailureDueToInvalidCharacter, FullSymbol.TryCreate(idt, string.Empty, out p, out characterWithError)); XAssert.AreEqual(0, characterWithError); p = FullSymbol.Create(idt, @"C"); XAssert.AreEqual(@"C", p.ToString(idt)); p = FullSymbol.Create(idt, @"C.BBB"); XAssert.AreEqual(@"C.BBB", p.ToString(idt)); }
/// <nodoc/> protected virtual bool ValidateResolverSettings(TResolverSettings resolverSettings) { var pathToFile = resolverSettings.File.ToString(Context.PathTable); if (!resolverSettings.Root.IsValid) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "The root must be specified."); return(false); } if (string.IsNullOrEmpty(resolverSettings.ModuleName)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "The module name must not be empty."); return(false); } if (resolverSettings.CustomCommands != null) { var commandNames = new HashSet <string>(); foreach (var customCommand in resolverSettings.CustomCommands) { if (string.IsNullOrEmpty(customCommand.Command)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "A non-empty custom command name must be defined."); return(false); } if (!commandNames.Add(customCommand.Command)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Duplicated custom command name '{customCommand.Command}'."); return(false); } if (customCommand.ExtraArguments == null) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Extra arguments for custom command '{customCommand.Command}' must be defined."); return(false); } } } if (resolverSettings.Exports != null) { var symbolNames = new HashSet <FullSymbol>(); foreach (var javaScriptExport in resolverSettings.Exports) { if (!javaScriptExport.SymbolName.IsValid) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Symbol name is undefined."); return(false); } if (!symbolNames.Add(javaScriptExport.SymbolName)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Duplicate symbol name '{javaScriptExport.SymbolName.ToString(Context.SymbolTable)}'."); return(false); } // Each specified project must be non-empty foreach (var project in javaScriptExport.Content) { object projectValue = project.GetValue(); string packageName = projectValue is string?(string)projectValue : ((IJavaScriptProjectOutputs)projectValue).PackageName; if (string.IsNullOrEmpty(packageName)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "Package name must be defined."); return(false); } if (projectValue is IJavaScriptProjectOutputs javaScriptProjectCommand) { if (javaScriptProjectCommand.Commands == null) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Commands for JavaScript export '{javaScriptExport.SymbolName.ToString(Context.SymbolTable)}' must be defined."); return(false); } foreach (var command in javaScriptProjectCommand.Commands) { if (string.IsNullOrEmpty(command)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Command name for JavaScript export '{javaScriptExport.SymbolName.ToString(Context.SymbolTable)}' must be defined."); return(false); } } } } } } if (resolverSettings.CustomScheduling != null) { if (string.IsNullOrEmpty(resolverSettings.CustomScheduling.Module)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Module name for the custom scheduling entry must be defined."); return(false); } if (string.IsNullOrEmpty(resolverSettings.CustomScheduling.SchedulingFunction)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Custom scheduling function name must be defined."); return(false); } if (FullSymbol.TryCreate(Context.SymbolTable, resolverSettings.CustomScheduling.SchedulingFunction, out _, out _) != FullSymbol.ParseResult.Success) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Custom scheduling function name is not a valid dotted identifier."); return(false); } } return(true); }
private PipFilter ParseFilterTuple() { SkipWhitespace(); // Extract filterType and filterArgument for filters of the form: // filterType = ' filterArgument ' // filterType [FilterArgumentSeparator] [FilterArgumentStartEnd] filterArgument [FilterArgumentStartEnd] int startFilterType = m_position; SkipWhitespace(); if (!SeekToNextInstanceOfChar(FilterArgumentSeparator)) { throw CreateException(ErrorMessages.MissingFilterArgumentSeparator, FilterArgumentSeparator); } int separatorPosition = m_position; string filterType = m_expression.Substring(startFilterType, separatorPosition - startFilterType).Trim(); // Advance past the separator and find the filter argument start delimiter ExpectAndAdvancePast(FilterArgumentSeparator); SkipWhitespace(); if (!MatchesNext(FilterArgumentStartEnd)) { throw CreateException(ErrorMessages.MissingStartArgumentDelimiter, FilterArgumentStartEnd); } // go past the delimiter to find the actual argument ExpectAndAdvancePast(FilterArgumentStartEnd); int argumentStart = m_position; if (!SeekToNextInstanceOfChar(FilterArgumentStartEnd)) { throw CreateException(ErrorMessages.MissingEndArgumentDelimiter, FilterArgumentStartEnd); } string filterArgument = m_expression.Substring(argumentStart, m_position - argumentStart); ExpectAndAdvancePast(FilterArgumentStartEnd); SkipWhitespace(); MatchMode matchMode; AbsolutePath absPath; string pathWildcard; bool pathFromMount; // Create the specific filter type switch (filterType) { case FilterTypeTag: return(new TagFilter(StringId.Create(m_context.PathTable.StringTable, filterArgument))); case FilterTypeInput: ParsePathBasedFilter(filterArgument, argumentStart, out matchMode, out absPath, out pathWildcard, out pathFromMount); return(new InputFileFilter(absPath, pathWildcard, matchMode, pathFromMount)); case FilterTypeSpec: case FilterTypeSpecValueTransitive: case FilterTypeSpecRef: ParsePathBasedFilter(filterArgument, argumentStart, out matchMode, out absPath, out pathWildcard, out pathFromMount); return(new SpecFileFilter(absPath, pathWildcard, matchMode, pathFromMount, valueTransitive: filterType == FilterTypeSpecValueTransitive, specDependencies: filterType == FilterTypeSpecRef)); case FilterTypeModule: return(new ModuleFilter(StringId.Create(m_context.PathTable.StringTable, filterArgument))); case FilterTypeId: // Strip the fixed prefix that we print to the user. if (filterArgument.StartsWith(Pip.SemiStableHashPrefix, StringComparison.OrdinalIgnoreCase)) { filterArgument = filterArgument.Substring(Pip.SemiStableHashPrefix.Length); } long pipId; if (!long.TryParse(filterArgument, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out pipId)) { throw CreateException(argumentStart, ErrorMessages.FailedToParsePipId, filterArgument); } return(new PipIdFilter(pipId)); case FilterTypeValue: case FilterTypeValueTransitive: FullSymbol symbol; int charWithError; if (FullSymbol.TryCreate(m_context.SymbolTable, filterArgument, out symbol, out charWithError) != FullSymbol.ParseResult.Success) { throw CreateException(argumentStart, ErrorMessages.FailedToParseValueIdentifier, filterArgument); } return(new ValueFilter(symbol, valueTransitive: filterType == FilterTypeValueTransitive)); case FilterTypeOutput: ParsePathBasedFilter(filterArgument, argumentStart, out matchMode, out absPath, out pathWildcard, out pathFromMount); return(new OutputFileFilter(absPath, pathWildcard, matchMode, pathFromMount)); default: if (filterType.IndexOf(LegacyDependentsFlag) >= 0) { throw CreateException(startFilterType, ErrorMessages.DependentsOperatorMayOnlyBeUsedInOuterScope, LegacyDependentsFlag); } throw CreateException(startFilterType, ErrorMessages.UnknownFilterType, filterType); } }
/// <nodoc/> protected virtual bool ValidateResolverSettings(TResolverSettings resolverSettings) { var pathToFile = resolverSettings.File.ToString(Context.PathTable); if (!resolverSettings.Root.IsValid) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "The root must be specified."); return(false); } if (string.IsNullOrEmpty(resolverSettings.ModuleName)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "The module name must not be empty."); return(false); } if (resolverSettings.CustomCommands != null) { var commandNames = new HashSet <string>(); foreach (var customCommand in resolverSettings.CustomCommands) { if (string.IsNullOrEmpty(customCommand.Command)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), "A non-empty custom command name must be defined."); return(false); } if (!commandNames.Add(customCommand.Command)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Duplicated custom command name '{customCommand.Command}'."); return(false); } if (customCommand.ExtraArguments == null) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Extra arguments for custom command '{customCommand.Command}' must be defined."); return(false); } } } if (resolverSettings.Exports != null) { var symbolNames = new HashSet <FullSymbol>(); foreach (var javaScriptExport in resolverSettings.Exports) { if (!javaScriptExport.SymbolName.IsValid) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Symbol name is undefined."); return(false); } if (!symbolNames.Add(javaScriptExport.SymbolName)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Duplicate symbol name '{javaScriptExport.SymbolName.ToString(Context.SymbolTable)}'."); return(false); } // Each specified project must be non-empty foreach (var selector in javaScriptExport.Content) { if (!ValidateProjectSelector(selector, pathToFile, $"JavaScript export '{javaScriptExport.SymbolName.ToString(Context.SymbolTable)}'")) { return(false); } } } } if (resolverSettings.CustomScheduling != null) { if (string.IsNullOrEmpty(resolverSettings.CustomScheduling.Module)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Module name for the custom scheduling entry must be defined."); return(false); } if (string.IsNullOrEmpty(resolverSettings.CustomScheduling.SchedulingFunction)) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Custom scheduling function name must be defined."); return(false); } if (FullSymbol.TryCreate(Context.SymbolTable, resolverSettings.CustomScheduling.SchedulingFunction, out _, out _) != FullSymbol.ParseResult.Success) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Custom scheduling function name is not a valid dotted identifier."); return(false); } } if (resolverSettings.AdditionalDependencies != null) { foreach (var additionalDependency in resolverSettings.AdditionalDependencies) { if (additionalDependency.Dependents == null) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Dependents is undefined."); return(false); } if (additionalDependency.Dependencies == null) { Tracing.Logger.Log.InvalidResolverSettings(Context.LoggingContext, Location.FromFile(pathToFile), $"Dependencies is undefined."); return(false); } foreach (var dependent in additionalDependency.Dependents) { if (!ValidateProjectSelector(dependent, pathToFile, "JavaScript dependent")) { return(false); } } foreach (var dependency in additionalDependency.Dependencies.Where(dependency => dependency.GetValue() is not ILazyEval)) { var javaScriptProjectSelector = new DiscriminatingUnion <string, IJavaScriptProjectSimpleSelector, IJavaScriptProjectRegexSelector>(); javaScriptProjectSelector.TrySetValue(dependency.GetValue()); if (!ValidateProjectSelector(javaScriptProjectSelector, pathToFile, "JavaScript dependency")) { return(false); } } } } return(true); }