Esempio n. 1
0
        /// <inheritdoc />
        public Task <bool?> TryConvertModuleToEvaluationAsync([NotNull] ParsedModule module, [NotNull] 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,
                m_constants.Global,
                package,
                m_sharedModuleRegistry,
                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);

            m_sharedModuleRegistry.AddUninstantiatedModuleInfo(moduleInfo);

            return(Task.FromResult <bool?>(true));
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts a file into a folder with in manifest based incrementality.
        /// </summary>
        internal async Task <EvaluationResult> PerformExtractOrIncrementalCheckAsync(DownloadData downloadData)
        {
            if (m_context.CancellationToken.IsCancellationRequested)
            {
                return(EvaluationResult.Canceled);
            }

            // Ensure file is downloaded
            var extractedFileResult = await DownloadFile(downloadData);

            if (extractedFileResult.IsErrorValue)
            {
                return(extractedFileResult);
            }

            var extractedFile = (FileArtifact)extractedFileResult.Value;

            var moduleDescriptor = m_workspaceResolver.GetModuleDescriptor(downloadData);

            var pipConstructionHelper = PipConstructionHelper.Create(
                m_context,
                m_frontEndHost.Engine.Layout.ObjectDirectory,
                m_frontEndHost.Engine.Layout.RedirectedDirectory,
                m_frontEndHost.Engine.Layout.TempDirectory,
                m_frontEndHost.PipGraph,
                moduleDescriptor.Id,
                moduleDescriptor.Name,
                RelativePath.Create(downloadData.ModuleSpecFile.GetName(m_context.PathTable)),
                FullSymbol.Create(m_context.SymbolTable, "extracted"),
                new LocationData(downloadData.ModuleSpecFile, 0, 0),
                m_context.QualifierTable.EmptyQualifierId);


            // When we don't have to extract we'll expose the downloaded file in the contents.
            if (downloadData.Settings.ArchiveType == DownloadArchiveType.File)
            {
                return(SealDirectory(
                           pipConstructionHelper,
                           downloadData,
                           DirectoryArtifact.CreateWithZeroPartialSealId(downloadData.DownloadedFilePath.GetParent(m_context.PathTable)),
                           SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .FromSortedArrayUnsafe(
                               ReadOnlyArray <FileArtifact> .FromWithoutCopy(new[] { extractedFile }),
                               OrdinalFileArtifactComparer.Instance)));
            }

            Statistics.Extractions.Total.Increment();

            using (Statistics.Extractions.UpToDateCheckDuration.Start(downloadData.Settings.Url))
            {
                var result = await CheckIfExtractIsNeededAsync(pipConstructionHelper, downloadData);

                if (result.IsErrorValue)
                {
                    Statistics.Extractions.Failures.Increment();
                }
                if (result != EvaluationResult.Continue)
                {
                    Statistics.Extractions.SkippedDueToManifest.Increment();
                    return(result);
                }
            }

            using (Statistics.Extractions.Duration.Start(downloadData.Settings.Url))
            {
                try
                {
                    if (!await Task.Run(
                            () => TryExtractToDisk(downloadData),
                            m_context.CancellationToken))
                    {
                        Statistics.Extractions.Failures.Increment();
                        return(EvaluationResult.Error);
                    }
                }
                catch (TaskCanceledException)
                {
                    return(EvaluationResult.Canceled);
                }
            }

            using (Statistics.Extractions.UpToDateCheckDuration.Start(downloadData.Settings.Url))
            {
                var result = await ValidateAndStoreIncrementalExtractState(pipConstructionHelper, downloadData);

                if (result.IsErrorValue)
                {
                    Statistics.Extractions.Failures.Increment();
                }
                return(result);
            }
        }
Esempio n. 3
0
 public FullSymbol GetFullSymbol() => FullSymbol.Create(m_symbolTable, GetSymbolAtom());