Ejemplo n.º 1
0
        public void Compile()
        {
            string fullPath = Path.GetFullPath(outputAssembly);
            string outDir   = Path.GetDirectoryName(fullPath);
            string fileName = Path.GetFileName(outputAssembly);

            PythonCompilerSink sink = new PythonCompilerSink(compilerSink);

            assemblyGen = new AssemblyGen(
                Path.GetFileNameWithoutExtension(outputAssembly),
                outDir, fileName, includeDebugInformation, executable, machine
                );

            bool entryPointSet = false;

            // set default main file
            if (mainFile == null && sourceFiles.Count == 1 && targetKind != PEFileKinds.Dll)
            {
                mainFile = sourceFiles[0];
            }

            foreach (string sourceFile in sourceFiles)
            {
                bool createMainMethod = sourceFile == mainFile;
                CompilePythonModule(sourceFile, sink, createMainMethod);

                if (sink.Errors > 0)
                {
                    return;
                }

                if (createMainMethod)
                {
                    entryPointSet = true;
                }
            }

            if (resourceFiles != null)
            {
                foreach (ResourceFile rf in resourceFiles)
                {
                    assemblyGen.AddResourceFile(rf.Name, rf.File, rf.PublicResource ? ResourceAttributes.Public : ResourceAttributes.Private);
                }
            }

            if (targetKind != PEFileKinds.Dll && !entryPointSet)
            {
                sink.AddError("", string.Format("Need an entry point for target kind {0}", targetKind), -1, Severity.Error);
            }

            assemblyGen.Dump();
        }