internal void AllocateFields(ReadOnlyArray<BoundSpillTemp> spills)
 {
     foreach (var spill in spills)
     {
         AllocateField(spill);
     }
 }
Exemplo n.º 2
0
        public Sensor(string name, int index, bool defaultHidden, 
            SensorType sensorType, Hardware hardware,
            ParameterDescription[] parameterDescriptions, ISettings settings)
        {
            this.index = index;
              this.defaultHidden = defaultHidden;
              this.sensorType = sensorType;
              this.hardware = hardware;
              Parameter[] parameters = new Parameter[parameterDescriptions == null ?
            0 : parameterDescriptions.Length];
              for (int i = 0; i < parameters.Length; i++ )
            parameters[i] = new Parameter(parameterDescriptions[i], this, settings);
              this.parameters = parameters;

              this.settings = settings;
              this.defaultName = name;
              this.name = settings.GetValue(
            new Identifier(Identifier, "name").ToString(), name);

              GetSensorValuesFromSettings();

              hardware.Closing += delegate(IHardware h) {
            SetSensorValuesToSettings();
              };
        }
Exemplo n.º 3
0
        public ReadOnlyArray<JsonProperty> GetProperties()
        {
            var builder = new ReadOnlyArray<JsonProperty>.Builder();

            foreach (var assignment in _assignments)
            {
                if (assignment.Value.Mode == PropertyExpressionType.Data)
                {
                    builder.Add(new JsonDataProperty(
                        assignment.Key,
                        assignment.Value.Expression
                    ));
                }
                else
                {
                    builder.Add(new JsonAccessorProperty(
                        assignment.Key,
                        assignment.Value.GetExpression,
                        assignment.Value.SetExpression
                    ));
                }
            }

            return builder.ToReadOnly();
        }
Exemplo n.º 4
0
        public RomInfo(byte[] rom)
        {
            Rom = new ReadOnlyArray<byte>(rom);

            NintendoGraphic = new byte[48];
            Array.Copy(rom, 0x0104, NintendoGraphic, 0, 48);

            var name = new byte[14];
            Array.Copy(rom, 0x0134, name, 0, 14);
            RomName = new string(name.Where(b => b != 0).Select(b => (char) b).ToArray());

            IsColor = rom[0x0143] == 0x80;
            LicenseeCode = (ushort)((rom[0x0144] << 8) | rom[0x0145]);
            IsSuperGb = rom[0x0146] == 3;

            CartridgeInfo = new CartridgeInfo(rom[0x0147]);
            RomSize = new RomSize(rom[0x0148]);
            RamSize = new RamSize(rom[0x0149]);

            Japanese = rom[0x014A] == 1;
            OldLincenseeCode = rom[0x01B];
            MaskRomVersionNumber = rom[0x014C];

            ComplementCheck = rom[0x014D];
            Checksum = (ushort)((rom[0x014E] << 8) | rom[0x014F]);
        }
Exemplo n.º 5
0
        public Z80(ReadOnlyArray<byte> rom, IMemoryManagementUnit mmu)
        {
            InitOpcodes();

            this.mmu = mmu;
            this.rom = rom;
        }
Exemplo n.º 6
0
        public Closure(ReadOnlyArray<string> fields)
        {
            if (fields == null)
                throw new ArgumentNullException("fields");

            Fields = fields;
        }
Exemplo n.º 7
0
 public CustomAttribute(
     IMethodReference constructor,
     ITypeReference type,
     ReadOnlyArray<MetadataConstant> positionalArguments) :
     this(constructor, type, positionalArguments, ReadOnlyArray<IMetadataNamedArgument>.Empty)
 {
 }
Exemplo n.º 8
0
 public Scope(BodyType bodyType, Scope parent, ReadOnlyArray<string> parameters)
 {
     _bodyType = bodyType;
     Parent = parent;
     _parameters = parameters;
     _rootScope = parent != null ? parent._rootScope : this;
 }
        /// <summary>
        /// Spill an expression list with a receiver (e.g. array access, method call), where at least one of the
        /// receiver or the arguments contains an await expression.
        /// </summary>
        private Tuple<BoundExpression, ReadOnlyArray<BoundExpression>> SpillExpressionsWithReceiver(
            BoundExpression receiverOpt,
            ReadOnlyArray<BoundExpression> expressions,
            SpillBuilder spillBuilder,
            ReadOnlyArray<RefKind> refKindsOpt)
        {
            if (receiverOpt == null)
            {
                return Tuple.Create(default(BoundExpression), SpillExpressionList(spillBuilder, expressions));
            }

            // We have a non-null receiver, and an expression of the form:
            //     receiver[index1, index2, ..., indexN]
            //     or:
            //     receiver(arg1, arg2, ... argN)

            // Build a list containing the receiver and all expressions (in that order)
            var allExpressions = ReadOnlyArray<BoundExpression>.CreateFrom(receiverOpt).Concat(expressions);
            var allRefKinds = (refKindsOpt != null)
                ? ReadOnlyArray<RefKind>.CreateFrom(RefKind.None).Concat(refKindsOpt)
                : ReadOnlyArray<RefKind>.Empty;

            // Spill the expressions (and possibly the receiver):
            var allSpilledExpressions = SpillExpressionList(spillBuilder, allExpressions, allRefKinds);

            var spilledReceiver = allSpilledExpressions.First();
            var spilledArguments = allSpilledExpressions.RemoveFirst();
            return Tuple.Create(spilledReceiver, spilledArguments);
        }
        /// <summary>
        /// Returns a constructed type given its instance type and type arguments.
        /// </summary>
        /// <param name="instanceType">the instance type to construct the result from</param>
        /// <param name="typeArguments">the immediate type arguments to be replaced for type parameters in the instance type</param>
        /// <returns></returns>
        internal static NamedTypeSymbol Construct1(this NamedTypeSymbol instanceType, ReadOnlyArray<TypeSymbol> typeArguments)
        {
            Debug.Assert(instanceType.ConstructedFrom == instanceType);
            
            var sequenceEqual = true;
            var args = instanceType.TypeArguments;

            if (args.Count != typeArguments.Count)
            {
                sequenceEqual = false;
            }
            else
            {
                for (int i = 0; i < args.Count; i++)
                {
                    if (args[i] != typeArguments[i])
                    {
                        sequenceEqual = false;
                        break;
                    }
                }
            }

            return sequenceEqual
                ? instanceType
                : ConstructedNamedTypeSymbol.Make(instanceType, typeArguments);
        }
Exemplo n.º 11
0
        public BodySyntax ExecuteBlockStatements(ReadOnlyArray<string> parameters)
        {
            _builder.EnterFunctionBody(parameters);

            blockStatements();

            return _builder.ExitBody();
        }
Exemplo n.º 12
0
            public AsyncStruct(MethodSymbol method, TypeCompilationState compilationState)
                : base(method, GeneratedNames.MakeIteratorOrAsyncDisplayClassName(method.Name, compilationState.GenerateTempNumber()), TypeKind.Struct)
            {
                this.interfaces = ReadOnlyArray<NamedTypeSymbol>.CreateFrom(
                    compilationState.EmitModule.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine));

                this.constructor = new SynthesizedInstanceConstructor(this);
            }
 public UnconfirmedCOVNotificationRequest(uint subscriberProcessIdentifier, ObjectId initiatingDeviceIdentifier, ObjectId monitoredObjectIdentifier, uint timeRemaining, ReadOnlyArray<PropertyValue> listOfValues)
 {
     this.SubscriberProcessIdentifier = subscriberProcessIdentifier;
     this.InitiatingDeviceIdentifier = initiatingDeviceIdentifier;
     this.MonitoredObjectIdentifier = monitoredObjectIdentifier;
     this.TimeRemaining = timeRemaining;
     this.ListOfValues = listOfValues;
 }
Exemplo n.º 14
0
 public GuitarData(Wiimote Owner)
     : base(Owner)
 {
     _stick = new byte[2];
     _stick_readonly = new ReadOnlyArray<byte>(_stick);
     _frets = new bool[5];
     _frets_readonly = new ReadOnlyArray<bool> (_frets);
 }
        public AssemblyResolver WithPaths(ReadOnlyArray<string> paths)
        {
            if (paths == this.searchPaths)
            {
                return this;
            }

            return new AssemblyResolver(paths, getFullPath, architectureFilter, preferredCulture);
        }
Exemplo n.º 16
0
        public NunchuckData(Wiimote Owner)
            : base(Owner)
        {
            _accel = new int[3];
            _accel_readonly = new ReadOnlyArray<int>(_accel);

            _stick = new byte[2];
            _stick_readonly = new ReadOnlyArray<byte>(_stick);
        }
Exemplo n.º 17
0
        public static NamedTypeSymbol Construct(this NamedTypeSymbol type, ReadOnlyArray<TypeSymbol> arguments)
        {
            Debug.Assert(type != null);
            Debug.Assert(arguments.IsNotNull);
            TypeMap map = new TypeMap(ReadOnlyArray<TypeSymbol>.CreateFrom(type.ConstructedFrom.TypeParameters),
                                            arguments);

            return map.SubstituteNamedType(type.ConstructedFrom);
        }
Exemplo n.º 18
0
 public ListOfEventSummariesType(ObjectId objectIdentifier, EventState eventState, EventTransitionBits acknowledgedTransitions, ReadOnlyArray<TimeStamp> eventTimeStamps, NotifyType notifyType, EventTransitionBits eventEnable, ReadOnlyArray<uint> eventPriorities)
 {
     this.ObjectIdentifier = objectIdentifier;
     this.EventState = eventState;
     this.AcknowledgedTransitions = acknowledgedTransitions;
     this.EventTimeStamps = eventTimeStamps;
     this.NotifyType = notifyType;
     this.EventEnable = eventEnable;
     this.EventPriorities = eventPriorities;
 }
Exemplo n.º 19
0
 public ReadRangeAck(ObjectId objectIdentifier, PropertyIdentifier propertyIdentifier, Option<uint> propertyArrayIndex, ResultFlags resultFlags, uint itemCount, ReadOnlyArray<GenericValue> itemData, Option<uint> firstSequenceNumber)
 {
     this.ObjectIdentifier = objectIdentifier;
     this.PropertyIdentifier = propertyIdentifier;
     this.PropertyArrayIndex = propertyArrayIndex;
     this.ResultFlags = resultFlags;
     this.ItemCount = itemCount;
     this.ItemData = itemData;
     this.FirstSequenceNumber = firstSequenceNumber;
 }
Exemplo n.º 20
0
 internal FullAndPublicKeyResults(byte[] keyPair, ReadOnlyArray<byte> publicKey, string container, DiagnosticBag bag, string keyFileName)
 {
     m_KeyPair = keyPair;
     m_PublicKey = publicKey;
     m_KeyContainer = container;
     m_Diagnostics = bag;
     m_KeyFileName = keyFileName;
     System.Diagnostics.Debug.Assert(m_KeyContainer == null || m_KeyPair == null, "Only one of keyContainer or keyPair can be non-null");
     System.Diagnostics.Debug.Assert((m_KeyPair != null) ? (m_KeyFileName != null) : true, "if m_KeyPair is set, so must m_KeyFileName.");
 }
Exemplo n.º 21
0
        // todo: UnlockedAchievements

        public AchievementManager(string filePath, IEnumerable<Achievement> achievements)
            : base(filePath)
        {
            Ensure.NotNull(achievements);
            _achievements = new ReadOnlyArray<Achievement>(achievements.ToArray());
            _achievementsByName = _achievements.ToDictionary(achivement => achivement.Name);

            this.Load();
            this.HookAchievementUnlockedEvents();
        }
Exemplo n.º 22
0
 public WinMDModule(
     ModuleMetadata owner,
     AbstractMemoryBlock memoryBlock,
     PEFileReader peFileReader,
     ReadOnlyArray<AssemblyIdentity> referencedAssemblies,
     WinMDScenario scenario)
     : base(owner, memoryBlock, peFileReader, referencedAssemblies)
 {
     this.scenario = scenario;
     this.winMdStartIndex = (uint)referencedAssemblies.Count - WinMdExtraRefs;
 }
Exemplo n.º 23
0
 public CustomAttribute(
     IMethodReference constructor,
     ITypeReference type,
     ReadOnlyArray<MetadataConstant> positionalArguments,
     ReadOnlyArray<IMetadataNamedArgument> namedArguments)
 {
     this.constructor = constructor;
     this.type = type;
     this.positionalArguments = positionalArguments;
     this.namedArguments = namedArguments;
 }
Exemplo n.º 24
0
        public static ReadOnlyArray<BoundFunction> Gather(BoundBody body)
        {
            if (body == null)
                throw new ArgumentNullException("body");

            var functions = new ReadOnlyArray<BoundFunction>.Builder();

            new Gatherer(functions).Visit(body);

            return functions.ToReadOnlyArray();
        }
Exemplo n.º 25
0
        public BodySyntax(BodyType bodyType, ReadOnlyArray<SyntaxNode> statements, ReadOnlyArray<IIdentifier> identifiers, bool isStrict, Closure closure)
            : base(statements)
        {
            if (identifiers == null)
                throw new ArgumentNullException("identifiers");

            BodyType = bodyType;
            Identifiers = identifiers;
            IsStrict = isStrict;
            Closure = closure;
        }
        //TODO: overloads/defaults

        public static string GetDescriptionString(ReadOnlyArray<SymbolDescriptionPart> actual)
        {
            var actualBuilder = new StringBuilder();

            foreach (var part in actual)
            {
                actualBuilder.Append(part.Text);
            }

            return actualBuilder.ToString();
        }
Exemplo n.º 27
0
        public BoundFunction Update(string name, ReadOnlyArray<string> parameters, BoundBody body, SourceLocation location)
        {
            if (
                name == Name &&
                parameters == Parameters &&
                body == Body &&
                location == Location
            )
                return this;

            return new BoundFunction(name, parameters, body, location);
        }
Exemplo n.º 28
0
        internal static BoundStatementList AnalyzeFieldInitializers(MethodBodyCompiler methodCompiler, MethodSymbol constructor, ReadOnlyArray<BoundInitializer> boundInitializers)
        {
            if (boundInitializers.IsNull)
            {
                return null;
            }

            // The lowered tree might be reused in multiple constructors. Therefore, unless there is just a single constructor 
            // (e.g. in interactive submission), the lowered code should not refer to it.
            var initializerStatements = InitializerRewriter.Rewrite(boundInitializers, constructor.IsInteractiveSubmissionConstructor ? constructor : null);
            return (BoundStatementList)RewritePass.Rewrite(methodCompiler, constructor.ContainingType, initializerStatements);
        }
Exemplo n.º 29
0
 /// <summary>
 /// Script class declaration constructor.
 /// </summary>
 internal ImplicitTypeDeclaration(SyntaxReference memberContainer, ReadOnlyArray<SingleTypeDeclaration> children, ISet<string> memberNames, string name) :
     base(
     kind: DeclarationKind.Class,
     name: name,
     arity: 0,
     modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Sealed,
     syntaxReference: memberContainer,
     nameLocation: new SourceLocation(memberContainer),
     memberNames: memberNames,
     children: children)
 {
 }
Exemplo n.º 30
0
        public static BoundProgram Perform(BoundProgram program, IList<BoundExpression> resultExpressions)
        {
            // If the last statement of the program is a return, we don't
            // have to rewrite the program.

            var body = program.Body;
            if (
                body.Body.Nodes.Count > 0 &&
                body.Body.Nodes[body.Body.Nodes.Count - 1] is BoundReturn
            )
                return program;

            // If we don't have any result expressions, we only have to
            // insert a return statement.

            if (resultExpressions == null || resultExpressions.Count == 0)
            {
                // Create a new nodes list with the added return statement.

                var nodes = new ReadOnlyArray<BoundStatement>.Builder();

                nodes.AddRange(body.Body.Nodes);
                nodes.Add(new BoundReturn(
                    null,
                    SourceLocation.Missing
                ));

                // Return the updated program.

                return program.Update(
                    body.Update(
                        body.Body.Update(
                            body.Body.Temporaries,
                            nodes.ToReadOnly(),
                            body.Body.Location
                            ),
                        body.Closure,
                        body.ScopedClosure,
                        body.Arguments,
                        body.Locals,
                        body.MappedArguments,
                        body.Flags,
                        body.TypeManager
                    )
                );
            }

            // Otherwise, we need to do a full rewrite.

            return program.Update(
                (BoundBody)new Rewriter(resultExpressions, body.TypeManager).Visit(program.Body)
            );
        }
        public void ProcessIsProperlyConfigured()
        {
            var project = CreateProjectWithPredictions("A.proj");

            var testProj = Start()
                           .Add(project)
                           .ScheduleAll()
                           .AssertSuccess()
                           .RetrieveSuccessfulProcess(project);

            // Undeclared sources are allowed as long as they are true sources
            Assert.True(testProj.AllowUndeclaredSourceReads);
            // Double writes are allowed as long as the written content is the same
            Assert.True(testProj.DoubleWritePolicy == DoubleWritePolicy.AllowSameContentDoubleWrites);
            // Working directory is the project directory
            Assert.True(testProj.WorkingDirectory == project.FullPath.GetParent(PathTable));
            // Log file is configured
            testProj.GetOutputs().Any(fa => fa.Path.GetName(PathTable).ToString(PathTable.StringTable) == "msbuild.log");
            // Surviving processes are configured
            testProj.AllowedSurvivingChildProcessNames.ToReadOnlySet().SetEquals(ReadOnlyArray <PathAtom> .FromWithoutCopy(
                                                                                     PathAtom.Create(PathTable.StringTable, "mspdbsrv.exe"),
                                                                                     PathAtom.Create(PathTable.StringTable, "vctip.exe"),
                                                                                     PathAtom.Create(PathTable.StringTable, "conhost.exe")));
        }
    /// <summary>
    /// Constructor for PlayerInputMock.
    /// Use for automating a player-controlled player.
    /// </summary>
    /// <param name="playerNumber">Players number</param>
    /// <param name="deviceId">Id of the players device</param>
    /// <param name="controlScheme">Control scheme of the players device</param>
    public PlayerInputMock(int playerNumber, int[] deviceIds, string controlScheme)
    {
        PlayerNumber  = playerNumber;
        DeviceIds     = deviceIds;
        ControlScheme = controlScheme;
        ReadOnlyArray <Gamepad> devices = Gamepad.all;

        // Search input devices for the fake input
        foreach (Gamepad device in devices)
        {
            if (device.name == "MockGamepad" + PlayerNumber)
            {
                Gamepad = device;
                break;
            }
        }

        // if not found, add it and return it
        if (Gamepad == null)
        {
            Gamepad = InputSystem.AddDevice <Gamepad>("MockGamepad" + PlayerNumber);
        }
        mockDeviceId = Gamepad.deviceId;
    }
Exemplo n.º 33
0
        public static Process CreateDummyProcessWithInputs(IEnumerable <FileArtifact> inputs, BuildXLContext context)
        {
            FileArtifact output = FileArtifact.CreateSourceFile(AbsolutePath.Create(context.PathTable, @"\\FAKEPATH\output" + s_procCounter + ".txt")).CreateNextWrittenVersion();

            s_procCounter++;
            FileArtifact exe = FileArtifact.CreateSourceFile(AbsolutePath.Create(context.PathTable, @"\\FAKEPATH\tool.exe"));

            var pipDataBuilder = new PipDataBuilder(context.StringTable);

            return(new Process(
                       executable: exe,
                       workingDirectory: AbsolutePath.Create(context.PathTable, @"\\FAKEPATH\"),
                       arguments: pipDataBuilder.ToPipData(" ", PipDataFragmentEscaping.NoEscaping),
                       responseFile: FileArtifact.Invalid,
                       responseFileData: PipData.Invalid,
                       environmentVariables: ReadOnlyArray <EnvironmentVariable> .Empty,
                       standardInput: FileArtifact.Invalid,
                       standardOutput: FileArtifact.Invalid,
                       standardError: FileArtifact.Invalid,
                       standardDirectory: output.Path.GetParent(context.PathTable),
                       warningTimeout: null,
                       timeout: null,
                       dependencies: ReadOnlyArray <FileArtifact> .From(inputs.Union(new[] { exe })),
                       outputs: ReadOnlyArray <FileArtifactWithAttributes> .FromWithoutCopy(output.WithAttributes()),
                       directoryDependencies: ReadOnlyArray <DirectoryArtifact> .Empty,
                       directoryOutputs: ReadOnlyArray <DirectoryArtifact> .Empty,
                       orderDependencies: ReadOnlyArray <PipId> .Empty,
                       untrackedPaths: ReadOnlyArray <AbsolutePath> .Empty,
                       untrackedScopes: ReadOnlyArray <AbsolutePath> .Empty,
                       tags: ReadOnlyArray <StringId> .Empty,
                       successExitCodes: ReadOnlyArray <int> .Empty,
                       semaphores: ReadOnlyArray <ProcessSemaphoreInfo> .Empty,
                       provenance: PipProvenance.CreateDummy(context),
                       toolDescription: StringId.Invalid,
                       additionalTempDirectories: ReadOnlyArray <AbsolutePath> .Empty));
        }
Exemplo n.º 34
0
    public Sensor(string name, int index, float? limit, SensorType sensorType, 
      IHardware hardware, ParameterDescription[] parameterDescriptions) 
    {
      this.defaultName = name;      
      this.index = index;
      this.defaultLimit = limit;
      this.sensorType = sensorType;
      this.hardware = hardware;
      Parameter[] parameters = new Parameter[parameterDescriptions.Length];
      for (int i = 0; i < parameters.Length; i++ ) 
        parameters[i] = new Parameter(parameterDescriptions[i], this);
      this.parameters = parameters;

      string configName = Config.Settings[Identifier + "/name"];
      if (configName != null)
        this.name = configName;
      else
        this.name = name;
      string configLimit = Config.Settings[Identifier + "/limit"];
      if (configLimit != null && configLimit != "")
        this.limit = float.Parse(configLimit);
      else
        this.limit = limit;
    }
Exemplo n.º 35
0
        public void InconsistentTempDirectoriesCreation(bool ensureTempDirectoriesCreation)
        {
            Configuration.Sandbox.EnsureTempDirectoriesExistenceBeforePipExecution = ensureTempDirectoriesCreation;

            AbsolutePath additionalTempDirectory = TempRootPath.Combine(
                Context.PathTable,
                nameof(InconsistentTempDirectoriesCreation) + "_" + ensureTempDirectoriesCreation);

            var pipBuilder = CreatePipBuilder(new[]
            {
                Operation.ReadFile(CreateSourceFile()),
                Operation.CreateDir(DirectoryArtifact.CreateWithZeroPartialSealId(additionalTempDirectory), additionalArgs: "--failIfExists"),
                Operation.WriteFile(CreateOutputFileArtifact())
            });

            pipBuilder.EnableTempDirectory();
            pipBuilder.AdditionalTempDirectories = ReadOnlyArray <AbsolutePath> .FromWithoutCopy(new AbsolutePath[] { additionalTempDirectory });

            if (OperatingSystemHelper.IsLinuxOS)
            {
                pipBuilder.AddUntrackedDirectoryScope(Context.PathTable, "/usr/local/lib/");
            }

            var processWithOutputs = SchedulePipBuilder(pipBuilder);
            var result             = RunScheduler();

            if (ensureTempDirectoriesCreation)
            {
                result.AssertFailure();
                AssertErrorEventLogged(ProcessesLogEventId.PipProcessError, 1);
            }
            else
            {
                result.AssertSuccess();
            }
        }
Exemplo n.º 36
0
        /// <nodoc />
        public IpcPip(
            IpcClientInfo ipcInfo,
            PipData arguments,
            FileArtifact outputFile,
            ReadOnlyArray <PipId> servicePipDependencies,
            ReadOnlyArray <FileArtifact> fileDependencies,
            ReadOnlyArray <DirectoryArtifact> directoryDependencies,
            ReadOnlyArray <FileOrDirectoryArtifact> skipMaterializationFor,
            ReadOnlyArray <StringId> tags,
            bool isServiceFinalization,
            bool mustRunOnOrchestrator,
            PipProvenance provenance)
        {
            Contract.Requires(ipcInfo != null);
            Contract.Requires(arguments.IsValid);
            Contract.Requires(outputFile.IsValid);
            Contract.Requires(servicePipDependencies.IsValid);
            Contract.Requires(fileDependencies.IsValid);
            Contract.Requires(directoryDependencies.IsValid);
            Contract.Requires(skipMaterializationFor.IsValid);
            Contract.RequiresForAll(servicePipDependencies, dependency => dependency.IsValid);
            Contract.RequiresForAll(fileDependencies, dependency => dependency.IsValid);
            Contract.RequiresForAll(directoryDependencies, dependency => dependency.IsValid);

            IpcInfo                        = ipcInfo;
            MessageBody                    = arguments;
            OutputFile                     = outputFile;
            ServicePipDependencies         = servicePipDependencies;
            FileDependencies               = fileDependencies;
            LazilyMaterializedDependencies = skipMaterializationFor;
            Tags = tags;
            IsServiceFinalization = isServiceFinalization;
            MustRunOnOrchestrator = mustRunOnOrchestrator;
            Provenance            = provenance;
            DirectoryDependencies = directoryDependencies;
        }
Exemplo n.º 37
0
        private void AddRequiredSurvivingChildren(ProcessBuilder processBuilder)
        {
            // mspdbsrv:
            // This process will live beyond the cl.exe call.
            // Allow the pip job object to clean the process without complaint.
            //
            // vctip.exe: On any compile error this telemetry upload exe will be run as a detached process.
            // Just let it be killed.
            // TODO: Can we stop it running? https://stackoverflow.microsoft.com/questions/74425/how-to-disable-vctip-exe-in-vc14
            //
            // conhost.exe: This process needs a little bit more time to finish after the main process. We shouldn't be allowing
            // this one to survive, we just need the timeout to be slightly more than zero. This will also be beneficial to other
            // arbitrary processeses that need a little bit more time. But, apparently, setting a timeout has a perf impact that is
            // being investigated. TODO: revisit this once this is fixed.
            //
            // All child processes: Don't wait to kill the processes.
            // CODESYNC: CloudBuild repo TrackerExecutor.cs "info.NestedProcessTerminationTimeout = TimeSpan.Zero"
            processBuilder.AllowedSurvivingChildProcessNames = ReadOnlyArray <PathAtom> .FromWithoutCopy(
                PathAtom.Create(m_context.StringTable, "mspdbsrv.exe"),
                PathAtom.Create(m_context.StringTable, "vctip.exe"),
                PathAtom.Create(m_context.StringTable, "conhost.exe"));

            processBuilder.NestedProcessTerminationTimeout = TimeSpan.Zero;
        }
    void OnEnable()
    {
        vector2Action.Enable();
        vector2Action.performed += UpdateVector2;
        vector2Action.started   += UpdateVector2;
        vector2Action.canceled  += UpdateVector2;

        ReadOnlyArray <InputControl> controls = vector2Action.controls;

        for (int i = 0; i < controls.Count; i++)
        {
            Vector2Control control = controls[i] as Vector2Control;
            if (control != null)
            {
                Vector2 value = control.ReadValue();
                status1Slider.value = value.x;
                status2Slider.value = value.y;
            }
            else
            {
                Debug.LogWarningFormat(this, "Vector2ControlActionStatus expects bindings of type {1}, but found {1} binding named {2}.", typeof(Vector2Control).FullName, controls[i].GetType().FullName, controls[i].name);
            }
        }
    }
Exemplo n.º 39
0
        public async Task Stress()
        {
            const int N              = 5;
            const int M              = N * N;
            var       context        = BuildXLContext.CreateInstanceForTesting();
            var       loggingContext = CreateLoggingContextForTest();
            var       pathTable      = context.PathTable;

            using (var tempFiles = new TempFileStorage(canGetFileNames: true))
            {
                var config = ConfigHelpers.CreateDefault(pathTable, tempFiles.GetUniqueFileName(), tempFiles);

                using (var pipTable = new PipTable(
                           context.PathTable,
                           context.SymbolTable,
                           initialBufferSize: 1024,
                           maxDegreeOfParallelism: (Environment.ProcessorCount + 2) / 3,
                           debug: false))
                {
                    var executionEnvironment = new PipQueueTestExecutionEnvironment(
                        context,
                        config,
                        pipTable,
                        Path.Combine(TestOutputDirectory, "temp"),
                        TryGetSubstSourceAndTarget(out string substSource, out string substTarget) ? (substSource, substTarget) : default((string, string)?),
                        GetSandboxConnection());

                    Func <RunnablePip, Task <PipResult> > taskFactory = async(runnablePip) =>
                    {
                        PipResult result;
                        var       operationTracker = new OperationTracker(runnablePip.LoggingContext);
                        var       pip = runnablePip.Pip;
                        using (var operationContext = operationTracker.StartOperation(PipExecutorCounter.PipRunningStateDuration, pip.PipId, pip.PipType, runnablePip.LoggingContext))
                        {
                            result = await TestPipExecutor.ExecuteAsync(operationContext, executionEnvironment, pip);
                        }

                        executionEnvironment.MarkExecuted(pip);
                        return(result);
                    };

                    string       executable         = CmdHelper.OsShellExe;
                    FileArtifact executableArtifact = FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, executable));

                    // This is the only file artifact we reference without a producer. Rather than scheduling a hashing pip, let's just invent one (so fingerprinting can succeed).
                    executionEnvironment.AddWellKnownFile(executableArtifact, WellKnownContentHashes.UntrackedFile);

                    using (var phase1PipQueue = new PipQueue(executionEnvironment.Configuration.Schedule))
                    {
                        // phase 1: create some files
                        var baseFileArtifacts = new List <FileArtifact>();
                        for (int i = 0; i < N; i++)
                        {
                            string       destination             = tempFiles.GetUniqueFileName();
                            AbsolutePath destinationAbsolutePath = AbsolutePath.Create(pathTable, destination);
                            FileArtifact destinationArtifact     = FileArtifact.CreateSourceFile(destinationAbsolutePath).CreateNextWrittenVersion();
                            baseFileArtifacts.Add(destinationArtifact);

                            PipData contents = PipDataBuilder.CreatePipData(
                                context.StringTable,
                                " ",
                                PipDataFragmentEscaping.CRuntimeArgumentRules,
                                i.ToString(CultureInfo.InvariantCulture));

                            var writeFile = new WriteFile(destinationArtifact, contents, WriteFileEncoding.Utf8, ReadOnlyArray <StringId> .Empty, PipProvenance.CreateDummy(context));
                            var pipId     = pipTable.Add((uint)(i + 1), writeFile);

                            var contentHash = ContentHashingUtilities.HashString(contents.ToString(pathTable));
                            executionEnvironment.AddExpectedWrite(writeFile, destinationArtifact, contentHash);

                            var runnable = RunnablePip.Create(loggingContext, executionEnvironment, pipId, pipTable.GetPipType(pipId), 0, taskFactory, 0);
                            runnable.Start(new OperationTracker(loggingContext), loggingContext);
                            runnable.SetDispatcherKind(DispatcherKind.IO);
                            phase1PipQueue.Enqueue(runnable);
                        }

                        phase1PipQueue.SetAsFinalized();
                        phase1PipQueue.DrainQueues();
                        await Task.WhenAll(
                            Enumerable.Range(0, 2).Select(
                                async range =>
                        {
                            using (var phase2PipQueue = new PipQueue(executionEnvironment.Configuration.Schedule))
                            {
                                // phase 2: do some more with those files
                                var pips         = new ConcurrentDictionary <PipId, Tuple <string, int> >();
                                var checkerTasks = new ConcurrentQueue <Task>();
                                Action <PipId, Task <PipResult> > callback =
                                    (id, task) =>
                                {
                                    XAssert.IsTrue(task.Status == TaskStatus.RanToCompletion);
                                    XAssert.IsFalse(task.Result.Status.IndicatesFailure());
                                    Tuple <string, int> t;
                                    if (!pips.TryRemove(id, out t))
                                    {
                                        XAssert.Fail();
                                    }

                                    checkerTasks.Enqueue(
                                        Task.Run(
                                            () =>
                                    {
                                        string actual = File.ReadAllText(t.Item1).Trim();

                                        // TODO: Make this async
                                        XAssert.AreEqual(actual, t.Item2.ToString());
                                    }));
                                };
                                var r = new Random(0);
                                for (int i = 0; i < M; i++)
                                {
                                    int sourceIndex             = r.Next(baseFileArtifacts.Count);
                                    FileArtifact sourceArtifact = baseFileArtifacts[sourceIndex];

                                    string destination = tempFiles.GetUniqueFileName();
                                    AbsolutePath destinationAbsolutePath = AbsolutePath.Create(pathTable, destination);
                                    FileArtifact destinationArtifact     = FileArtifact.CreateSourceFile(destinationAbsolutePath).CreateNextWrittenVersion();
                                    Pip pip;

                                    DispatcherKind queueKind;
                                    switch (r.Next(2))
                                    {
                                    case 0:
                                        pip       = new CopyFile(sourceArtifact, destinationArtifact, ReadOnlyArray <StringId> .Empty, PipProvenance.CreateDummy(context));
                                        queueKind = DispatcherKind.IO;
                                        executionEnvironment.AddExpectedWrite(pip, destinationArtifact, executionEnvironment.GetExpectedContent(sourceArtifact));
                                        break;

                                    case 1:
                                        string workingDirectory =
                                            OperatingSystemHelper.IsUnixOS ? "/tmp" :
                                            Environment.GetFolderPath(Environment.SpecialFolder.Windows);

                                        AbsolutePath workingDirectoryAbsolutePath = AbsolutePath.Create(pathTable, workingDirectory);

                                        var pipData = OperatingSystemHelper.IsUnixOS ?
                                                      PipDataBuilder.CreatePipData(pathTable.StringTable, " ", PipDataFragmentEscaping.CRuntimeArgumentRules, "-c", "'", "cp", sourceArtifact, destinationArtifact, "'") :
                                                      PipDataBuilder.CreatePipData(pathTable.StringTable, " ", PipDataFragmentEscaping.CRuntimeArgumentRules, "/d", "/c", "copy", "/B", sourceArtifact, destinationArtifact);

                                        queueKind = DispatcherKind.CPU;
                                        pip       = new Process(
                                            executableArtifact,
                                            workingDirectoryAbsolutePath,
                                            pipData,
                                            FileArtifact.Invalid,
                                            PipData.Invalid,
                                            ReadOnlyArray <EnvironmentVariable> .Empty,
                                            FileArtifact.Invalid,
                                            FileArtifact.Invalid,
                                            FileArtifact.Invalid,
                                            tempFiles.GetUniqueDirectory(pathTable),
                                            null,
                                            null,
                                            ReadOnlyArray <FileArtifact> .FromWithoutCopy(executableArtifact, sourceArtifact),
                                            ReadOnlyArray <FileArtifactWithAttributes> .FromWithoutCopy(destinationArtifact.WithAttributes()),
                                            ReadOnlyArray <DirectoryArtifact> .Empty,
                                            ReadOnlyArray <DirectoryArtifact> .Empty,
                                            ReadOnlyArray <PipId> .Empty,
                                            ReadOnlyArray <AbsolutePath> .From(CmdHelper.GetCmdDependencies(pathTable)),
                                            ReadOnlyArray <AbsolutePath> .From(CmdHelper.GetCmdDependencyScopes(pathTable)),
                                            ReadOnlyArray <StringId> .Empty,
                                            ReadOnlyArray <int> .Empty,
                                            ReadOnlyArray <ProcessSemaphoreInfo> .Empty,
                                            provenance: PipProvenance.CreateDummy(context),
                                            toolDescription: StringId.Invalid,
                                            additionalTempDirectories: ReadOnlyArray <AbsolutePath> .Empty);
                                        executionEnvironment.AddExpectedWrite(pip, destinationArtifact, executionEnvironment.GetExpectedContent(sourceArtifact));
                                        break;

                                    default:
                                        Contract.Assert(false);
                                        continue;
                                    }

                                    var pipId = pipTable.Add((uint)((range *M) + N + i + 1), pip);

                                    Func <RunnablePip, Task> taskFactoryWithCallback = async(runnablePip) =>
                                    {
                                        var task      = taskFactory(runnablePip);
                                        var pipResult = await task;
                                        callback(pipId, task);
                                    };

                                    var runnable = RunnablePip.Create(loggingContext, executionEnvironment, pipId, pipTable.GetPipType(pipId), 0, taskFactoryWithCallback, 0);
                                    runnable.Start(new OperationTracker(loggingContext), loggingContext);
                                    runnable.SetDispatcherKind(queueKind);
                                    phase2PipQueue.Enqueue(runnable);

                                    if (!pips.TryAdd(pipId, Tuple.Create(destination, sourceIndex)))
                                    {
                                        Contract.Assert(false);
                                    }
                                }

                                phase2PipQueue.SetAsFinalized();
                                phase2PipQueue.DrainQueues();
                                XAssert.AreEqual(0, pips.Count);
                                await Task.WhenAll(checkerTasks);
                            }
                        }));
                    }
                }
            }
        }
Exemplo n.º 40
0
 public SpecialEvent(PeriodType period, ReadOnlyArray <TimeValue> listOfTimeValues, uint eventPriority)
 {
     this.Period           = period;
     this.ListOfTimeValues = listOfTimeValues;
     this.EventPriority    = eventPriority;
 }
Exemplo n.º 41
0
            /// <summary>
            /// Stores built automaton in pre-allocated <see cref="Automaton{TSequence,TElement,TElementDistribution,TSequenceManipulator,TThis}"/> object.
            /// </summary>
            public DataContainer GetData(bool?isDeterminized = null)
            {
                if (this.StartStateIndex < 0 || this.StartStateIndex >= this.states.Count)
                {
                    throw new InvalidOperationException(
                              $"Built automaton must have a valid start state. " +
                              $"StartStateIndex = {this.StartStateIndex}, states.Count = {this.states.Count}");
                }

                var hasEpsilonTransitions     = false;
                var usesGroups                = false;
                var hasOnlyForwardTransitions = true;

                var resultStates              = ReadOnlyArray.CreateBuilder <StateData>(this.states.Count);
                var resultTransitions         = ReadOnlyArray.CreateBuilder <Transition>(this.transitions.Count - this.numRemovedTransitions);
                var nextResultTransitionIndex = 0;

                for (var i = 0; i < resultStates.Count; ++i)
                {
                    var firstResultTransitionIndex = nextResultTransitionIndex;
                    var transitionIndex            = this.states[i].FirstTransitionIndex;
                    while (transitionIndex != -1)
                    {
                        var node       = this.transitions[transitionIndex];
                        var transition = node.Transition;
                        Debug.Assert(
                            transition.DestinationStateIndex < resultStates.Count,
                            "Destination indexes must be in valid range");
                        resultTransitions[nextResultTransitionIndex] = transition;
                        ++nextResultTransitionIndex;
                        hasEpsilonTransitions = hasEpsilonTransitions || transition.IsEpsilon;
                        usesGroups            = usesGroups || (transition.Group != 0);

                        if (transition.DestinationStateIndex <= i)
                        {
                            hasOnlyForwardTransitions = false;
                        }

                        transitionIndex = node.Next;
                    }

                    resultStates[i] = new StateData(
                        firstResultTransitionIndex,
                        nextResultTransitionIndex - firstResultTransitionIndex,
                        this.states[i].EndWeight);
                }

                Debug.Assert(
                    nextResultTransitionIndex == resultTransitions.Count,
                    "number of copied transitions must match result array size");

                // Detect two very common automata shapes
                var isEnumerable = hasOnlyForwardTransitions ? true : (bool?)null;

                return(new DataContainer(
                           this.StartStateIndex,
                           resultStates.MoveToImmutable(),
                           resultTransitions.MoveToImmutable(),
                           !hasEpsilonTransitions,
                           usesGroups,
                           isDeterminized,
                           isZero: null,
                           isEnumerable: isEnumerable));
            }
Exemplo n.º 42
0
 public SealDirectoryMutablePipState(PipType piptype, long semiStableHash, PageableStoreId storeId, SealDirectoryKind sealDirectoryKind, ReadOnlyArray <StringId> patterns, bool isComposite, bool scrub, SealDirectoryContentFilter?contentFilter)
     : base(piptype, semiStableHash, storeId)
 {
     SealDirectoryKind = sealDirectoryKind;
     Patterns          = patterns;
     IsComposite       = isComposite;
     Scrub             = scrub;
     ContentFilter     = contentFilter;
 }
Exemplo n.º 43
0
        public void ScrubFileDirectoriesWithPipGraph()
        {
            string rootDirectory = Path.Combine(TemporaryDirectory, nameof(ScrubFileDirectoriesWithPipGraph));
            string sourceRoot    = Path.Combine(rootDirectory, "Src");
            string outputRoot    = Path.Combine(rootDirectory, "Out");
            string targetRoot    = Path.Combine(rootDirectory, "Target");

            var pathTable = new PathTable();

            using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler(
                       new List <IMount> {
                new Mount()
                {
                    Name = PathAtom.Create(pathTable.StringTable, "testRoot"),
                    Path = AbsolutePath.Create(pathTable, TemporaryDirectory),
                    IsWritable = true,
                    IsReadable = true,
                    IsScrubbable = true,
                    AllowCreateDirectory = true,
                }
            },
                       pathTable)
                   )
            {
                string inputFilePath = Path.Combine(sourceRoot, "input.txt");
                WriteFile(inputFilePath);
                string outputFilePath = Path.Combine(outputRoot, "output.txt");
                WriteFile(outputFilePath);

                string tempOutputDirectoryPath = Path.Combine(outputRoot, "TempOutDir");
                string tempOutputPath          = Path.Combine(tempOutputDirectoryPath, "tempOutputInDir.txt");
                Directory.CreateDirectory(tempOutputDirectoryPath);

                string optionalOutputDirectoryPath = Path.Combine(outputRoot, "OptionalOutDir");
                string optionalOutputPath          = Path.Combine(optionalOutputDirectoryPath, "optionalOutputInDir.txt");
                Directory.CreateDirectory(optionalOutputDirectoryPath);

                string targetFileInOutputDirectoryPath = Path.Combine(targetRoot, "targetInDir.txt");
                WriteFile(targetFileInOutputDirectoryPath);

                string outputDirectoryPath             = Path.Combine(outputRoot, "OutDir");
                string outputFileInOutputDirectoryPath = Path.Combine(outputDirectoryPath, "outputInDir.txt");
                WriteFile(outputFileInOutputDirectoryPath);

                string sharedOutputDirectoryPath             = Path.Combine(outputRoot, "SharedOutDir");
                string outputFileInOutputSharedDirectoryPath = Path.Combine(sharedOutputDirectoryPath, "outputInSharedDir.txt");
                WriteFile(outputFileInOutputSharedDirectoryPath);

                string junkOutputPath = Path.Combine(outputRoot, "junk.txt");
                WriteFile(junkOutputPath);
                string junkOutputInOutputDirectoryPath = Path.Combine(outputDirectoryPath, "junkInDir.txt");
                WriteFile(junkOutputInOutputDirectoryPath);
                string junkTempOutputPath = Path.Combine(tempOutputDirectoryPath, "junkTempOutput.txt");
                WriteFile(junkTempOutputPath);
                string junkOptionalOutputPath = Path.Combine(optionalOutputDirectoryPath, "junkOptionalOutput.txt");
                WriteFile(junkOptionalOutputPath);
                string junkDirectoryPath           = Path.Combine(outputRoot, "JunkDir");
                string junkFileInJunkDirectoryPath = Path.Combine(junkDirectoryPath, "junkInJunkDir.txt");
                WriteFile(junkFileInJunkDirectoryPath);

                // Create pip's temporary directory.
                string pipTempDir1 = Path.Combine(outputRoot, "PipTemp1");
                Directory.CreateDirectory(pipTempDir1);
                string fileInPipTempDir1 = Path.Combine(pipTempDir1, "fileInPipTemp1.txt");
                WriteFile(fileInPipTempDir1);
                string pipTempDir2 = Path.Combine(outputRoot, "PipTemp2", "Nested");
                Directory.CreateDirectory(pipTempDir2);
                string fileInPipTempDir2 = Path.Combine(pipTempDir1, "fileInPipTemp2Nested.txt");
                WriteFile(fileInPipTempDir2);

                var          pipBuilder = CreatePipBuilderWithTag(env, nameof(ScrubFileDirectoriesWithPipGraph));
                FileArtifact input      = env.Paths.CreateSourceFile(env.Paths.CreateAbsolutePath(inputFilePath));
                pipBuilder.AddInputFile(input);

                AbsolutePath output = env.Paths.CreateAbsolutePath(outputFilePath);
                pipBuilder.AddOutputFile(output);

                AbsolutePath tempOutput = env.Paths.CreateAbsolutePath(tempOutputPath);
                pipBuilder.AddOutputFile(tempOutput, FileExistence.Temporary);

                AbsolutePath optionalOutput = env.Paths.CreateAbsolutePath(optionalOutputPath);
                pipBuilder.AddOutputFile(optionalOutput, FileExistence.Optional);

                AbsolutePath outputDirectory = env.Paths.CreateAbsolutePath(outputDirectoryPath);
                pipBuilder.AddOutputDirectory(outputDirectory);

                AbsolutePath targetRootAbsolutePath = env.Paths.CreateAbsolutePath(targetRoot);
                pipBuilder.AddOutputDirectory(targetRootAbsolutePath);

                AbsolutePath sharedOutputDirectory = env.Paths.CreateAbsolutePath(sharedOutputDirectoryPath);
                pipBuilder.AddOutputDirectory(sharedOutputDirectory, SealDirectoryKind.SharedOpaque);

                pipBuilder.TempDirectory             = env.Paths.CreateAbsolutePath(pipTempDir1);
                pipBuilder.AdditionalTempDirectories = ReadOnlyArray <AbsolutePath> .FromWithoutCopy(env.Paths.CreateAbsolutePath(pipTempDir2));

                env.PipConstructionHelper.AddProcess(pipBuilder);
                PipGraph pipGraph = AssertSuccessGraphBuilding(env);
                RunScrubberWithPipGraph(env, pipGraph, pathsToScrub: new[] { outputRoot, targetRoot });

                // All non-junk files/directories should be preserved, except ... (see below)
                XAssert.IsTrue(File.Exists(inputFilePath));
                XAssert.IsTrue(File.Exists(outputFilePath));
                XAssert.IsTrue(Directory.Exists(tempOutputDirectoryPath));
                XAssert.IsTrue(Directory.Exists(optionalOutputDirectoryPath));
                XAssert.IsTrue(Directory.Exists(outputDirectoryPath));
                XAssert.IsTrue(Directory.Exists(sharedOutputDirectoryPath));

                // Shared output directory is always scrubbed, and thus its contents should be removed.
                XAssert.IsFalse(File.Exists(outputFileInOutputSharedDirectoryPath));

                // All junk files/directories should be removed, except ... (see below).
                XAssert.IsFalse(File.Exists(junkOutputPath));
                XAssert.IsFalse(File.Exists(junkTempOutputPath));
                XAssert.IsFalse(File.Exists(junkOptionalOutputPath));
                XAssert.IsFalse(Directory.Exists(junkDirectoryPath));

                // Junk output in an output directory is not removed because
                // when we run again the pip (can be from cache), the whole output directory will be removed.
                XAssert.IsTrue(File.Exists(junkOutputInOutputDirectoryPath));

                XAssert.IsFalse(Directory.Exists(pipTempDir1));
                XAssert.IsFalse(Directory.Exists(pipTempDir2));
                XAssert.IsTrue(Directory.Exists(Path.GetDirectoryName(pipTempDir2)));
            }
        }
Exemplo n.º 44
0
        /// \brief Reads and interprets data reported by the Wii Remote.
        /// \return On success, > 0, < 0 on failure, 0 if nothing has been recieved.
        ///
        /// Wii Remote reads function similarly to a Queue, in FIFO (first in, first out) order.
        /// For example, if two reports were sent since the last \c ReadWiimoteData() call,
        /// this call will only read and interpret the first of those two (and "pop" it off
        /// of the queue).  So, in order to make sure you don't fall behind the Wiimote's update
        /// frequency, you can do something like this (in a game loop for example):
        ///
        /// \code
        /// Wii Remote wiimote;
        /// int ret;
        /// do
        /// {
        ///     ret = wiimote.ReadWiimoteData();
        /// } while (ret > 0);
        /// \endcode
        public int ReadWiimoteData()
        {
            byte[] buf    = new byte[22];
            int    status = WiimoteManager.RecieveRaw(hidapi_handle, buf);

            if (status <= 0)
            {
                return(status);         // Either there is some sort of error or we haven't recieved anything
            }
            int typesize = GetInputDataTypeSize((InputDataType)buf[0]);

            byte[] data = new byte[typesize];
            for (int x = 0; x < data.Length; x++)
            {
                data[x] = buf[x + 1];
            }

            if (WiimoteManager.Debug_Messages)
            {
                Debug.Log("Recieved: [" + buf[0].ToString("X").PadLeft(2, '0') + "] " + BitConverter.ToString(data));
            }

            // Variable names used throughout the switch/case block
            byte[] buttons;
            byte[] accel;
            byte[] ext = null;
            byte[] ir;

            switch ((InputDataType)buf[0])  // buf[0] is the output ID byte
            {
            case InputDataType.STATUS_INFO: // done.
                buttons = new byte[] { data[0], data[1] };
                byte flags         = data[2];
                byte battery_level = data[5];

                Button.InterpretData(buttons);

                bool old_ext_connected = Status.ext_connected;

                byte[] total = new byte[] { flags, battery_level };
                Status.InterpretData(total);

                if (expecting_status_report)
                {
                    expecting_status_report = false;
                }
                else                                        // We haven't requested any data report type, meaning a controller has connected.
                {
                    SendDataReportMode(last_report_type);   // If we don't update the data report mode, no updates will be sent
                }

                if (Status.ext_connected != old_ext_connected && Type != WiimoteType.PROCONTROLLER)
                {
                    if (Status.ext_connected)                // The Wii Remote doesn't allow reading from the extension identifier
                    {                                        // when nothing is connected.
                        Debug.Log("An extension has been connected.");
                        if (current_ext != ExtensionController.MOTIONPLUS)
                        {
                            ActivateExtension();
                            RequestIdentifyExtension();         // Identify what extension was connected.
                        }
                        else
                        {
                            ExpectingWiiMotionPlusSwitch = false;
                        }
                    }
                    else
                    {
                        if (!ExpectingWiiMotionPlusSwitch)
                        {
                            _current_ext = ExtensionController.NONE;
                        }
                        Debug.Log("An extension has been disconnected.");
                    }
                }
                break;

            case InputDataType.READ_MEMORY_REGISTERS: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                if (CurrentReadData == null)
                {
                    Debug.LogWarning("Recived Register Read Report when none was expected.  Ignoring.");
                    return(status);
                }

                byte size  = (byte)((data[2] >> 4) + 0x01);
                byte error = (byte)(data[2] & 0x0f);
                // Error 0x07 means reading from a write-only register
                // Offset 0xa600fa is for the Wii Motion Plus.  This error code can be expected behavior in this case.
                if (error == 0x07)
                {
                    if (CurrentReadData.Offset != 0xa600fa)
                    {
                        Debug.LogError("Wiimote reports Read Register error 7: Attempting to read from a write-only register (" + CurrentReadData.Offset.ToString("x") + ").  Aborting read.");
                    }

                    CurrentReadData = null;
                    return(status);
                }
                // lowOffset is reversed because the Wii Remote reports are in Big Endian order
                ushort lowOffset = BitConverter.ToUInt16(new byte[] { data[4], data[3] }, 0);
                ushort expected  = (ushort)CurrentReadData.ExpectedOffset;
                if (expected != lowOffset)
                {
                    Debug.LogWarning("Expected Register Read Offset (" + expected + ") does not match reported offset from Wii Remote (" + lowOffset + ")");
                }
                byte[] read = new byte[size];
                for (int x = 0; x < size; x++)
                {
                    read[x] = data[x + 5];
                }

                CurrentReadData.AppendData(read);
                if (CurrentReadData.ExpectedOffset >= CurrentReadData.Offset + CurrentReadData.Size)
                {
                    CurrentReadData = null;
                }

                break;

            case InputDataType.ACKNOWLEDGE_OUTPUT_REPORT:
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);
                // TODO: doesn't do any actual error handling, or do any special code about acknowledging the output report.
                break;

            case InputDataType.REPORT_BUTTONS: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);
                break;

            case InputDataType.REPORT_BUTTONS_ACCEL: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                accel = new byte[] { data[0], data[1], data[2], data[3], data[4] };
                Accel.InterpretData(accel);
                break;

            case InputDataType.REPORT_BUTTONS_EXT8: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                ext = new byte[8];
                for (int x = 0; x < ext.Length; x++)
                {
                    ext[x] = data[x + 2];
                }

                if (_Extension != null)
                {
                    _Extension.InterpretData(ext);
                }
                break;

            case InputDataType.REPORT_BUTTONS_ACCEL_IR12: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                accel = new byte[] { data[0], data[1], data[2], data[3], data[4] };
                Accel.InterpretData(accel);

                ir = new byte[12];
                for (int x = 0; x < 12; x++)
                {
                    ir[x] = data[x + 5];
                }
                Ir.InterpretData(ir);
                break;

            case InputDataType.REPORT_BUTTONS_EXT19: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                ext = new byte[19];
                for (int x = 0; x < ext.Length; x++)
                {
                    ext[x] = data[x + 2];
                }

                if (_Extension != null)
                {
                    _Extension.InterpretData(ext);
                }
                break;

            case InputDataType.REPORT_BUTTONS_ACCEL_EXT16: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                accel = new byte[] { data[0], data[1], data[2], data[3], data[4] };
                Accel.InterpretData(accel);

                ext = new byte[16];
                for (int x = 0; x < ext.Length; x++)
                {
                    ext[x] = data[x + 5];
                }

                if (_Extension != null)
                {
                    _Extension.InterpretData(ext);
                }
                break;

            case InputDataType.REPORT_BUTTONS_IR10_EXT9: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                ir = new byte[10];
                for (int x = 0; x < 10; x++)
                {
                    ir[x] = data[x + 2];
                }
                Ir.InterpretData(ir);

                ext = new byte[9];
                for (int x = 0; x < 9; x++)
                {
                    ext[x] = data[x + 12];
                }

                if (_Extension != null)
                {
                    _Extension.InterpretData(ext);
                }
                break;

            case InputDataType.REPORT_BUTTONS_ACCEL_IR10_EXT6: // done.
                buttons = new byte[] { data[0], data[1] };
                Button.InterpretData(buttons);

                accel = new byte[] { data[0], data[1], data[2], data[3], data[4] };
                Accel.InterpretData(accel);

                ir = new byte[10];
                for (int x = 0; x < 10; x++)
                {
                    ir[x] = data[x + 5];
                }
                Ir.InterpretData(ir);

                ext = new byte[6];
                for (int x = 0; x < 6; x++)
                {
                    ext[x] = data[x + 15];
                }

                if (_Extension != null)
                {
                    _Extension.InterpretData(ext);
                }
                break;

            case InputDataType.REPORT_EXT21: // done.
                ext = new byte[21];
                for (int x = 0; x < ext.Length; x++)
                {
                    ext[x] = data[x];
                }

                if (_Extension != null)
                {
                    _Extension.InterpretData(ext);
                }
                break;

            case InputDataType.REPORT_INTERLEAVED:
                if (!ExpectingSecondInterleavedPacket)
                {
                    ExpectingSecondInterleavedPacket = true;
                    InterleavedDataBuffer            = data;
                }
                else if (WiimoteManager.Debug_Messages)
                {
                    Debug.LogWarning(
                        "Recieved two REPORT_INTERLEAVED (" + InputDataType.REPORT_INTERLEAVED.ToString("x") + ") reports in a row!  "
                        + "Expected REPORT_INTERLEAVED_ALT (" + InputDataType.REPORT_INTERLEAVED_ALT.ToString("x") + ").  Ignoring!"
                        );
                }

                break;

            case InputDataType.REPORT_INTERLEAVED_ALT:
                if (ExpectingSecondInterleavedPacket)
                {
                    ExpectingSecondInterleavedPacket = false;

                    buttons = new byte[] { data[0], data[1] };
                    Button.InterpretData(buttons);

                    byte[] ir1 = new byte[18];
                    byte[] ir2 = new byte[18];

                    for (int x = 0; x < 18; x++)
                    {
                        ir1[x] = InterleavedDataBuffer[x + 3];
                        ir2[x] = data[x + 3];
                    }

                    Ir.InterpretDataInterleaved(ir1, ir2);
                    Accel.InterpretDataInterleaved(InterleavedDataBuffer, data);
                }
                else if (WiimoteManager.Debug_Messages)
                {
                    Debug.LogWarning(
                        "Recieved two REPORT_INTERLEAVED_ALT (" + InputDataType.REPORT_INTERLEAVED_ALT.ToString("x") + ") reports in a row!  "
                        + "Expected REPORT_INTERLEAVED (" + InputDataType.REPORT_INTERLEAVED.ToString("x") + ").  Ignoring!"
                        );
                }
                break;
            }

            if (ext == null)
            {
                _RawExtension = null;
            }
            else
            {
                _RawExtension = new ReadOnlyArray <byte>(ext);
            }

            return(status);
        }
Exemplo n.º 45
0
        private bool TryConfigureProcessBuilder(
            ProcessBuilder processBuilder,
            PipConstructionHelper pipConstructionHelper,
            ProjectWithPredictions project,
            QualifierId qualifierId,
            out AbsolutePath outputResultCacheFile,
            out string failureDetail)
        {
            outputResultCacheFile = AbsolutePath.Invalid;
            if (!TrySetBuildToolExecutor(pipConstructionHelper, processBuilder, project))
            {
                failureDetail = "Failed to construct tooldefinition";
                return(false);
            }

            // Working directory - the directory where the project file lives.
            processBuilder.WorkingDirectory = DirectoryArtifact.CreateWithZeroPartialSealId(project.FullPath.GetParent(PathTable));

            // We allow undeclared inputs to be read
            processBuilder.Options |= Process.Options.AllowUndeclaredSourceReads;

            // Run in a container if specified
            if (m_resolverSettings.RunInContainer)
            {
                processBuilder.Options |= Process.Options.NeedsToRunInContainer;
                processBuilder.ContainerIsolationLevel = ContainerIsolationLevel.IsolateAllOutputs;
            }

            // By default the double write policy is to allow same content double writes.
            processBuilder.DoubleWritePolicy |= m_resolverSettings.DoubleWritePolicy ?? DoubleWritePolicy.AllowSameContentDoubleWrites;

            SetUntrackedFilesAndDirectories(processBuilder);

            // Add the log directory and its corresponding files
            var          qualifier    = m_context.QualifierTable.GetQualifier(qualifierId);
            AbsolutePath logDirectory = GetLogDirectory(project, qualifier);

            processBuilder.AddOutputFile(logDirectory.Combine(PathTable, "msbuild.log"), FileExistence.Optional);
            processBuilder.AddOutputFile(logDirectory.Combine(PathTable, "msbuild.wrn"), FileExistence.Optional);
            processBuilder.AddOutputFile(logDirectory.Combine(PathTable, "msbuild.err"), FileExistence.Optional);
            processBuilder.AddOutputFile(logDirectory.Combine(PathTable, "msbuild.prf"), FileExistence.Optional);

            if (m_resolverSettings.EnableBinLogTracing == true)
            {
                processBuilder.AddOutputFile(logDirectory.Combine(PathTable, "msbuild.binlog"), FileExistence.Optional);
            }

            // Unless the legacy non-isolated mode is explicitly specified, the project builds in isolation, and therefore
            // it produces an output cache file. This file is placed on the (unique) object directory for this project
            if (m_resolverSettings.UseLegacyProjectIsolation != true)
            {
                var objectDirectory = pipConstructionHelper.GetUniqueObjectDirectory(project.FullPath.GetName(PathTable));
                outputResultCacheFile = objectDirectory.Path.Combine(PathTable, PathAtom.Create(PathTable.StringTable, OutputCacheFileName));
                processBuilder.AddOutputFile(outputResultCacheFile, FileExistence.Required);
            }

            // Path to the project
            processBuilder.ArgumentsBuilder.Add(PipDataAtom.FromAbsolutePath(project.FullPath));
            // Response file with the rest of the arguments
            var rspFileSpec = ResponseFileSpecification.Builder()
                              .AllowForRemainingArguments(processBuilder.ArgumentsBuilder.CreateCursor())
                              .ForceCreation(true)
                              .Prefix("@")
                              .Build();

            processBuilder.SetResponseFileSpecification(rspFileSpec);

            if (!TryAddMsBuildArguments(project, processBuilder.ArgumentsBuilder, logDirectory, outputResultCacheFile, out failureDetail))
            {
                return(false);
            }

            // Q_SESSION_GUID is used to provide a unique build GUID to build tools and scripts.
            // It'll cause full cache misses if we try to hash it as an input, however, so exclude.
            processBuilder.SetPassthroughEnvironmentVariable(StringId.Create(m_context.StringTable, BuildEnvironmentConstants.QSessionGuidEnvVar));

            // GlobalUnsafePassthroughEnvironmentVariables
            processBuilder.SetGlobalPassthroughEnvironmentVariable(m_frontEndHost.Configuration.FrontEnd.GlobalUnsafePassthroughEnvironmentVariables, m_context.StringTable);

            // mspdbsrv: _MSPDBSRV_ENDPOINT_ sets up one mspdbsrv.exe instance per build target execution.
            // However this process will live beyond the build.cmd or msbuild.exe call.
            // Allow the pip job object to clean the process without complaint.
            //
            // vctip.exe: On any compile error this telemetry upload exe will be run as a detached process.
            // Just let it be killed.
            // TODO: Can we stop it running? https://stackoverflow.microsoft.com/questions/74425/how-to-disable-vctip-exe-in-vc14
            //
            // conhost.exe: This process needs a little bit more time to finish after the main process, but killing it right away
            // is inconsequential.
            //
            // All child processes: Don't wait to kill the processes.
            // CODESYNC: CloudBuild repo TrackerExecutor.cs "info.NestedProcessTerminationTimeout = TimeSpan.Zero"
            processBuilder.AllowedSurvivingChildProcessNames = ReadOnlyArray <PathAtom> .FromWithoutCopy(
                PathAtom.Create(m_context.StringTable, "mspdbsrv.exe"),
                PathAtom.Create(m_context.StringTable, "vctip.exe"),
                PathAtom.Create(m_context.StringTable, "conhost.exe"),
                PathAtom.Create(m_context.StringTable, "VBCSCompiler.exe"));

            // There are some cases (e.g. a 64-bit MSBuild launched as a child process from a 32-bit MSBuild instance) where
            // processes need a little bit more time to finish. Increasing the timeout does not affect job objects where no child
            // processes survive, or job object where the only surviving processes are the ones explicitly allowed to survive (which
            // are killed immediately). So overall, this non-zero timeout will only make some pips that would have failed to take a little
            // bit longer (and hopefully succeed)
            processBuilder.NestedProcessTerminationTimeout = TimeSpan.FromMilliseconds(500);

            SetProcessEnvironmentVariables(CreateEnvironment(logDirectory, project), processBuilder);

            failureDetail = string.Empty;
            return(true);
        }
