Esempio n. 1
0
 public static Location AsLoggingLocation(this LineInfo lineInfo, ModuleLiteral moduleLiteral, ImmutableContextBase context)
 {
     return(lineInfo.AsUniversalLocation(moduleLiteral, context).AsLoggingLocation());
 }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
 /// <inheritdoc/>
 public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context)
 {
     errors.ReportInvalidRadix(environment, expression, location, m_radix);
 }
Esempio n. 4
0
        private static EvaluationResult GetPathValue(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var path = GetPathValue(context, args);

            return(path.IsValid ? EvaluationResult.Create(path) : EvaluationResult.Undefined);
        }
Esempio n. 5
0
        private static EvaluationResult HasVariable(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var name = Args.AsString(args, 0);

            return(EvaluationResult.Create(GetRawValue(context, name) != null));
        }
Esempio n. 6
0
        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()));
            }
        }
Esempio n. 7
0
 /// <inheritdoc />
 public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context)
 {
     errors.ReportJsonUnsuportedDynamicFieldsForSerialization(environment, this, location);
 }
Esempio n. 8
0
 private static EvaluationResult GetSpecFile(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(FileArtifact.CreateSourceFile(context.LastActiveUsedPath)));
 }
Esempio n. 9
0
 private static EvaluationResult GetSpecFileDirectory(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(DirectoryArtifact.CreateWithZeroPartialSealId(context.LastActiveUsedPath.GetParent(context.FrontEndContext.PathTable))));
 }
Esempio n. 10
0
 private static EvaluationResult IsWindowsOS(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(Host.Current.CurrentOS == BuildXL.Interop.OperatingSystem.Win));
 }
Esempio n. 11
0
 private EvaluationResult GetCurrentHost(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(m_currentHost));
 }
Esempio n. 12
0
 private static EvaluationResult GetLastActiveUseModuleName(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(context.LastActiveUsedModuleName));
 }
Esempio n. 13
0
 private static EvaluationResult GetLastActiveUseNamespace(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(context.TopLevelValueInfo.ValueName.GetParent(context.FrontEndContext.SymbolTable).ToString(context.FrontEndContext.SymbolTable)));
 }
Esempio n. 14
0
        private static EvaluationResult GetTempDirectory(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var directory = context.GetPipConstructionHelper().GetUniqueTempDirectory();

            return(EvaluationResult.Create(directory));
        }
Esempio n. 15
0
 private static EvaluationResult Empty(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(OrderedSet.Empty));
 }
Esempio n. 16
0
        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))));
        }
Esempio n. 17
0
 private static EvaluationResult Create(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(Add(context, OrderedSet.Empty, args[0], args));
 }
Esempio n. 18
0
 /// <inheritdoc />
 protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame)
 {
     return(EvaluationResult.Create(Value));
 }
Esempio n. 19
0
 /// <inheritdoc />
 protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame)
 {
     return(Expression.Eval(context, env, frame));
 }
Esempio n. 20
0
        /// <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));
        }
Esempio n. 21
0
 private static EvaluationResult GetDirectoryValues(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(GetPathValues(context, args, typeof(DirectoryArtifact)));
 }
Esempio n. 22
0
        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))));
        }
Esempio n. 23
0
 private static EvaluationResult GetPathValues(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(GetPathValues(context, args, typeof(AbsolutePath)));
 }
Esempio n. 24
0
 private static EvaluationResult GetIpcServerMoniker(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(context.GetPipConstructionHelper().PipGraph.GetApiServerMoniker()));
 }
Esempio n. 25
0
 private static EvaluationResult NewLine(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(EvaluationResult.Create(Environment.NewLine));
 }
Esempio n. 26
0
 private EvaluationResult WriteAllText(Context context, ModuleLiteral env, EvaluationStackFrame args)
 {
     return(WriteFileHelper(context, env, args, WriteFileMode.WriteAllText));
 }
Esempio n. 27
0
        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));
        }
Esempio n. 28
0
        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));
        }
Esempio n. 29
0
 /// <inheritdoc />
 public override void ReportError(EvaluationErrors errors, ModuleLiteral environment, LineInfo location, Expression expression, Context context)
 {
     errors.ReportUnsupportedTypeValueObjectException(environment, this, location);
 }
Esempio n. 30
0
        public static UniversalLocation AsUniversalLocation(this LineInfo lineInfo, ModuleLiteral moduleLiteral, ImmutableContextBase context)
        {
            var path = moduleLiteral.GetPath(context);

            return(new UniversalLocation(null, lineInfo, path, context.PathTable));
        }