Ejemplo n.º 1
0
        private bool TryWriteSandboxedProcessResult(PathTable pathTable, SandboxedProcessResult result)
        {
            Contract.Requires(result != null);

            // When BuildXL serializes SandboxedProcessInfo, it does not serialize the path table used by SandboxedProcessInfo.
            // On deserializing that info, a new path table is created; see the Deserialize method of SandboxedProcessInfo.
            // Unix sandbox uses the new path table in the deserialized SandboxedProcessInfo to create ManifestPath (AbsolutePath)
            // from reported path access (string) in ReportFileAccess. Without special case, the serialization of SandboxedProcessResult
            // will serialize the AbsolutePath as is. Then, when SandboxedProcessResult is read by BuildXL, BuildXL will not understand
            // the ManifestPath because it is created from a different path table.
            //
            // In Windows, instead of creating ManifestPath from the reported path access (string), ManifestPath is reported from Detours
            // using the AbsolutePath id embedded in the file access manifest. That AbsolutePath id is obtained using the same
            // path table used by BuildXL, and thus BuildXL will understand the ManifestPath serialized by this tool.
            //
            // For Unix, we need to give a special care of path serialization.
            bool isWindows = !OperatingSystemHelper.IsUnixOS;

            Action <BuildXLWriter, AbsolutePath> writePath = (writer, path) =>
            {
                if (isWindows)
                {
                    writer.Write(true);
                    writer.Write(path);
                }
                else
                {
                    writer.Write(false);
                    writer.Write(path.ToString(pathTable));
                }
            };

            bool success = false;

            ExceptionUtilities.HandleRecoverableIOException(
                () =>
            {
                string sandboxedProcessResultOutputPath = Path.GetFullPath(m_configuration.SandboxedProcessResultOutputFile);
                m_logger.LogInfo($"Writing sandboxed process result to '{sandboxedProcessResultOutputPath}'");

                using (FileStream stream = File.OpenWrite(sandboxedProcessResultOutputPath))
                {
                    result.Serialize(stream, writePath);
                }

                success = true;
            },
                ex =>
            {
                m_logger.LogError(ex.ToString());
                success = false;
            });

            return(success);
        }
Ejemplo n.º 2
0
        private bool TryWriteSandboxedProcessResult(SandboxedProcessResult result)
        {
            Contract.Requires(result != null);

            bool success = false;

            ExceptionUtilities.HandleRecoverableIOException(
                () =>
            {
                using (FileStream stream = File.OpenWrite(Path.GetFullPath(m_configuration.SandboxedProcessResultOutputFile)))
                {
                    result.Serialize(stream);
                }

                success = true;
            },
                ex =>
            {
                m_logger.LogError(ex.ToString());
                success = false;
            });

            return(success);
        }