Skip to content

Commit

Permalink
xilinx/ise: Add Cygwin path to Windows conversion in xst files (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
cr1901 authored and sbourdeauducq committed Jul 17, 2018
1 parent 1ec3ea9 commit 26d77fe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
7 changes: 3 additions & 4 deletions migen/build/generic_programmer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import os, sys
from migen.build import tools


class GenericProgrammer:
Expand All @@ -15,7 +16,7 @@ def set_flash_proxy_dir(self, flash_proxy_dir):
def find_flash_proxy(self):
for d in self.flash_proxy_dirs:
fulldir = os.path.abspath(os.path.expanduser(d))
fullname = os.path.join(fulldir, self.flash_proxy_basename)
fullname = tools.cygpath(os.path.join(fulldir, self.flash_proxy_basename))
if os.path.exists(fullname):
return fullname
raise OSError("Failed to find flash proxy bitstream")
Expand All @@ -27,5 +28,3 @@ def load_bitstream(self, bitstream_file):
# must be overloaded by specific programmer
def flash(self, address, data_file):
raise NotImplementedError


33 changes: 33 additions & 0 deletions migen/build/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import subprocess
import sys
import ctypes


def language_by_filename(name):
Expand Down Expand Up @@ -55,3 +56,35 @@ def subprocess_call_filtered(command, rules, *, max_matches=1, **kwargs):
for line in stdout:
print(sub_rules(line, rules, max_matches), end="")
return proc.wait()


if sys.platform == "cygwin":
cygwin1 = ctypes.CDLL("/usr/bin/cygwin1.dll")
cygwin_conv_path_proto = ctypes.CFUNCTYPE(
ctypes.c_ssize_t, # Return
ctypes.c_uint, # what
ctypes.c_void_p, # from
ctypes.c_void_p, # to
ctypes.c_size_t) # size
cygwin_conv_path = cygwin_conv_path_proto(("cygwin_conv_path", cygwin1),
((1, "what"),
(1, "from"),
(1, "to"),
(1, "size")))


def cygpath_to_windows(path):
what = ctypes.c_uint(0) # CCP_POSIX_TO_WIN_A
fro = ctypes.c_char_p(path.encode('utf-8'))
to = ctypes.byref(ctypes.create_string_buffer(260))
size = ctypes.c_size_t(260)

cygwin_conv_path(what, fro, to, size)
return ctypes.cast(to, ctypes.c_char_p).value.decode('utf-8')

# Convert cygwin paths to Windows native paths. This is a noop otherwise.
def cygpath(p):
return cygpath_to_windows(p)
else:
def cygpath(p):
return p
6 changes: 3 additions & 3 deletions migen/build/xilinx/ise.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _build_ucf(named_sc, named_pc):
def _build_xst_files(device, sources, vincpaths, build_name, xst_opt):
prj_contents = ""
for filename, language, library in sources:
prj_contents += language + " " + library + " " + filename + "\n"
prj_contents += language + " " + library + " " + tools.cygpath(filename) + "\n"
tools.write_to_file(build_name + ".prj", prj_contents)

xst_contents = """run
Expand All @@ -58,7 +58,7 @@ def _build_xst_files(device, sources, vincpaths, build_name, xst_opt):
-p {device}
""".format(build_name=build_name, xst_opt=xst_opt, device=device)
for path in vincpaths:
xst_contents += "-vlgincdir " + path + "\n"
xst_contents += "-vlgincdir " + tools.cygpath(path) + "\n"
tools.write_to_file(build_name + ".xst", xst_contents)


Expand Down Expand Up @@ -97,7 +97,7 @@ def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
fail_stmt = ""
if source:
settings = common.settings(ise_path, ver, "ISE_DS")
build_script_contents += source_cmd + settings + "\n"
build_script_contents += source_cmd + tools.cygpath(settings) + "\n"
if mode == "edif":
ext = "edif"
else:
Expand Down

0 comments on commit 26d77fe

Please sign in to comment.