@@ -82,6 +82,8 @@ Example:
8282)
8383
8484def _openocd_debug_server_impl (ctx ):
85+ # is_windows = "windows" in ctx.var['TARGET_CPU']
86+ is_windows = ctx .host_configuration .host_path_separator == ";"
8587 interface_config_string = ""
8688 for config in ctx .attr .interface_configs :
8789 interface_config_string = interface_config_string + " -f " + config
@@ -92,20 +94,66 @@ def _openocd_debug_server_impl(ctx):
9294 if ctx .attr .transport :
9395 transport_string = "-c \" transport select %s\" " % (ctx .attr .transport )
9496 script_template = """
95- {openocd} {interface_config_string} {transport_string} -c "adapter_khz {programmer_frequency}" {chip_config_string}
97+ {openocd} {interface_config_string} {transport_string} -c "adapter speed {programmer_frequency}" {chip_config_string}
9698
9799"""
98100
99- script = ctx .actions .declare_file ("%s.sh" % ctx .label .name )
100- script_content = script_template .format (
101- openocd = ctx .file ._openocd .short_path ,
102- interface_config_string = interface_config_string ,
103- chip_config_string = chip_config_string ,
104- programmer_frequency = ctx .attr .programmer_frequency ,
105- transport_string = transport_string ,
106- )
101+ script_content = ""
102+ if is_windows :
103+ # A bit of a hacky way to do this... The issue is Windows does not support
104+ # symlinks which does not work well for runfiles in particular. To enable them
105+ # the user must use Developer Mode, also not ideal. Instead:
106+ # 1) Use the 'symlink' as a generic path to the root of openocd
107+ # 2) Open the MANIFEST file (non-standard format, beware for future versions)
108+ # 3) Find com_openocd and use the full path to the symlink
109+ # 4) In batch script, cd to base of tool and call bin/openocd.exe directly
110+ windows_script_prepend = """
111+ @echo off
112+ for /f "tokens=*" %%a in (MANIFEST) do call :SEARCH %%a %%a
113+
114+ :SEARCH
115+ set str1=%1
116+ if /i "%str1:~0,11%"=="com_openocd" goto FOUND
117+
118+ goto FAIL
119+
120+ :FOUND
121+ for %%i in (%2) do call :MAKEPATH %%~di%%~pi
122+
123+ goto EOF
124+
125+ :MAKEPATH
126+ cd %1
127+
128+
129+ """
130+ windows_script_append = """
131+ goto EOF
132+
133+ :FAIL
134+
135+ :EOF
136+
137+ """
138+ script = ctx .actions .declare_file ("%s.bat" % ctx .label .name )
139+ script_content = windows_script_prepend + script_template .format (
140+ openocd = "\" bin/openocd.exe\" " ,
141+ interface_config_string = interface_config_string ,
142+ chip_config_string = chip_config_string ,
143+ programmer_frequency = ctx .attr .programmer_frequency ,
144+ transport_string = transport_string ,
145+ ) + windows_script_append
146+ else :
147+ script = ctx .actions .declare_file ("%s.sh" % ctx .label .name )
148+ script_content = script_template .format (
149+ openocd = ctx .file ._openocd .short_path ,
150+ interface_config_string = interface_config_string ,
151+ chip_config_string = chip_config_string ,
152+ programmer_frequency = ctx .attr .programmer_frequency ,
153+ transport_string = transport_string ,
154+ )
107155 ctx .actions .write (script , script_content , is_executable = True )
108- runfiles = ctx .runfiles (files = [ctx .file ._openocd ])
156+ runfiles = ctx .runfiles (files = [ctx .file ._openocd ] )
109157 return [DefaultInfo (executable = script , runfiles = runfiles )]
110158
111159openocd_debug_server = rule (
0 commit comments