Beispiel #1
0
        public static int Start(BinaryInfo info, string extra_args, MBFile stdin,
                                MBFile stdout, out string stderr, IBuildContext ctxt)
        {
            MemoryStream ms            = new MemoryStream(32);
            StreamReader stdin_stream  = null;
            StreamWriter stdout_stream = null;
            StreamWriter stderr_stream = null;
            int          exit_code;

            if (stdin != null)
            {
                stdin_stream = new StreamReader(stdin.OpenRead(ctxt));
                ctxt.Logger.Log("launcher.stdin_from", stdin.GetPath(ctxt));
            }

            if (stdout != null)
            {
                stdout_stream = new StreamWriter(stdout.OpenWrite(ctxt));
                ctxt.Logger.Log("launcher.stdout_to", stdout.GetPath(ctxt));
            }

            stderr_stream = new StreamWriter(ms);

            exit_code = Start(info, extra_args, stdin_stream, stdout_stream,
                              stderr_stream, ctxt);

            byte[] buf = ms.ToArray();
            stderr = System.Text.Encoding.Default.GetString(buf).Trim();

            return(exit_code);
        }
Beispiel #2
0
        public static int Start(BinaryInfo info, string extra_args, MBFile stdin,
                                MBFile stdout, MBFile stderr, IBuildContext ctxt)
        {
            StreamReader stdin_stream  = null;
            StreamWriter stdout_stream = null;
            StreamWriter stderr_stream = null;

            if (stdin != null)
            {
                stdin_stream = new StreamReader(stdin.OpenRead(ctxt));
                ctxt.Logger.Log("launcher.stdin_from", stdin.GetPath(ctxt));
            }

            if (stdout != null)
            {
                stdout_stream = new StreamWriter(stdout.OpenWrite(ctxt));
                ctxt.Logger.Log("launcher.stdout_to", stdout.GetPath(ctxt));
            }

            if (stderr != null)
            {
                stderr_stream = new StreamWriter(stderr.OpenWrite(ctxt));
                ctxt.Logger.Log("launcher.stderr_to", stderr.GetPath(ctxt));
            }

            return(Start(info, extra_args, stdin_stream, stdout_stream,
                         stderr_stream, ctxt));
        }
Beispiel #3
0
        public IOSink(MBFile file, IBuildContext ctxt)
        {
            if (file == null)
            {
                throw new ArgumentNullException();
            }

            writer = new StreamWriter(file.OpenWrite(ctxt));
        }
        public override Result Build(IBuildContext ctxt)
        {
            string outname = GetOutputName(ctxt);

            if (outname == null)
            {
                return(null);
            }

            string resname = GetResourceName(ctxt);

            // Output

            MBFile file = (MBFile)CreateResultObject();

            file.Dir  = ctxt.WorkingDirectory;
            file.Name = outname;
            StreamWriter writer = new StreamWriter(file.OpenWrite(ctxt));

            // Input stream

            Assembly caller  = Assembly.GetAssembly(GetType());
            Stream   rstream = caller.GetManifestResourceStream(resname);

            if (rstream == null)
            {
                ctxt.Logger.Error(9999, "No such resource stream " + resname +
                                  " in assembly " + caller.FullName, null);
                return(null);
            }

            StreamReader reader = new StreamReader(rstream);

            // Do it

            try {
                char[] buf = new char[512];
                int    read;

                do
                {
                    read = reader.Read(buf, 0, buf.Length);
                    writer.Write(buf, 0, read);
                } while (read > 0);
            } catch (Exception e) {
                ctxt.Logger.Error(9999, "Exception while writing to file from resource stream" + resname,
                                  e.Message);
                return(null);
            } finally {
                reader.Close();
                writer.Close();
            }

            return(file);
        }
Beispiel #5
0
        public static int SaveToolStdout(BinaryInfo info, string extra_args, MBFile stdout,
                                         out string stderr, IBuildContext ctxt)
        {
            Stream       sout  = stdout.OpenWrite(ctxt);
            StreamWriter wout  = new StreamWriter(sout);
            MemoryStream mserr = new MemoryStream(32);
            StreamWriter err   = new StreamWriter(mserr);

            int result = Start(info, extra_args, null, wout, err, ctxt);

            byte[] buf = mserr.ToArray();
            stderr = System.Text.Encoding.Default.GetString(buf).Trim();

            ctxt.Logger.Log("launcher.stdout_to", stdout.GetPath(ctxt));
            ctxt.Logger.Log("launcher.stderr", stderr);
            return(result);
        }