Exemplo n.º 1
0
        public Task <bool> IsUpToDateAsync(BuildAction buildAction, TextWriter logWriter, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            return(ExecuteUnderLockAsync(IsUpToDateInternalAsync, cancellationToken));

            async Task <bool> IsUpToDateInternalAsync(CancellationToken token)
            {
                token.ThrowIfCancellationRequested();

                var sw = Stopwatch.StartNew();

                await InitializeAsync(token);

                LogLevel requestedLogLevel = await _projectSystemOptions.GetFastUpToDateLoggingLevelAsync(token);

                var logger = new BuildUpToDateCheckLogger(logWriter, requestedLogLevel, _configuredProject.UnconfiguredProject.FullPath);

                try
                {
                    State state = _state;

                    if (!CheckGlobalConditions(buildAction, logger, state))
                    {
                        return(false);
                    }

                    // Short-lived cache of timestamp by path
                    var timestampCache = new Dictionary <string, DateTime>(StringComparers.Paths);

                    if (!CheckInputsAndOutputs(logger, timestampCache, state) ||
                        !CheckMarkers(logger, timestampCache, state) ||
                        !CheckCopyToOutputDirectoryFiles(logger, timestampCache, state) ||
                        !CheckCopiedOutputFiles(logger, timestampCache, state))
                    {
                        return(false);
                    }

                    _telemetryService.PostEvent(TelemetryEventName.UpToDateCheckSuccess);
                    logger.Info("Project is up to date.");
                    return(true);
                }
                finally
                {
                    lock (_stateLock)
                    {
                        _state = _state.WithLastCheckedAtUtc(DateTime.UtcNow);
                    }

                    logger.Verbose("Up to date check completed in {0:N1} ms", sw.Elapsed.TotalMilliseconds);
                }
            }
        }
        public async Task <bool> IsUpToDateAsync(BuildAction buildAction, TextWriter logWriter, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            EnsureInitialized();

            var requestedLogLevel = await _projectSystemOptions.GetFastUpToDateLoggingLevelAsync().ConfigureAwait(false);

            var logger = new Logger(logWriter, requestedLogLevel, _configuredProject.UnconfiguredProject.FullPath);

            if (!CheckGlobalConditions(buildAction, logger))
            {
                return(false);
            }

            var timestampCache = _fileTimestampCache.Value.TimestampCache ??
                                 new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase);
            var latestInput    = GetLatestInput(CollectInputs(logger), timestampCache);
            var earliestOutput = GetEarliestOutput(CollectOutputs(logger), timestampCache);

            if (latestInput.time != null)
            {
                logger.Info("Latest write timestamp on input is {0} on '{1}'.", latestInput.time.Value, latestInput.path);
            }
            else
            {
                logger.Info("Input '{0}' does not exist.", latestInput.path);
            }

            if (earliestOutput.time != null)
            {
                logger.Info("Earliest write timestamp on output is {0} on '{1}'.", earliestOutput.time.Value, earliestOutput.path);
            }
            else
            {
                logger.Info("Output '{0}' does not exist.", earliestOutput.path);
            }

            // We are up to date if the earliest output write happened after the latest input write
            var markersUpToDate = CheckMarkers(logger, timestampCache);
            var isUpToDate      =
                latestInput.time != null &&
                earliestOutput.time != null &&
                earliestOutput.time > latestInput.time &&
                markersUpToDate;

            logger.Info("Project is{0} up to date.", (!isUpToDate ? " not" : ""));

            return(isUpToDate);
        }
Exemplo n.º 3
0
        public async Task <bool> IsEnabledAsync(CancellationToken cancellationToken)
        {
            LogLevel logLevel = await _projectSystemOptions.GetFastUpToDateLoggingLevelAsync(cancellationToken);

            if (logLevel != LogLevel.None)
            {
                // Always display if the user has enabled any kind of up-to-date check logging
                return(true);
            }

            await _project.Services.ThreadingPolicy.SwitchToUIThread(cancellationToken);

            IVsFeatureFlags featureFlagsService = _featureFlagsService.Value;

            return(featureFlagsService.IsFeatureEnabled("ManagedProjectSystem.EnableIncrementalBuildFailureOutputLogging", defaultValue: false));
        }