コード例 #1
0
        /// <summary>
        /// The compilation requires us to change into the compile output folder since the
        /// AssemblyBuilder.Save does not use a full path when generating the assembly.
        /// </summary>
        public void Compile()
        {
            VerifyParameters();

            // Compile the source files to a dll first.
            ScriptEngine engine = IronPython.Hosting.Python.CreateEngine();
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary.Add("mainModule", mainFile);
            string outputAssemblyDll = Path.ChangeExtension(outputAssembly, ".dll");

            ClrModule.CompileModules(DefaultContext.Default, outputAssemblyDll, dictionary, ToStringArray(sourceFiles));

            // Generate an executable if required.
            if (targetKind != PEFileKinds.Dll)
            {
                // Change into compilation folder.
                string originalFolder = Directory.GetCurrentDirectory();
                try {
                    string compileFolder = Path.Combine(originalFolder, Path.GetDirectoryName(outputAssembly));
                    Directory.SetCurrentDirectory(compileFolder);
                    GenerateExecutable(outputAssemblyDll);
                } finally {
                    Directory.SetCurrentDirectory(originalFolder);
                }
            }
        }
コード例 #2
0
        static int Main(string[] args)
        {
            var files  = new List <string>();
            var config = new Config();

            config.ParseArgs(args);
            if (!config.Validate())
            {
                ConsoleOps.Usage(true);
            }
            ConsoleOps.Info("{0}", config);
            ConsoleOps.Info("compiling...");

            // we don't use the engine, but we create it so we can have a default context.
            ScriptEngine engine = Python.CreateEngine();

            ClrModule.CompileModules(DefaultContext.DefaultCLS, config.Output + ".dll", new Dictionary <string, object> {
                { "mainModule", config.MainName }
            }, config.Files.ToArray());

            if (config.Target != PEFileKinds.Dll)
            {
                GenerateExe(config);
            }

            ConsoleOps.Info("Saved to {0}", config.Output);
            return(0);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: zpeach68/ironpython2
        public static int Main(string[] args)
        {
            var files  = new List <string>();
            var config = new Config();

            config.ParseArgs(args);
            if (!config.Validate())
            {
                ConsoleOps.Usage(true);
            }

            // we don't use the engine, but we create it so we can have a default context.
            ScriptEngine engine = Python.CreateEngine(config.PythonOptions);

            ConsoleOps.Info($"IronPython Compiler for {engine.Setup.DisplayName} ({engine.LanguageVersion})");
            ConsoleOps.Info($"{config}");
            ConsoleOps.Info("compiling...");

            var compileOptions = new Dictionary <string, object>()
            {
                { "mainModule", config.MainName },
                { "assemblyFileVersion", config.FileVersion },
                { "copyright", config.Copyright },
                { "productName", config.ProductName },
                { "productVersion", config.ProductVersion },
            };

            try
            {
                ClrModule.CompileModules(DefaultContext.DefaultCLS,
                                         Path.Combine(config.OutputPath, Path.ChangeExtension(config.Output, ".dll")),
                                         compileOptions,
                                         config.Files.ToArray());

                var outputfilename = Path.Combine(config.OutputPath, Path.ChangeExtension(config.Output, ".dll"));
                if (config.Target != PEFileKinds.Dll)
                {
                    outputfilename = Path.Combine(config.OutputPath, Path.ChangeExtension(config.Output, ".exe"));
                    GenerateExe(config);
                }
                ConsoleOps.Info($"Saved to {outputfilename}");
            }
            catch (Exception e)
            {
                Console.WriteLine();
                ConsoleOps.Error(true, e.Message);
            }
            return(0);
        }