def generateFortranModules(cmd, srcPath, OutputDir): # Fortran 90 code often fails to compile because it needs modules defined by # other files in the same directory. If this seems to be happening then try # to generate all of the required modules by compiling every Fortran file in # the same directory. srcDir, srcBase = os.path.split(srcPath) cmd = cmd + ['-I', srcDir, '-fsyntax-only'] # If the file compiles OK or isn't failing because of lacking modules then # there is no point in trying to generate modules. out, err, exitCode = DEUtils.executeCommand(cmd + [srcPath], OutputDir) if exitCode == 0 or err is None or "Can't open module file" not in err: return # Drat, it fails to compile. Generate modules for every Fortran file in the # source directory. fortranSuffixes = DEUtils.getSuffixesForLanguage('fortran') filesToCompile = [] for filename in os.listdir(srcDir): filepath = os.path.join(srcDir, filename) if not os.path.isdir(filepath): base, ext = os.path.splitext(filename) if ext in fortranSuffixes: filesToCompile.append(filepath) # Compile every file, returning triumphantly once the original file manages # to compile, or giving up miserably if no progress is being made. newFilesToCompile = [] while filesToCompile != newFilesToCompile: newFilesToCompile = [] # Compile each file in turn. for path in filesToCompile: out, err, exitCode = DEUtils.executeCommand( cmd + [path], OutputDir) if exitCode != 0 and err is not None and "Can't open module file" in err: # It failed to compile due to a missing module. Remember it for # the next round. newFilesToCompile.append(path) elif path == srcPath: # The original file compiled, or at least didn't fail to compile # due to a lacking module. Return triumphantly! return # Arrange for the next iteration to compile the files that were missing # modules this time round. filesToCompile, newFilesToCompile = newFilesToCompile, filesToCompile # The set of files missing modules didn't change, give up miserably. return
def generateFortranModules(cmd, srcPath, OutputDir): # Fortran 90 code often fails to compile because it needs modules defined by # other files in the same directory. If this seems to be happening then try # to generate all of the required modules by compiling every Fortran file in # the same directory. srcDir,srcBase = os.path.split(srcPath) cmd = cmd + ['-I', srcDir, '-fsyntax-only'] # If the file compiles OK or isn't failing because of lacking modules then # there is no point in trying to generate modules. out,err,exitCode = DEUtils.executeCommand(cmd + [srcPath], OutputDir) if exitCode == 0 or err is None or "Can't open module file" not in err: return # Drat, it fails to compile. Generate modules for every Fortran file in the # source directory. fortranSuffixes = DEUtils.getSuffixesForLanguage('fortran') filesToCompile = [] for filename in os.listdir(srcDir): filepath = os.path.join(srcDir, filename) if not os.path.isdir(filepath): base,ext = os.path.splitext(filename) if ext in fortranSuffixes: filesToCompile.append(filepath) # Compile every file, returning triumphantly once the original file manages # to compile, or giving up miserably if no progress is being made. newFilesToCompile = [] while filesToCompile != newFilesToCompile: newFilesToCompile = [] # Compile each file in turn. for path in filesToCompile: out,err,exitCode = DEUtils.executeCommand(cmd + [path], OutputDir) if exitCode != 0 and err is not None and "Can't open module file" in err: # It failed to compile due to a missing module. Remember it for # the next round. newFilesToCompile.append(path); elif path == srcPath: # The original file compiled, or at least didn't fail to compile # due to a lacking module. Return triumphantly! return # Arrange for the next iteration to compile the files that were missing # modules this time round. filesToCompile, newFilesToCompile = newFilesToCompile, filesToCompile # The set of files missing modules didn't change, give up miserably. return
def executeOne(cmd): return DEUtils.executeCommand(cmd + args, cwd)
def executeOne(cmd): return DEUtils.executeCommand(cmd + args, cwd)