Commit 2db9c7bf authored by Tristan Gingold's avatar Tristan Gingold

shell: Split check_windows.

THere is now check_windows_tools and check_windows_commands.
parent e9b5dc57
......@@ -119,7 +119,7 @@ class Git(Fetcher):
config_content = Popen("git config -f .gitmodules --list",
stdout=PIPE,
stdin=PIPE,
close_fds=not shell.check_windows(),
close_fds=not shell.check_windows_tools(),
shell=True)
config_lines = [line.strip().decode('utf-8') for line
in config_content.stdout.readlines()]
......
......@@ -172,7 +172,7 @@ def set_logging_level(options):
if not isinstance(numeric_level, int):
raise Exception('Invalid log level: %s' % options.log)
if not shell.check_windows() and options.logfile == None:
if not shell.check_windows_tools() and options.logfile == None:
logging.basicConfig(
format=colored(
"%(levelname)s",
......
......@@ -118,7 +118,7 @@ $(TCL_CLOSE)'''
'translate': _ISE_RUN.format("Translate"),
'map': _ISE_RUN.format("Map"),
'par': _ISE_RUN.format("Place "
+ ("^&" if shell.check_windows() else "'&'")
+ ("^&" if shell.check_windows_tools() else "'&'")
+ " Route"),
'bitstream': _ISE_RUN.format("Generate Programming File"),
'install_source': "*.bit *.bin"}
......@@ -151,7 +151,7 @@ $(TCL_CLOSE)'''
syn_properties = self.manifest_dict.get("syn_properties")
project_new = []
project_tcl = self._tcl_controls["project"]
if shell.check_windows():
if shell.check_windows_commands():
tmp = 'project set "{0}" "{1}"'
else:
tmp = 'project set \\"{0}\\" \\"{1}\\"'
......
......@@ -74,7 +74,7 @@ class ToolISim(MakeSim):
xilinx_dir = str(os.path.join(
self.manifest_dict["sim_path"], "..", ".."))
hdl_language = 'vhdl' # 'verilog'
if shell.check_windows():
if shell.check_windows_tools():
os_prefix = 'nt'
else:
os_prefix = 'lin'
......
......@@ -48,7 +48,7 @@ class MakeSyn(ToolMakefile):
def _makefile_syn_top(self):
"""Create the top part of the synthesis Makefile"""
if shell.check_windows():
if shell.check_windows_tools():
tcl_interpreter = self._tool_info["windows_bin"]
else:
tcl_interpreter = self._tool_info["linux_bin"]
......@@ -125,14 +125,14 @@ endif""")
for command in self._tcl_controls["files"].split('\n'):
tcl_command.append(echo_command.format(command))
command_string = "\n".join(tcl_command)
if shell.check_windows():
if shell.check_windows_commands():
command_string = command_string.replace("'", "")
self.writeln(command_string)
for filetype in sources_list:
filetype_string = ('\t\t@$(foreach sourcefile,'
' $(SOURCES_{0}), echo "{1}" >> $@ &)'.format(
filetype.__name__, fileset_dict[filetype]))
if shell.check_windows():
if shell.check_windows_commands():
filetype_string = filetype_string.replace(
'"', '')
self.writeln(filetype_string)
......@@ -155,7 +155,7 @@ endif""")
for command in self._tcl_controls[stage].split('\n'):
tcl_command.append(echo_command.format(command))
command_string = "\n".join(tcl_command)
if shell.check_windows():
if shell.check_windows_commands():
command_string = command_string.replace(
"'", "")
self.writeln("""\
......
......@@ -74,7 +74,7 @@ class ToolMakefile(object):
def _get_name_bin(self):
"""Get the name and binary values"""
if shell.check_windows():
if shell.check_windows_tools():
bin_name = self._tool_info['windows_bin']
else:
bin_name = self._tool_info['linux_bin']
......@@ -137,7 +137,7 @@ class ToolMakefile(object):
self.writeln("clean:")
tmp = "\t\t" + shell.del_command() + " $(CLEAN_TARGETS)"
self.writeln(tmp)
if shell.check_windows():
if shell.check_windows_commands():
tmp = "\t\t@-" + shell.rmdir_command() + \
" $(CLEAN_TARGETS) >nul 2>&1"
self.writeln(tmp)
......@@ -170,7 +170,7 @@ class ToolMakefile(object):
if not self._initialized:
self._initialized = True
self.initialize()
if shell.check_windows():
if shell.check_windows_commands():
self._file.write(line.replace('\\"', '"'))
else:
self._file.write(line)
......
......@@ -39,7 +39,7 @@ def run(command):
stdout=PIPE,
stdin=PIPE,
stderr=PIPE,
close_fds=not check_windows(),
close_fds=not check_windows_tools(), # FIXME: comment
shell=True)
lines = command_out.stdout.readlines()
if len(lines) == 0:
......@@ -56,17 +56,19 @@ def tclpath(path):
return path.replace(slash_char(), "/")
def check_windows():
"""Check if we are operating on a Windows filesystem"""
if platform.system() == 'Windows' or sys.platform == 'cygwin':
return True
else:
return False
def check_windows_tools():
"""Check if we are using windows version of synthesis/simulation tools"""
return platform.system() == 'Windows' or sys.platform == 'cygwin'
def check_windows_commands():
"""Check if we are using windows commands (del/type).
False on cygwin"""
return platform.system() == 'Windows'
def del_command():
"""Get a string with the O.S. specific delete command"""
if check_windows():
if check_windows_commands():
return "del /s /q /f"
else:
return "rm -rf"
......@@ -74,7 +76,7 @@ def del_command():
def rmdir_command():
"""Get a string with the O.S. specific remove directory command"""
if check_windows():
if check_windows_commands():
return "rmdir /s /q"
else:
return "rm -rf"
......@@ -82,7 +84,7 @@ def rmdir_command():
def copy_command():
"""Get a string with the O.S. specific copy command"""
if check_windows():
if check_windows_commands():
return "copy"
else:
return "cp"
......@@ -90,7 +92,7 @@ def copy_command():
def mkdir_command():
"""Get a string with the O.S. specific mkdir command"""
if check_windows():
if check_windows_commands():
return "mkdir"
else:
return "mkdir -p"
......@@ -98,7 +100,7 @@ def mkdir_command():
def touch_command():
"""Get a string with the O.S. specific mkdir command"""
if check_windows():
if check_windows_commands():
return "type nul >>"
else:
return "touch"
......@@ -117,7 +119,7 @@ def which(filename):
def slash_char():
"""Get a string with the O.S. specific path separator"""
if check_windows():
if check_windows_tools():
return "\\"
else:
return "/"
......
......@@ -12,7 +12,8 @@ class Config(object):
def __init__(self, path=None, check_windows=False, fakebin="linux_fakebin"):
self.path = path
self.prev_env_path = os.environ['PATH']
self.prev_check_windows = hdlmake.util.shell.check_windows
self.prev_check_windows_commands = hdlmake.util.shell.check_windows_commands
self.prev_check_windows_tools = hdlmake.util.shell.check_windows_tools
self.check_windows = check_windows
self.fakebin = fakebin
......@@ -22,13 +23,15 @@ class Config(object):
+ self.prev_env_path)
if self.path is not None:
os.chdir(self.path)
hdlmake.util.shell.check_windows = (lambda : self.check_windows)
hdlmake.util.shell.check_windows_tools = (lambda : self.check_windows)
hdlmake.util.shell.check_windows_commands = (lambda : self.check_windows)
def __exit__(self, *_):
if self.path is not None:
os.chdir("..")
os.environ['PATH'] = self.prev_env_path
hdlmake.util.shell.check_windows = self.prev_check_windows
hdlmake.util.shell.check_windows_tools = self.prev_check_windows_tools
hdlmake.util.shell.check_windows_commands = self.prev_check_windows_commands
def compare_makefile():
ref = open('Makefile.ref', 'r').read()
......@@ -399,7 +402,7 @@ def test_dep_level():
run(['list-files', '--top', 'level2'], path="053vlog_dep_level")
def test_modelsim_windows():
assert hdlmake.util.shell.check_windows() is False
assert hdlmake.util.shell.check_windows_tools() is False
run_compare(path="057msim_windows", check_windows=True)
def test_nosim_tool():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment