From: <mth...@us...> - 2009-04-30 23:05:44
|
Revision: 9679 http://openmsx.svn.sourceforge.net/openmsx/?rev=9679&view=rev Author: mthuurne Date: 2009-04-30 23:05:42 +0000 (Thu, 30 Apr 2009) Log Message: ----------- Moved tryCompile() and tryLink() from "compilers" module to "probe" module: their implementation has to reflect the way we want to probe. Modified Paths: -------------- openmsx/trunk/build/compilers.py openmsx/trunk/build/probe.py Modified: openmsx/trunk/build/compilers.py =================================================================== --- openmsx/trunk/build/compilers.py 2009-04-30 21:53:13 UTC (rev 9678) +++ openmsx/trunk/build/compilers.py 2009-04-30 23:05:42 UTC (rev 9679) @@ -2,19 +2,10 @@ from msysutils import msysActive, msysPathToNative -from os import environ, remove -from os.path import isfile +from os import environ from shlex import split as shsplit from subprocess import PIPE, STDOUT, Popen -def writeFile(path, lines): - out = open(path, 'w') - try: - for line in lines: - print >> out, line - finally: - out.close() - if msysActive(): def fixArgs(args): for arg in args: @@ -114,39 +105,3 @@ def link(self, log, objectPaths, binaryPath): return self._run(log, objectPaths + [ '-o', binaryPath ]) - -def tryCompile(log, compileCommand, sourcePath, lines): - '''Write the program defined by "lines" to a text file specified - by "path" and try to compile it. - Returns True iff compilation succeeded. - ''' - assert sourcePath.endswith('.cc') - objectPath = sourcePath[ : -3] + '.o' - writeFile(sourcePath, lines) - try: - return compileCommand.compile(log, sourcePath, objectPath) - finally: - remove(sourcePath) - if isfile(objectPath): - remove(objectPath) - -def tryLink(log, compileCommand, linkCommand, sourcePath): - assert sourcePath.endswith('.cc') - objectPath = sourcePath[ : -3] + '.o' - binaryPath = sourcePath[ : -3] + '.bin' - def dummyProgram(): - # Try to link dummy program to the library. - yield 'int main(int argc, char **argv) { return 0; }' - writeFile(sourcePath, dummyProgram()) - try: - compileOK = compileCommand.compile(log, sourcePath, objectPath) - if not compileOK: - print >> log, 'cannot test linking because compile failed' - return False - return linkCommand.link(log, [ objectPath ], binaryPath) - finally: - remove(sourcePath) - if isfile(objectPath): - remove(objectPath) - if isfile(binaryPath): - remove(binaryPath) Modified: openmsx/trunk/build/probe.py =================================================================== --- openmsx/trunk/build/probe.py 2009-04-30 21:53:13 UTC (rev 9678) +++ openmsx/trunk/build/probe.py 2009-04-30 23:05:42 UTC (rev 9679) @@ -3,15 +3,15 @@ # Performs some test compiles, to check for headers and functions. # It does not execute anything it builds, making it friendly for cross compiles. -from compilers import CompileCommand, LinkCommand, tryCompile, tryLink +from compilers import CompileCommand, LinkCommand from makeutils import extractMakeVariables from outpututils import rewriteIfChanged from probe_defs import librariesByName from probe_results import iterProbeResults from msysutils import msysActive -from os import environ, makedirs -from os.path import isdir +from os import environ, makedirs, remove +from os.path import isdir, isfile from shlex import split as shsplit from subprocess import PIPE, Popen import sys @@ -87,6 +87,53 @@ # TODO: Report this explicitly in the probe results table. return '' +def writeFile(path, lines): + out = open(path, 'w') + try: + for line in lines: + print >> out, line + finally: + out.close() + +def tryCompile(log, compileCommand, sourcePath, lines): + '''Write the program defined by "lines" to a text file specified + by "path" and try to compile it. + Returns True iff compilation succeeded. + ''' + assert sourcePath.endswith('.cc') + objectPath = sourcePath[ : -3] + '.o' + writeFile(sourcePath, lines) + try: + return compileCommand.compile(log, sourcePath, objectPath) + finally: + remove(sourcePath) + if isfile(objectPath): + remove(objectPath) + +def tryLink(log, compileCommand, linkCommand, sourcePath): + assert sourcePath.endswith('.cc') + objectPath = sourcePath[ : -3] + '.o' + binaryPath = sourcePath[ : -3] + '.bin' + def dummyProgram(): + # Try to link dummy program to the library. + # TODO: Use object file instead of dummy program. + # That way, object file can refer to symbol from the lib and + # we get more useful results from static libs. + yield 'int main(int argc, char **argv) { return 0; }' + writeFile(sourcePath, dummyProgram()) + try: + compileOK = compileCommand.compile(log, sourcePath, objectPath) + if not compileOK: + print >> log, 'cannot test linking because compile failed' + return False + return linkCommand.link(log, [ objectPath ], binaryPath) + finally: + remove(sourcePath) + if isfile(objectPath): + remove(objectPath) + if isfile(binaryPath): + remove(binaryPath) + def checkCompiler(log, compileCommand, outDir): '''Checks whether compiler can compile anything at all. Returns True iff the compiler works. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |