jlink: fix flashing behavior on Windows

The object returned by NamedTemporaryFile cannot be opened a second
time while the file is still open on Windows. This is exactly what the
JLink commander needs to do with the resulting file, however, breaking
jlink flash on that platform.

Fix this by using a temporary directory instead, and creating a file
inside it. The resulting directory still gets cleaned up, but the
resulting file can be read by the commander.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
diff --git a/scripts/support/runner/jlink.py b/scripts/support/runner/jlink.py
index 8d8c6b1..aaf317e 100644
--- a/scripts/support/runner/jlink.py
+++ b/scripts/support/runner/jlink.py
@@ -124,15 +124,18 @@
         lines.append('g') # Start the CPU
         lines.append('q') # Close the connection and quit
 
-        with tempfile.NamedTemporaryFile(suffix='.jlink') as f:
-            f.writelines(bytes(line + '\n', 'utf-8') for line in lines)
-            f.flush()
+        # Don't use NamedTemporaryFile: the resulting file can't be
+        # opened again on Windows.
+        with tempfile.TemporaryDirectory(suffix='jlink') as d:
+            fname = os.path.join(d, 'runner.jlink')
+            with open(fname, 'wb') as f:
+                f.writelines(bytes(line + '\n', 'utf-8') for line in lines)
 
             cmd = ([self.commander] +
                    ['-if', self.iface,
                     '-speed', self.speed,
                     '-device', self.device,
-                    '-CommanderScript', f.name])
+                    '-CommanderScript', fname])
 
             print('Flashing Target Device')
             self.check_call(cmd)