Skip to content
This repository has been archived by the owner on Mar 4, 2018. It is now read-only.

Commit

Permalink
Extend check_compiler to store the correct file extension for program…
Browse files Browse the repository at this point in the history
… and modules

BTW this also make sure we can compile a module.

See #244
  • Loading branch information
ColinDuquesnoy committed Nov 1, 2015
1 parent 401649b commit 6ec57e6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion open_cobol_ide/__init__.py
Expand Up @@ -2,4 +2,4 @@
This package contains the code of the OpenCobolIDE application.
"""

__version__ = '4.7.dev49'
__version__ = '4.7.dev50'
52 changes: 42 additions & 10 deletions open_cobol_ide/compilers.py
Expand Up @@ -170,15 +170,15 @@ class GnuCobolCompiler(QtCore.QObject):

OUTPUT_PATTERNS = [OUTPUT_PATTERN_GCC, OUTPUT_PATTERN_MSVC]

extensions = [
# no extension for exe on linux and mac
'.exe' if system.windows else '',
# .dll on windows, so everywhere else
'.dll' if system.windows else '.so' if system.linux else '.dylib'
]

def __init__(self):
super().__init__()
#: platform specifc extensions, sorted per file type
self.extensions = [
# no extension for exe on linux and mac
'.exe' if system.windows else '',
# .dll on windows, so everywhere else
'.dll' if system.windows else '.so' if system.linux else '.dylib'
]

@staticmethod
def get_version():
Expand Down Expand Up @@ -242,19 +242,52 @@ def setup_process_environment():
@classmethod
@memoized
def check_compiler(cls, compiler):
def get_output_path(input_path):
dirname, filename = os.path.split(input_path)
basename = os.path.splitext(filename)[0]
possible_extensions = ['.exe', '.dll', '.so', '.dylib']
for ext in possible_extensions:
candidate = os.path.join(dirname, basename + ext)
if os.path.exists(candidate):
return candidate
return None

from open_cobol_ide.view.dialogs.preferences import DEFAULT_TEMPLATE
cbl_path = os.path.join(tempfile.gettempdir(), 'test.cbl')
working_dir = tempfile.gettempdir()
cbl_path = os.path.join(working_dir, 'test.cbl')
with open(cbl_path, 'w') as f:
f.write(DEFAULT_TEMPLATE)
dest = os.path.join(tempfile.gettempdir(),
'test' + ('.exe' if system.windows else ''))

_logger().debug('check compiler')

status, output = run_command(compiler, ['-x', '-o', dest, cbl_path])
status, output = run_command(compiler, ['-x', cbl_path],
working_dir=working_dir)
dest = get_output_path(cbl_path)
if dest:
GnuCobolCompiler.extensions[0] = os.path.splitext(dest)[1]
try:
os.remove(dest)
except OSError:
pass

status, output = run_command(compiler, [cbl_path],
working_dir=working_dir)
dest = get_output_path(cbl_path)
if dest:
GnuCobolCompiler.extensions[1] = os.path.splitext(dest)[1]
try:
os.remove(dest)
except OSError:
pass

_logger().info('GnuCOBOL compiler check: %s',
'success' if status == 0 else 'fail')
_logger().info('Executable extension: %s' %
GnuCobolCompiler.extensions[0])
_logger().info('Module extension: %s' %
GnuCobolCompiler.extensions[1])

try:
os.remove(dest)
Expand Down Expand Up @@ -367,7 +400,6 @@ def compile(self, file_path, file_type, object_files=None,
original_output_dir = output_dir
if not os.path.isabs(output_dir):
output_dir = os.path.abspath(os.path.join(path, output_dir))
# run command using qt process api, this is blocking.
if object_files:
inputs = [filename] + object_files
else:
Expand Down

0 comments on commit 6ec57e6

Please sign in to comment.