예제 #1
0
        static void CompileAssembly()
        {
            var options = new CompilerOptions();

            //redirect cl options to compiler
            if (!RedirectOptions(options))
            {
                LogError(Errors.InvalidCommandLine);
                Environment.Exit(-1);
            }

            //remove system references
            options.References.RemoveAll(IsSysRef);

            //add reference to pagefx corlib
            AddCorlibRef(options);
            AddCommonoRefs(options);

            if (cl.HasOption(PFCOptions.MX))
            {
                string mx = GlobalSettings.GetMxLibraryPath();
                if (!File.Exists(mx))
                {
                    //TODO: raise error
                }
                options.AddRef(mx);
            }

            var rsls = RslList.Parse(cl);

            foreach (var rsl in rsls)
            {
                options.AddRef(rsl.Library);
            }

            options.NoLogo   = true;
            options.NoStdlib = true;
            options.NoConfig = true;
            options.Output   = asmpath;

            string cout = CompilerConsole.Run(options, true);

            var errors = CompilerConsole.ParseOutput(cout);

            if (NoMain(errors))
            {
                asmpath        = Path.ChangeExtension(asmpath, ".dll");
                options.Output = asmpath;
                options.Target = CompilerTarget.Library;

                cout   = CompilerConsole.Run(options, true);
                errors = CompilerConsole.ParseOutput(cout);
            }

            if (errors.HasErrors)
            {
                Console.WriteLine(cout);
                Environment.Exit(-1);
            }
        }
예제 #2
0
        public static bool Compile(TestCase tc)
        {
            tc.CopySourceFiles();

            var lang = tc.Language;

            if (lang == CompilerLanguage.CIL)
            {
                return(ILAsm.Run(tc));
            }

            using (tc.Root.ChangeCurrentDirectory())
            {
                var options = new CompilerOptions();
                try
                {
                    ResolveReferences(tc.Root, tc.References, options.References);
                }
                catch (Exception exc)
                {
                    tc.Error = String.Format("Unable to resolve test case {0} references. Exception:\n{1}",
                                             tc.Name, exc);
                    return(false);
                }

                SetCompilerOptions(tc, lang, options);

                try
                {
                    string cout = CompilerConsole.Run(options, true);
                    if (CompilerConsole.HasErrors(cout))
                    {
                        tc.Error = String.Format("Unable to compile test case {0}.\n{1}", tc.Name, cout);
                        return(false);
                    }
                }
                catch (Exception exc)
                {
                    tc.Error = String.Format("Unable to compile test case {0}. Exception:\n{1}", tc.Name, exc);
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        static void RunTest(Test test)
        {
            string wd = Environment.CurrentDirectory;

            const string prefix   = "__pfx_nunit";
            const string name_cs  = prefix + ".cs";
            const string name_exe = prefix + ".exe";
            const string name_swf = prefix + ".swf";

            string mainFile = Path.Combine(wd, name_cs);

            File.WriteAllText(mainFile, test.MainCode);

            var compilerOptions = new CompilerOptions
            {
                Target   = CompilerTarget.ConsoleApp,
                Output   = name_exe,
                NoLogo   = true,
                NoConfig = true,
                NoStdlib = true
            };

            GlobalSettings.AddCommonReferences(compilerOptions);
            compilerOptions.AddRef(_asmpath);
            compilerOptions.Input.Add(name_cs);

            string cout = CompilerConsole.Run(compilerOptions);

            if (CompilerConsole.HasErrors(cout))
            {
                Console.WriteLine(cout);
                Environment.Exit(-1);
            }

            string path_exe = Path.Combine(wd, name_exe);
            string path_swf = Path.Combine(wd, name_swf);

            var asm = LoadAssembly(path_exe);

            MakeSwf(asm, path_swf);
            RunPlayer(test, path_swf);
            Report.AddTest(test);
        }
예제 #4
0
        private void Compile(string resname)
        {
            string sourceCode = GetType().GetTextResource(resname);
            string dir        = Path.Combine(QA.RootTestCases, "NegativeTests");

            Directory.CreateDirectory(dir);
            string csfile = Path.Combine(dir, "src.cs");

            File.WriteAllText(csfile, sourceCode);

            string asmpath = Path.Combine(dir, "out.dll");

            var options = new CompilerOptions
            {
                NoLogo   = true,
                NoConfig = true,
                NoStdlib = true,
                Target   = CompilerTarget.Library,
                Output   = asmpath
            };

            GlobalSettings.AddCommonReferences(options);

            options.Input.Add(csfile);

            string err = CompilerConsole.Run(options);

            if (!string.IsNullOrEmpty(err))
            {
                throw new InvalidOperationException("Unable to compile " + resname);
            }

            var asm = AssemblyLoader.Load(asmpath, VM.AVM, dir, ref err);

            string swfpath = Path.Combine(dir, "out.swf");

            FlashLanguageInfrastructure.Serialize(asm, swfpath, "/format:swf");
        }
예제 #5
0
        private static void Compile(CompilerOptions copts, string path)
        {
            string olddir = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = Path.GetDirectoryName(path);
                string cout   = CompilerConsole.Run(copts, true);
                var    errors = CompilerConsole.ParseOutput(cout);
                if (errors.HasErrors)
                {
                    throw new InvalidOperationException(string.Format("Unable to generate wrapper.\n{0}", cout));
                }
                if (errors.HasWarnings)
                {
                    Console.WriteLine(cout);
                }
            }
            finally
            {
                Environment.CurrentDirectory = olddir;
            }
        }