Exemplo n.º 46
0
 /// <summary>
 /// Writes a ReadOnlyArray
 /// </summary>
 public void Write <T>(ReadOnlyArray <T> value, Action <BuildXLWriter, T> writer)
 {
     Contract.Requires(value.IsValid);
     WriteReadOnlyListCore(value, writer);
 }
Exemplo n.º 47
0
 public void SetReferenceSearchPaths(IEnumerable <string> paths)
 {
     SetReferenceSearchPaths(ReadOnlyArray <string> .CreateFrom(paths));
 }
Exemplo n.º 48
0
 public void ImportNamespace(string @namespace)
 {
     CommonScriptEngine.ValidateNamespace(@namespace);
     pendingNamespaces = pendingNamespaces.Append(@namespace);
 }
Exemplo n.º 49
0
        private bool TryScheduleIpcPip(Context context, ObjectLiteral obj, bool allowUndefinedTargetService, bool isServiceFinalization, out FileArtifact outputFile, out PipId pipId)
        {
            // IpcClientInfo
            IIpcMoniker moniker          = Converter.ExtractRef <IIpcMoniker>(obj, m_ipcSendMoniker, allowUndefined: false);
            int?        numRetries       = Converter.ExtractNumber(obj, m_ipcSendMaxConnectRetries, allowUndefined: true);
            int?        retryDelayMillis = Converter.ExtractNumber(obj, m_ipcSendConnectRetryDelayMillis, allowUndefined: true);
            var         clientConfig     = new ClientConfig(numRetries, retryDelayMillis);
            var         ipcClientInfo    = new IpcClientInfo(moniker.ToStringId(context.StringTable), clientConfig);

            // target service pip
            PipId?servicePipId = Converter.ExtractValue <PipId>(obj, m_ipcSendTargetServicePip, allowUndefined: allowUndefinedTargetService);

            // arguments
            PipData arguments;
            ReadOnlyArray <FileArtifact>      fileDependencies;
            ReadOnlyArray <DirectoryArtifact> directoryDependencies;

            using (var ipcProcessBuilder = ProcessBuilder.Create(context.PathTable, context.FrontEndContext.GetPipDataBuilder()))
            {
                // process arguments
                ArrayLiteral argumentsArrayLiteral = Converter.ExtractArrayLiteral(obj, m_ipcSendMessageBody);
                TransformerExecuteArgumentsProcessor.ProcessArguments(context, ipcProcessBuilder, argumentsArrayLiteral);

                // input file dependencies
                var dependenciesArray = Converter.ExtractArrayLiteral(obj, m_ipcSendDependencies, allowUndefined: true);
                if (dependenciesArray != null)
                {
                    for (int i = 0; i < dependenciesArray.Length; i++)
                    {
                        ProcessImplicitDependency(ipcProcessBuilder, dependenciesArray[i], convContext: new ConversionContext(pos: i, objectCtx: dependenciesArray));
                    }
                }

                arguments             = ipcProcessBuilder.ArgumentsBuilder.ToPipData(" ", PipDataFragmentEscaping.CRuntimeArgumentRules);
                fileDependencies      = ipcProcessBuilder.GetInputFilesSoFar();
                directoryDependencies = ipcProcessBuilder.GetInputDirectoriesSoFar();
            }

            // output
            AbsolutePath output = Converter.ExtractPath(obj, m_ipcSendOutputFile, allowUndefined: true);

            if (!output.IsValid)
            {
                output = context.GetPipConstructionHelper().GetUniqueObjectDirectory(m_ipcObjectFolderName).Path.Combine(context.PathTable, m_ipcOutputFileName);
            }

            // tags
            string[] tags      = null;
            var      tagsArray = Converter.ExtractArrayLiteral(obj, m_executeTags, allowUndefined: true);

            if (tagsArray != null && tagsArray.Count > 0)
            {
                tags = new string[tagsArray.Count];
                for (int i = 0; i < tagsArray.Count; i++)
                {
                    tags[i] = Converter.ExpectString(tagsArray[i], context: new ConversionContext(pos: i, objectCtx: tagsArray));
                }
            }

            // skip materialization for files
            FileOrDirectoryArtifact[] skipMaterializationArtifacts = CollectionUtilities.EmptyArray <FileOrDirectoryArtifact>();
            ArrayLiteral skipMaterializationLiteral = Converter.ExtractArrayLiteral(obj, m_ipcSendLazilyMaterializedDependencies, allowUndefined: true);

            if (skipMaterializationLiteral != null)
            {
                skipMaterializationArtifacts = new FileOrDirectoryArtifact[skipMaterializationLiteral.Length];
                for (int i = 0; i < skipMaterializationLiteral.Length; i++)
                {
                    Converter.ExpectFileOrStaticDirectory(
                        skipMaterializationLiteral[i],
                        out var fileArtifact,
                        out var staticDirectory,
                        context: new ConversionContext(pos: i, objectCtx: skipMaterializationLiteral));

                    Contract.Assert(fileArtifact.IsValid ^ staticDirectory != null);

                    skipMaterializationArtifacts[i] = fileArtifact.IsValid
                        ? FileOrDirectoryArtifact.Create(fileArtifact)
                        : FileOrDirectoryArtifact.Create(staticDirectory.Root);
                }
            }

            // must run on master
            var mustRunOnMaster = Converter.ExtractOptionalBoolean(obj, m_ipcSendMustRunOnMaster) == true;

            outputFile = FileArtifact.CreateOutputFile(output);

            // create IPC pip and add it to the graph
            bool result = context.GetPipConstructionHelper().TryAddIpc(
                ipcClientInfo,
                arguments,
                outputFile,
                servicePipDependencies: servicePipId != null ? ReadOnlyArray <PipId> .From(new[] { servicePipId.Value }) : ReadOnlyArray <PipId> .Empty,
                fileDependencies: fileDependencies,
                directoryDependencies: directoryDependencies,
                skipMaterializationFor: ReadOnlyArray <FileOrDirectoryArtifact> .FromWithoutCopy(skipMaterializationArtifacts),
                isServiceFinalization: isServiceFinalization,
                mustRunOnMaster: mustRunOnMaster,
                tags: tags,
                out var ipcPip);

            pipId = ipcPip.PipId;

            return(result);
        }
Exemplo n.º 50
0
 public WeightedStateSet(int stateIndex)
 {
     this.weightedStates   = null;
     this.singleStateIndex = stateIndex;
 }
Exemplo n.º 51
0
 internal static ServiceInfo ServiceClient(IEnumerable <PipId> servicePipDependencies)
 {
     return(new ServiceInfo(ServicePipKind.ServiceClient, servicePipDependencies: ReadOnlyArray <PipId> .From(servicePipDependencies)));
 }
Exemplo n.º 52
0
 /// <summary>
 /// Clone and override select properties.
 /// </summary>
 public Process Override(
     FileArtifact?executable       = null,
     AbsolutePath?workingDirectory = null,
     PipData?arguments             = null,
     FileArtifact?responseFile     = null,
     PipData?responseFileData      = null,
     ReadOnlyArray <EnvironmentVariable>?environmentVariables = null,
     StandardInput?standardInput    = null,
     FileArtifact?standardOutput    = null,
     FileArtifact?standardError     = null,
     AbsolutePath?standardDirectory = null,
     TimeSpan?warningTimeout        = null,
     TimeSpan?timeout = null,
     ReadOnlyArray <FileArtifact>?dependencies = null,
     ReadOnlyArray <FileArtifactWithAttributes>?fileOutputs  = null,
     ReadOnlyArray <DirectoryArtifact>?directoryDependencies = null,
     ReadOnlyArray <DirectoryArtifact>?directoryOutputs      = null,
     ReadOnlyArray <PipId>?orderDependencies      = null,
     ReadOnlyArray <AbsolutePath>?untrackedPaths  = null,
     ReadOnlyArray <AbsolutePath>?untrackedScopes = null,
     ReadOnlyArray <StringId>?tags                   = null,
     ReadOnlyArray <int>?successExitCodes            = null,
     ReadOnlyArray <ProcessSemaphoreInfo>?semaphores = null,
     PipProvenance provenance = null,
     StringId?toolDescription = null,
     ReadOnlyArray <AbsolutePath>?additionalTempDirectories = null,
     RegexDescriptor?warningRegex         = null,
     RegexDescriptor?errorRegex           = null,
     AbsolutePath?uniqueOutputDirectory   = null,
     AbsolutePath?redirectedDirectoryRoot = null,
     AbsolutePath?tempDirectory           = null,
     Options?options                    = null,
     bool?testRetries                   = null,
     ServiceInfo serviceInfo            = null,
     ReadOnlyArray <int>?retryExitCodes = null,
     ReadOnlyArray <PathAtom>?allowedSurvivingChildProcessNames = null,
     TimeSpan?nestedProcessTerminationTimeout = null,
     AbsentPathProbeInUndeclaredOpaquesMode absentPathProbeMode = AbsentPathProbeInUndeclaredOpaquesMode.Unsafe,
     DoubleWritePolicy doubleWritePolicy             = DoubleWritePolicy.DoubleWritesAreErrors,
     ContainerIsolationLevel containerIsolationLevel = ContainerIsolationLevel.None)
 {
     return(new Process(
                executable ?? Executable,
                workingDirectory ?? WorkingDirectory,
                arguments ?? Arguments,
                responseFile ?? ResponseFile,
                responseFileData ?? ResponseFileData,
                environmentVariables ?? EnvironmentVariables,
                standardInput ?? StandardInput,
                standardOutput ?? StandardOutput,
                standardError ?? StandardError,
                standardDirectory ?? StandardDirectory,
                warningTimeout ?? WarningTimeout,
                timeout ?? Timeout,
                dependencies ?? Dependencies,
                fileOutputs ?? FileOutputs,
                directoryDependencies ?? DirectoryDependencies,
                directoryOutputs ?? DirectoryOutputs,
                orderDependencies ?? OrderDependencies,
                untrackedPaths ?? UntrackedPaths,
                untrackedScopes ?? UntrackedScopes,
                tags ?? Tags,
                successExitCodes ?? SuccessExitCodes,
                semaphores ?? Semaphores,
                provenance ?? Provenance,
                toolDescription ?? ToolDescription,
                additionalTempDirectories ?? AdditionalTempDirectories,
                warningRegex ?? WarningRegex,
                errorRegex ?? ErrorRegex,
                uniqueOutputDirectory ?? UniqueOutputDirectory,
                redirectedDirectoryRoot ?? UniqueRedirectedDirectoryRoot,
                tempDirectory ?? TempDirectory,
                options ?? ProcessOptions,
                testRetries ?? TestRetries,
                serviceInfo ?? ServiceInfo,
                retryExitCodes ?? RetryExitCodes,
                allowedSurvivingChildProcessNames,
                nestedProcessTerminationTimeout,
                absentPathProbeMode,
                doubleWritePolicy,
                containerIsolationLevel));
 }
