public static Location AsLoggingLocation(this LineInfo lineInfo, ModuleLiteral moduleLiteral, ImmutableContextBase context) { return(lineInfo.AsUniversalLocation(moduleLiteral, context).AsLoggingLocation()); }
/// <summary> /// Replaces the name of each environment variable embedded in the specified path with the string equivalent of the value of the variable. /// Replacement only occurs for environment variables that are set. Unset environment variables are left unexpanded. /// </summary> private static EvaluationResult ExpandEnvironmentVariablesInPath(Context context, ModuleLiteral env, EvaluationStackFrame args) { var path = Args.AsPath(args, 0); var pathAsString = path.ToString(context.PathTable); if (StringVariableExpander.TryExpandVariablesInString(pathAsString, context.FrontEndHost.Engine, out string expandedPath)) { // The resulting expanded path may not be a valid one. Apply the same validations as when creating an absolute path from a literal return(AmbientPath.CreateFromAbsolutePathString(context, expandedPath)); } // No expansion occurred return(EvaluationResult.Create(path)); }
/// <inheritdoc/> public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context) { errors.ReportInvalidRadix(environment, expression, location, m_radix); }
private static EvaluationResult GetPathValue(Context context, ModuleLiteral env, EvaluationStackFrame args) { var path = GetPathValue(context, args); return(path.IsValid ? EvaluationResult.Create(path) : EvaluationResult.Undefined); }
private static EvaluationResult HasVariable(Context context, ModuleLiteral env, EvaluationStackFrame args) { var name = Args.AsString(args, 0); return(EvaluationResult.Create(GetRawValue(context, name) != null)); }
private EvaluationResult GetKeyForm(Context context, ModuleLiteral env, EvaluationStackFrame args) { var keyFormDll = Args.AsFile(args, 0); var arch = Args.AsString(args, 1); var name = Args.AsString(args, 2); var version = Args.AsString(args, 3); var publicKeyToken = Args.AsString(args, 4); var versionScope = Args.AsStringOptional(args, 5); var culture = Args.AsStringOptional(args, 6); var type = Args.AsStringOptional(args, 7); var handler = m_handlers.GetOrAdd( keyFormDll.Path, _ => { var keyFormDllPath = keyFormDll.Path.ToString(context.PathTable); var fileName = Path.GetFileName(keyFormDllPath); if (!string.Equals(KeyFormFileName, fileName, StringComparison.OrdinalIgnoreCase)) { throw new KeyFormDllWrongFileNameException(keyFormDllPath, KeyFormFileName, new ErrorContext(pos: 1)); } if (!File.Exists(keyFormDllPath)) { throw new KeyFormDllNotFoundException(keyFormDllPath, new ErrorContext(pos: 1)); } IntPtr moduleHandle = NativeMethods.LoadLibraryW(keyFormDllPath); if (moduleHandle == IntPtr.Zero) { var lasterror = Marshal.GetLastWin32Error(); var ex = new Win32Exception(lasterror); throw new KeyFormDllLoadException(keyFormDllPath, lasterror, ex.Message, new ErrorContext(pos: 1)); } IntPtr procHandle = NativeMethods.GetProcAddress(moduleHandle, KeyFormFunction); if (procHandle == IntPtr.Zero) { var lasterror = Marshal.GetLastWin32Error(); var ex = new Win32Exception(lasterror); throw new KeyFormDllLoadException(keyFormDllPath, lasterror, ex.Message, new ErrorContext(pos: 1)); } return(Marshal.GetDelegateForFunctionPointer <GetKeyFormHandler>(procHandle)); }); using (var pooledBuilder = m_stringBuilderCache.GetInstance()) { var builder = pooledBuilder.Instance; try { // Since this is native code hardening our process against threading issues // in the native code by ensuring we only access from single thread. // WIP: experimental. Removing locking for key form. // lock (m_keyFormLock) { handler(arch, name, version, publicKeyToken, versionScope, culture, type, builder, (uint)builder.Capacity); } } catch (Exception e) { // I know it is bad to catch all exceptions, but this is going into native code of which we // don't have control and this code doesn't handle weird input properly. var keyFormDllPath = keyFormDll.Path.ToString(context.PathTable); throw new KeyFormNativeFailureException(keyFormDllPath, e, new ErrorContext(pos: 1)); } return(EvaluationResult.Create(builder.ToString())); } }
/// <inheritdoc /> public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context) { errors.ReportJsonUnsuportedDynamicFieldsForSerialization(environment, this, location); }
private static EvaluationResult GetSpecFile(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(FileArtifact.CreateSourceFile(context.LastActiveUsedPath))); }
private static EvaluationResult GetSpecFileDirectory(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(DirectoryArtifact.CreateWithZeroPartialSealId(context.LastActiveUsedPath.GetParent(context.FrontEndContext.PathTable)))); }
private static EvaluationResult IsWindowsOS(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(Host.Current.CurrentOS == BuildXL.Interop.OperatingSystem.Win)); }
private EvaluationResult GetCurrentHost(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(m_currentHost)); }
private static EvaluationResult GetLastActiveUseModuleName(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(context.LastActiveUsedModuleName)); }
private static EvaluationResult GetLastActiveUseNamespace(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(context.TopLevelValueInfo.ValueName.GetParent(context.FrontEndContext.SymbolTable).ToString(context.FrontEndContext.SymbolTable))); }
private static EvaluationResult GetTempDirectory(Context context, ModuleLiteral env, EvaluationStackFrame args) { var directory = context.GetPipConstructionHelper().GetUniqueTempDirectory(); return(EvaluationResult.Create(directory)); }
private static EvaluationResult Empty(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(OrderedSet.Empty)); }
private static EvaluationResult GetBuildEngineDirectoryToBeDeprecated(Context context, ModuleLiteral env, EvaluationStackFrame args) { var pathTable = context.FrontEndContext.PathTable; var executingEnginePath = AbsolutePath.Create(pathTable, AssemblyHelper.GetAssemblyLocation(Assembly.GetExecutingAssembly())); return(EvaluationResult.Create(DirectoryArtifact.CreateWithZeroPartialSealId(executingEnginePath.GetParent(pathTable)))); }
private static EvaluationResult Create(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(Add(context, OrderedSet.Empty, args[0], args)); }
/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { return(EvaluationResult.Create(Value)); }
/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { return(Expression.Eval(context, env, frame)); }
/// <inheritdoc /> public Task <bool?> TryConvertModuleToEvaluationAsync(IModuleRegistry moduleRegistry, ParsedModule module, IWorkspace workspace) { if (!string.Equals(module.Descriptor.ResolverName, Name, StringComparison.Ordinal)) { return(Task.FromResult <bool?>(null)); } var downloadData = m_workspaceResolver.Downloads[module.Descriptor.Name]; var package = CreatePackage(module.Definition); Contract.Assert(module.Specs.Count == 1, "This resolver generated the module, so we expect a single spec."); var sourceKv = module.Specs.First(); var sourceFilePath = sourceKv.Key; var sourceFile = sourceKv.Value; var currentFileModule = ModuleLiteral.CreateFileModule( sourceFilePath, moduleRegistry, package, sourceFile.LineMap); // Download var downloadSymbol = FullSymbol.Create(m_context.SymbolTable, "download"); var downloadResolvedEntry = new ResolvedEntry( downloadSymbol, (Context context, ModuleLiteral env, EvaluationStackFrame args) => DownloadFile(downloadData), // The following position is a contract right now iwtht he generated ast in the workspace resolver // we have to find a nicer way to handle and register these. TypeScript.Net.Utilities.LineInfo.FromLineAndPosition(0, 1) ); currentFileModule.AddResolvedEntry(downloadSymbol, downloadResolvedEntry); currentFileModule.AddResolvedEntry(new FilePosition(1, sourceFilePath), downloadResolvedEntry); // Contents.All var extractedSymbol = FullSymbol.Create(m_context.SymbolTable, "extracted"); var contentsResolvedEntry = new ResolvedEntry( extractedSymbol, (Context context, ModuleLiteral env, EvaluationStackFrame args) => ExtractFile(downloadData), // The following position is a contract right now iwtht he generated ast in the workspace resolver // we have to find a nicer way to handle and register these. TypeScript.Net.Utilities.LineInfo.FromLineAndPosition(0, 3) ); currentFileModule.AddResolvedEntry(extractedSymbol, contentsResolvedEntry); currentFileModule.AddResolvedEntry(new FilePosition(3, sourceFilePath), contentsResolvedEntry); var moduleInfo = new UninstantiatedModuleInfo( // We can register an empty one since we have the module populated properly new SourceFile( sourceFilePath, new Declaration[] { }), currentFileModule, m_context.QualifierTable.EmptyQualifierSpaceId); moduleRegistry.AddUninstantiatedModuleInfo(moduleInfo); return(Task.FromResult <bool?>(true)); }
private static EvaluationResult GetDirectoryValues(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(GetPathValues(context, args, typeof(DirectoryArtifact))); }
private static EvaluationResult GetNewIpcMoniker(Context context, ModuleLiteral env, EvaluationStackFrame args) { var semiStableHash = context.GetPipConstructionHelper().GetNextSemiStableHash(); return(EvaluationResult.Create(IpcFactory.GetProvider().LoadOrCreateMoniker(string.Format(CultureInfo.InvariantCulture, "{0:X16}", semiStableHash)))); }
private static EvaluationResult GetPathValues(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(GetPathValues(context, args, typeof(AbsolutePath))); }
private static EvaluationResult GetIpcServerMoniker(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(context.GetPipConstructionHelper().PipGraph.GetApiServerMoniker())); }
private static EvaluationResult NewLine(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(EvaluationResult.Create(Environment.NewLine)); }
private EvaluationResult WriteAllText(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(WriteFileHelper(context, env, args, WriteFileMode.WriteAllText)); }
private static EvaluationResult ExpandEnvironmentVariablesInString(Context context, ModuleLiteral env, EvaluationStackFrame args) { var unexpandedString = Args.AsString(args, 0); if (StringVariableExpander.TryExpandVariablesInString(unexpandedString, context.FrontEndHost.Engine, out string expandedString)) { return(EvaluationResult.Create(expandedString)); } // No expansion occurred return(EvaluationResult.Create(unexpandedString)); }
private EvaluationResult WriteFileHelper(Context context, ModuleLiteral env, EvaluationStackFrame args, WriteFileMode mode) { AbsolutePath path; string[] tags; string description; PipData pipData; if (args.Length > 0 && args[0].Value is ObjectLiteral) { var obj = Args.AsObjectLiteral(args, 0); path = Converter.ExtractPath(obj, m_writeOutputPath, allowUndefined: false); tags = Converter.ExtractStringArray(obj, m_writeTags, allowUndefined: true); description = Converter.ExtractString(obj, m_writeDescription, allowUndefined: true); switch (mode) { case WriteFileMode.WriteData: var data = obj[m_writeContents]; pipData = ProcessData(context, data, new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllLines: var lines = Converter.ExtractArrayLiteral(obj, m_writeLines); var entry = context.TopStack; var newData = ObjectLiteral.Create( new List <Binding> { new Binding(m_dataSeparator, Environment.NewLine, entry.InvocationLocation), new Binding(m_dataContents, lines, entry.InvocationLocation), }, lines.Location, entry.Path); pipData = ProcessData(context, EvaluationResult.Create(newData), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllText: var text = Converter.ExtractString(obj, m_writeText); pipData = ProcessData(context, EvaluationResult.Create(text), new ConversionContext(pos: 1)); break; default: throw Contract.AssertFailure("Unknown WriteFileMode."); } } else { path = Args.AsPath(args, 0, false); tags = Args.AsStringArrayOptional(args, 2); description = Args.AsStringOptional(args, 3); switch (mode) { case WriteFileMode.WriteFile: var fileContent = Args.AsIs(args, 1); // WriteFile has a separator argument with default newline var separator = Args.AsStringOptional(args, 3) ?? Environment.NewLine; description = Args.AsStringOptional(args, 4); pipData = CreatePipDataForWriteFile(context, fileContent, separator); break; case WriteFileMode.WriteData: var data = Args.AsIs(args, 1); pipData = ProcessData(context, EvaluationResult.Create(data), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllLines: var lines = Args.AsArrayLiteral(args, 1); var entry = context.TopStack; var newData = ObjectLiteral.Create( new List <Binding> { new Binding(m_dataSeparator, Environment.NewLine, entry.InvocationLocation), new Binding(m_dataContents, lines, entry.InvocationLocation), }, lines.Location, entry.Path); pipData = ProcessData(context, EvaluationResult.Create(newData), new ConversionContext(pos: 1)); break; case WriteFileMode.WriteAllText: var text = Args.AsString(args, 1); pipData = ProcessData(context, EvaluationResult.Create(text), new ConversionContext(pos: 1)); break; default: throw Contract.AssertFailure("Unknown WriteFileMode."); } } FileArtifact result; if (!context.GetPipConstructionHelper().TryWriteFile(path, pipData, WriteFileEncoding.Utf8, tags, description, out result)) { // Error has been logged return(EvaluationResult.Error); } return(new EvaluationResult(result)); }
/// <inheritdoc /> public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context) { errors.ReportUnsupportedTypeValueObjectException(environment, this, location); }
public static UniversalLocation AsUniversalLocation(this LineInfo lineInfo, ModuleLiteral moduleLiteral, ImmutableContextBase context) { var path = moduleLiteral.GetPath(context); return(new UniversalLocation(null, lineInfo, path, context.PathTable)); }