def generate(self, projectName, targetPath): tempPath = tempfile.mkdtemp() try: # Create a build build = self.project.platform.createBuild(self.config, self.library, projectName, self.name) # If there is at least one C++ function, generate only C++ code if "c++" in self.getLanguages() or self.config.get( "language", "c") == "c++": playerSourceName = "player_gen.cpp" else: playerSourceName = "player_gen.c" self.library.language = "c" # Generate the player playerSourcePath = os.path.join(tempPath, playerSourceName) g = Generator.CSourcePlayerGenerator( self.config, self.project.platform, [self.library], templatePath=Resource.getPath("templates")) output = open(playerSourcePath, "w") g.generate(outputFile=output) output.close() # Add the generated source file to the configuration self.addSourceFile(playerSourcePath) # Finalize the build build.compile(targetPath=targetPath) finally: try: shutil.rmtree(tempPath) except: Log.warn("Unable to clean up temporary directory '%s'" % tempPath)