Exemplo n.º 53
0
 private static ReadOnlyArray <T> ToReadOnlyArray <T>(IEnumerable <T> e)
 {
     return(e == null
         ? ReadOnlyArray <T> .Empty
         : ReadOnlyArray <T> .From(e));
 }
Exemplo n.º 54
0
        /// <summary>
        /// Initialize the parameter list view based on the given registered type that has parameters to edit. This can be
        /// things such as interactions, processors, or composites.
        /// </summary>
        /// <param name="registeredType">Type of object that the parameters will be passed to at runtime.
        /// We need this to be able to determine the possible set of parameters and their possible values. This
        /// can be a class implementing <see cref="IInputInteraction"/>, for example.</param>
        /// <param name="existingParameters">List of existing parameters. Can be empty.</param>
        public void Initialize(Type registeredType, ReadOnlyArray <InputControlLayout.ParameterValue> existingParameters)
        {
            if (registeredType == null)
            {
                // No registered type. This usually happens when data references a registration that has
                // been removed in the meantime (e.g. an interaction that is no longer supported). We want
                // to accept this case and simply pretend that the given type has no parameters.

                Clear();
                return;
            }

            // Try to instantiate object so that we can determine defaults.
            object instance = null;

            try
            {
                instance = Activator.CreateInstance(registeredType);
            }
            catch (Exception)
            {
                // Swallow. If we can't create an instance, we simply assume no defaults.
            }

            var parameters = new List <EditableParameterValue>();

            ////REVIEW: support properties here?
            // Go through public instance fields and add every parameter found on the registered
            // type.
            var fields = registeredType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            foreach (var field in fields)
            {
                // Skip all fields that have an [InputControl] attribute. This is relevant
                // only for composites, but we just always do it here.
                if (field.GetCustomAttribute <InputControlAttribute>(false) != null)
                {
                    continue;
                }

                // Determine parameter name from field.
                var parameter = new EditableParameterValue {
                    field = field
                };
                var name = field.Name;
                parameter.value.name = name;

                // Determine parameter type from field.
                var fieldType = field.FieldType;
                if (fieldType == typeof(bool))
                {
                    parameter.value.type = InputControlLayout.ParameterType.Boolean;

                    // Determine default.
                    if (instance != null)
                    {
                        parameter.defaultValue = new InputControlLayout.ParameterValue(name, (bool)field.GetValue(instance));
                    }
                }
                else if (fieldType == typeof(int))
                {
                    parameter.value.type = InputControlLayout.ParameterType.Integer;

                    // Determine default.
                    if (instance != null)
                    {
                        parameter.defaultValue = new InputControlLayout.ParameterValue(name, (int)field.GetValue(instance));
                    }
                }
                else if (fieldType == typeof(float))
                {
                    parameter.value.type = InputControlLayout.ParameterType.Float;

                    // Determine default.
                    if (instance != null)
                    {
                        parameter.defaultValue = new InputControlLayout.ParameterValue(name, (float)field.GetValue(instance));
                    }
                }
                else if (fieldType.IsEnum)
                {
                    parameter.value.type = InputControlLayout.ParameterType.Integer;
                    parameter.enumNames  = Enum.GetNames(fieldType).Select(x => new GUIContent(x)).ToArray();

                    ////REVIEW: this probably falls apart if multiple members have the same value
                    var list = new List <int>();
                    foreach (var value in Enum.GetValues(fieldType))
                    {
                        list.Add((int)value);
                    }
                    parameter.enumValues = list.ToArray();

                    // Determine default.
                    if (instance != null)
                    {
                        var defaultValue    = field.GetValue(instance);
                        var defaultValueInt = Convert.ToInt32(defaultValue);
                        parameter.defaultValue = new InputControlLayout.ParameterValue(name, defaultValueInt);
                    }
                }

                // If the parameter already exists in the given list, maintain its value.
                var existingParameterIndex = existingParameters.IndexOf(x => x.name == field.Name);
                if (existingParameterIndex >= 0)
                {
                    // Make sure we're preserving the right type.
                    parameter.value = existingParameters[existingParameterIndex].ConvertTo(parameter.value.type);
                }
                else
                {
                    // Not assigned. Set to default.
                    if (parameter.defaultValue != null)
                    {
                        parameter.value = parameter.defaultValue.Value;
                    }
                }

                // Add.
                parameters.Add(parameter);
            }

            m_Parameters = parameters.ToArray();

            // See if we have a dedicated parameter editor.
            var parameterEditorType = InputParameterEditor.LookupEditorForType(registeredType);

            if (parameterEditorType != null)
            {
                // Create an editor instance and hand it the instance we created. Unlike our default
                // editing logic, on this path we will be operating on an object instance that contains
                // the parameter values. So on this path, we actually need to update the object to reflect
                // the current parameter values.

                foreach (var parameter in m_Parameters)
                {
                    if (parameter.isEnum)
                    {
                        var enumValue = Enum.ToObject(parameter.field.FieldType, parameter.value.GetIntValue());
                        parameter.field.SetValue(instance, enumValue);
                    }
                    else
                    {
                        switch (parameter.value.type)
                        {
                        case InputControlLayout.ParameterType.Float:
                            parameter.field.SetValue(instance, parameter.value.GetFloatValue());
                            break;

                        case InputControlLayout.ParameterType.Boolean:
                            parameter.field.SetValue(instance, parameter.value.GetBoolValue());
                            break;

                        case InputControlLayout.ParameterType.Integer:
                            parameter.field.SetValue(instance, parameter.value.GetIntValue());
                            break;
                        }
                    }
                }

                m_ParameterEditor = (InputParameterEditor)Activator.CreateInstance(parameterEditorType);
                m_ParameterEditor.SetTarget(instance);
            }
            else
            {
                m_ParameterEditor = null;

                // Create parameter labels.
                m_ParameterLabels = new GUIContent[m_Parameters.Length];
                for (var i = 0; i < m_Parameters.Length; ++i)
                {
                    // Look up tooltip from field.
                    var tooltip          = string.Empty;
                    var field            = m_Parameters[i].field;
                    var tooltipAttribute = field.GetCustomAttribute <TooltipAttribute>();
                    if (tooltipAttribute != null)
                    {
                        tooltip = tooltipAttribute.tooltip;
                    }

                    // Create label.
                    var niceName = ObjectNames.NicifyVariableName(m_Parameters[i].value.name);
                    m_ParameterLabels[i] = new GUIContent(niceName, tooltip);
                }
            }
        }
Exemplo n.º 55
0
        private static Process CreateConsoleProcessInContainer(
            BuildXLContext context,
            TempFileStorage tempFiles,
            PathTable pt,
            string arguments,
            ReadOnlyArray <FileArtifactWithAttributes> outputFiles,
            ReadOnlyArray <DirectoryArtifact> directoryOutputs,
            ContainerIsolationLevel containerIsolationLevel = ContainerIsolationLevel.IsolateAllOutputs)
        {
            var executableFileArtifact = FileArtifact.CreateSourceFile(AbsolutePath.Create(context.PathTable, CmdHelper.CmdX64));

            var argumentBuilder = new PipDataBuilder(context.PathTable.StringTable);

            argumentBuilder.Add("/d");
            argumentBuilder.Add("/c");
            using (argumentBuilder.StartFragment(PipDataFragmentEscaping.CRuntimeArgumentRules, " "))
            {
                foreach (var arg in arguments.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries))
                {
                    argumentBuilder.Add(arg);
                }
            }

            string workingDirectory             = tempFiles.GetUniqueDirectory();
            var    workingDirectoryAbsolutePath = AbsolutePath.Create(context.PathTable, workingDirectory);

            string uniqueOutputDirectory     = tempFiles.GetUniqueDirectory();
            var    uniqueOutputDirectoryPath = AbsolutePath.Create(context.PathTable, uniqueOutputDirectory);

            string uniqueRedirectedOutputDirectory     = tempFiles.GetUniqueDirectory("redirected");
            var    uniqueRedirectedOutputDirectoryPath = AbsolutePath.Create(context.PathTable, uniqueRedirectedOutputDirectory);

            var pip = new Process(
                executableFileArtifact,
                workingDirectoryAbsolutePath,
                argumentBuilder.ToPipData(" ", PipDataFragmentEscaping.NoEscaping),
                FileArtifact.Invalid,
                PipData.Invalid,
                ReadOnlyArray <EnvironmentVariable> .FromWithoutCopy(),
                FileArtifact.Invalid,
                FileArtifact.Invalid,
                FileArtifact.Invalid,
                tempFiles.GetUniqueDirectory(pt),
                null,
                null,
                dependencies: ReadOnlyArray <FileArtifact> .FromWithoutCopy(new[] { executableFileArtifact }),
                outputs: outputFiles,
                directoryDependencies: ReadOnlyArray <DirectoryArtifact> .Empty,
                directoryOutputs: directoryOutputs,
                orderDependencies: ReadOnlyArray <PipId> .Empty,
                untrackedPaths: ReadOnlyArray <AbsolutePath> .Empty,
                untrackedScopes: ReadOnlyArray <AbsolutePath> .Empty,
                tags: ReadOnlyArray <StringId> .Empty,
                successExitCodes: ReadOnlyArray <int> .Empty,
                semaphores: ReadOnlyArray <ProcessSemaphoreInfo> .Empty,
                provenance: PipProvenance.CreateDummy(context),
                toolDescription: StringId.Invalid,
                additionalTempDirectories: ReadOnlyArray <AbsolutePath> .Empty,
                options: Process.Options.NeedsToRunInContainer,
                uniqueOutputDirectory: uniqueOutputDirectoryPath,
                uniqueRedirectedDirectoryRoot: uniqueRedirectedOutputDirectoryPath,
                containerIsolationLevel: containerIsolationLevel);

            return(pip);
        }
Exemplo n.º 56
0
        public static (IIpcMoniker ipcMoniker, PipId servicePipId) CreateService(TestPipGraphFragment fragment, ServiceRelatedPips pips = null)
        {
            var ipcMoniker       = fragment.GetIpcMoniker();
            var apiServerMoniker = fragment.GetApiServerMoniker();

            var shutdownBuilder = fragment.GetProcessBuilder();

            new ArgumentsBuilder(shutdownBuilder)
            .AddIpcMonikerOption("--ipcMoniker ", ipcMoniker)
            .AddIpcMonikerOption("--serverMoniker ", apiServerMoniker)
            .AddOutputFileOption("--output ", fragment.CreateOutputFile("shutdown.txt"))
            .Finish();
            shutdownBuilder.ServiceKind = ServicePipKind.ServiceShutdown;
            (Process shutdownProcess, ProcessOutputs _) = fragment.ScheduleProcessBuilder(shutdownBuilder);

            var finalProcessBuilder = fragment.GetIpcProcessBuilder();

            new ArgumentsBuilder(finalProcessBuilder)
            .AddStringOption("--command ", "final")
            .AddIpcMonikerOption("--ipcMoniker ", ipcMoniker)
            .Finish();
            var finalOutputFile = fragment.CreateOutputFile("final.txt");
            var finalizationPip = fragment.ScheduleIpcPip(
                ipcMoniker,
                null,
                finalProcessBuilder,
                finalOutputFile,
                true);

            XAssert.IsTrue(finalizationPip.PipId.IsValid);

            var serviceProcessBuilder = fragment.GetProcessBuilder();

            new ArgumentsBuilder(serviceProcessBuilder)
            .AddIpcMonikerOption("--ipcMoniker ", ipcMoniker)
            .AddIpcMonikerOption("--serverMoniker ", apiServerMoniker)
            .AddOutputFileOption("--output ", fragment.CreateOutputFile("service.txt"))
            .Finish();
            serviceProcessBuilder.ServiceKind          = ServicePipKind.Service;
            serviceProcessBuilder.ShutDownProcessPipId = shutdownProcess.PipId;
            serviceProcessBuilder.FinalizationPipIds   = ReadOnlyArray <PipId> .FromWithoutCopy(new[] { finalizationPip.PipId });

            (Process serviceProcess, ProcessOutputs _) = fragment.ScheduleProcessBuilder(serviceProcessBuilder);

            var createProcessBuilder = fragment.GetIpcProcessBuilder();

            new ArgumentsBuilder(createProcessBuilder)
            .AddStringOption("--command ", "create")
            .AddIpcMonikerOption("--ipcMoniker ", ipcMoniker)
            .Finish();
            var createOutputFile = fragment.CreateOutputFile("create.txt");
            var createPip        = fragment.ScheduleIpcPip(
                ipcMoniker,
                serviceProcess.PipId,
                createProcessBuilder,
                createOutputFile,
                false);

            XAssert.IsTrue(createPip.PipId.IsValid);

            if (pips != null)
            {
                pips.ShutDown     = shutdownProcess;
                pips.Final        = finalizationPip;
                pips.ServiceStart = serviceProcess;
                pips.Create       = createPip;
            }

            return(ipcMoniker, serviceProcess.PipId);
        }
Exemplo n.º 57
0
        /// <summary>
        /// Class constructor
        /// </summary>
        public Process(
            FileArtifact executable,
            AbsolutePath workingDirectory,
            PipData arguments,
            FileArtifact responseFile,
            PipData responseFileData,
            ReadOnlyArray <EnvironmentVariable> environmentVariables,
            StandardInput standardInput,
            FileArtifact standardOutput,
            FileArtifact standardError,
            AbsolutePath standardDirectory,
            TimeSpan?warningTimeout,
            TimeSpan?timeout,
            ReadOnlyArray <FileArtifact> dependencies,
            ReadOnlyArray <FileArtifactWithAttributes> outputs,
            ReadOnlyArray <DirectoryArtifact> directoryDependencies,
            ReadOnlyArray <DirectoryArtifact> directoryOutputs,
            ReadOnlyArray <PipId> orderDependencies,
            ReadOnlyArray <AbsolutePath> untrackedPaths,
            ReadOnlyArray <AbsolutePath> untrackedScopes,
            ReadOnlyArray <StringId> tags,
            ReadOnlyArray <int> successExitCodes,
            ReadOnlyArray <ProcessSemaphoreInfo> semaphores,
            PipProvenance provenance,
            StringId toolDescription,
            ReadOnlyArray <AbsolutePath> additionalTempDirectories,
            RegexDescriptor warningRegex               = default,
            RegexDescriptor errorRegex                 = default,
            AbsolutePath uniqueOutputDirectory         = default,
            AbsolutePath uniqueRedirectedDirectoryRoot = default,
            AbsolutePath tempDirectory                 = default,
            Options options                    = default,
            bool testRetries                   = false,
            ServiceInfo serviceInfo            = null,
            ReadOnlyArray <int>?retryExitCodes = null,
            ReadOnlyArray <PathAtom>?allowedSurvivingChildProcessNames = null,
            TimeSpan?nestedProcessTerminationTimeout = null,
            AbsentPathProbeInUndeclaredOpaquesMode absentPathProbeMode = AbsentPathProbeInUndeclaredOpaquesMode.Unsafe,
            DoubleWritePolicy doubleWritePolicy             = DoubleWritePolicy.DoubleWritesAreErrors,
            ContainerIsolationLevel containerIsolationLevel = ContainerIsolationLevel.None)
        {
            Contract.Requires(executable.IsValid);
            Contract.Requires(workingDirectory.IsValid);
            Contract.Requires(arguments.IsValid);
            Contract.RequiresForAll(environmentVariables, environmentVariable => environmentVariable.Name.IsValid);
            Contract.RequiresForAll(environmentVariables, environmentVariable => environmentVariable.Value.IsValid ^ environmentVariable.IsPassThrough);
            Contract.Requires(dependencies.IsValid);
            Contract.RequiresForAll(dependencies, dependency => dependency.IsValid);
            Contract.Requires(directoryDependencies.IsValid);
            Contract.RequiresForAll(directoryDependencies, directoryDependency => directoryDependency.IsValid);
            Contract.Requires(outputs.IsValid);
            Contract.RequiresForAll(outputs, output => output.IsValid);
            Contract.Requires(directoryOutputs.IsValid);
            Contract.RequiresForAll(outputs, output => !output.IsSourceFile);
            Contract.RequiresForAll(directoryOutputs, directoryOutput => directoryOutput.IsValid);
            Contract.Requires(orderDependencies.IsValid);
            Contract.RequiresForAll(orderDependencies, dependency => dependency != PipId.Invalid);
            Contract.Requires(untrackedPaths.IsValid);
            Contract.RequiresForAll(untrackedPaths, path => path.IsValid);
            Contract.Requires(untrackedScopes.IsValid);
            Contract.RequiresForAll(untrackedScopes, scope => scope.IsValid);
            Contract.Requires(!timeout.HasValue || timeout.Value <= MaxTimeout);
            Contract.Requires(standardDirectory.IsValid || (standardOutput.IsValid && standardError.IsValid));
            Contract.Requires(provenance != null);
            Contract.Requires(additionalTempDirectories.IsValid);
            Contract.RequiresForAll(additionalTempDirectories, path => path.IsValid);
            Contract.Requires(tags.IsValid);
            // If the process needs to run in a container, the redirected directory has to be set
            Contract.Requires((options & Options.NeedsToRunInContainer) == Options.None || uniqueRedirectedDirectoryRoot.IsValid);

#if DEBUG   // a little too expensive for release builds
            Contract.Requires(Contract.Exists(dependencies, d => d == executable), "The executable must be declared as a dependency");
            Contract.Requires(
                !standardInput.IsFile || Contract.Exists(dependencies, d => d == standardInput.File),
                "If provided, the standard-input artifact must be declared as a dependency");
            Contract.Requires(
                !standardOutput.IsValid || Contract.Exists(outputs, o => o.ToFileArtifact() == standardOutput),
                "If provided, the standard-error artifact must be declared as an expected output");
            Contract.Requires(
                !standardError.IsValid || Contract.Exists(outputs, o => o.ToFileArtifact() == standardError),
                "If provided, the standard-error artifact must be declared as an expected output");
            Contract.Requires(
                !responseFile.IsValid ^ responseFileData.IsValid,
                "If provided, the response-file artifact must have a corresponding ResponseFileData");

            Contract.Requires(outputs.Length == outputs.Distinct().Count());
            Contract.Requires(directoryOutputs.Length == directoryOutputs.Distinct().Count());
            Contract.Requires(dependencies.Length == dependencies.Distinct().Count());
            Contract.Requires(directoryDependencies.Length == directoryDependencies.Distinct().Count());
            Contract.Requires(untrackedPaths.Length == untrackedPaths.Distinct().Count());
            Contract.Requires(untrackedScopes.Length == untrackedScopes.Distinct().Count());
            Contract.Requires(additionalTempDirectories.Length == additionalTempDirectories.Distinct().Count());
            Contract.RequiresForAll(semaphores, s => s.IsValid);
            Contract.Requires(semaphores.Length == semaphores.Distinct().Count());
#endif

            Provenance        = provenance;
            Tags              = tags;
            Executable        = executable;
            ToolDescription   = toolDescription;
            WorkingDirectory  = workingDirectory;
            Arguments         = arguments;
            ResponseFile      = responseFile;
            ResponseFileData  = responseFileData;
            StandardOutput    = standardOutput;
            StandardError     = standardError;
            StandardInput     = standardInput;
            StandardDirectory = standardDirectory;
            WarningTimeout    = warningTimeout;
            Timeout           = timeout;

            // We allow any IEnumerable for these fields, but perform a copy up-front.
            // See the remarks of RemoveDuplicateFileArtifacts for why it is used on the input / output lists.
            Dependencies                                  = dependencies;
            DirectoryDependencies                         = directoryDependencies;
            FileOutputs                                   = outputs;
            DirectoryOutputs                              = directoryOutputs;
            OrderDependencies                             = orderDependencies;
            UntrackedPaths                                = untrackedPaths;
            UntrackedScopes                               = untrackedScopes;
            EnvironmentVariables                          = environmentVariables;
            SuccessExitCodes                              = successExitCodes;
            RetryExitCodes                                = retryExitCodes ?? ReadOnlyArray <int> .Empty;
            WarningRegex                                  = warningRegex;
            ErrorRegex                                    = errorRegex;
            UniqueOutputDirectory                         = uniqueOutputDirectory;
            UniqueRedirectedDirectoryRoot                 = uniqueRedirectedDirectoryRoot;
            Semaphores                                    = semaphores;
            TempDirectory                                 = tempDirectory;
            TestRetries                                   = testRetries;
            ServiceInfo                                   = serviceInfo;
            ProcessOptions                                = options;
            AdditionalTempDirectories                     = additionalTempDirectories;
            AllowedSurvivingChildProcessNames             = allowedSurvivingChildProcessNames ?? ReadOnlyArray <PathAtom> .Empty;
            NestedProcessTerminationTimeout               = nestedProcessTerminationTimeout;
            ProcessAbsentPathProbeInUndeclaredOpaquesMode = absentPathProbeMode;
            DoubleWritePolicy                             = doubleWritePolicy;
            ContainerIsolationLevel                       = containerIsolationLevel;
        }
Exemplo n.º 58
0
 public GetAlarmSummaryAck(ReadOnlyArray <Element> item)
 {
     this.Item = item;
 }
Exemplo n.º 59
0
        /// <inheritdoc />
        public async Task <Possible <ContentAvailabilityBatchResult, Failure> > TryLoadAvailableContentAsync(IReadOnlyList <ContentHash> hashes)
        {
            // TODO: These conversions are silly.
            CasHash[] casHashes = new CasHash[hashes.Count];
            for (int i = 0; i < casHashes.Length; i++)
            {
                casHashes[i] = new CasHash(new global::BuildXL.Cache.Interfaces.Hash(hashes[i]));
            }

            Possible <ICacheSession, Failure> maybeOpen = m_cache.Get(nameof(TryLoadAvailableContentAsync));

            if (!maybeOpen.Succeeded)
            {
                return(maybeOpen.Failure);
            }

            Possible <string, Failure>[] multiMaybePinned = await maybeOpen.Result.PinToCasAsync(casHashes);

            Contract.Assume(multiMaybePinned != null);
            Contract.Assume(multiMaybePinned.Length == casHashes.Length);

            var     results             = new ContentAvailabilityResult[casHashes.Length];
            Failure aggregateFailure    = null;
            bool    allContentAvailable = true;

            for (int i = 0; i < casHashes.Length; i++)
            {
                Possible <string, Failure> maybePinned = multiMaybePinned[i];

                if (maybePinned.Succeeded)
                {
                    // TODO: This doesn't indicate what is local / how much was transfered. From the similar BuildCache adapter:
                    //  long transferred = successfulResult.TransferredBytes;
                    // TODO: This API will fail just because content isn't available; see below for that case.
                    results[i] = new ContentAvailabilityResult(hashes[i], isAvailable: true, bytesTransferred: 0, sourceCache: maybePinned.Result);
                    BuildXL.Storage.Tracing.Logger.Log.StorageCacheContentPinned(Events.StaticContext, casHashes[i].ToString(), maybePinned.Result);
                }
                else if (maybePinned.Failure is NoCasEntryFailure)
                {
                    // TODO: As above: this API will fail just because content isn't available, and that case isn't distinguishable (at least by looking at the interface alone).
                    //              That's not reasonable for implementations in general, such as BuildCache (or anything else with weak LRU; failures should not be 'normal'
                    //              By contract, IArtifactContentCache defines available vs. unavailable on the (successful) result object, as established here.
                    //              Note that we have idenitifed the content-miss case by reflecting; but that is quite fragile and requires some not-yet-prescribed co-operation from the implementations as to failure type.
                    allContentAvailable = false;
                    results[i]          = new ContentAvailabilityResult(hashes[i], isAvailable: false, bytesTransferred: 0, sourceCache: "ContentMiss");
                }
                else
                {
                    if (aggregateFailure == null)
                    {
                        aggregateFailure = maybePinned.Failure.Annotate("Retrieval failed for one or more content blobs by hash");
                    }

                    // We return only an aggregate error from this function. To prevent erasing information, we log each error returned from
                    // the cache here (the caller may choose to also log the aggregate failure.
                    BuildXL.Storage.Tracing.Logger.Log.StorageCacheCopyLocalError(
                        Events.StaticContext,
                        hashes[i].ToString(),
                        maybePinned.Failure.DescribeIncludingInnerFailures());
                }
            }

            if (aggregateFailure == null)
            {
                return(new ContentAvailabilityBatchResult(
                           ReadOnlyArray <ContentAvailabilityResult> .FromWithoutCopy(results),
                           allContentAvailable: allContentAvailable));
            }
            else
            {
                return(aggregateFailure);
            }
        }
Exemplo n.º 60
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);
            }
        }