The flag close_fds=True does not work on Windows: check before spawning a subprocess

parent 662b4763
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
from __future__ import print_function from __future__ import print_function
import os import os
import sys import sys
import platform
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import os.path import os.path
...@@ -148,6 +149,9 @@ class Env(dict): ...@@ -148,6 +149,9 @@ class Env(dict):
def check_remote_tool(self, info_class): def check_remote_tool(self, info_class):
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
tool_info = info_class.get_keys() tool_info = info_class.get_keys()
remote_path_key = 'rsynth_' + tool_info['id'] + '_path' remote_path_key = 'rsynth_' + tool_info['id'] + '_path'
remote_version_key = 'rsynth_' + tool_info['id'] + '_version' remote_version_key = 'rsynth_' + tool_info['id'] + '_version'
...@@ -160,7 +164,7 @@ class Env(dict): ...@@ -160,7 +164,7 @@ class Env(dict):
if self["rsynth_user"] is not None and self["rsynth_server"] is not None: if self["rsynth_user"] is not None and self["rsynth_server"] is not None:
ssh_cmd = 'ssh -o BatchMode=yes -o ConnectTimeout=5 %s@%s echo ok 2>&1' ssh_cmd = 'ssh -o BatchMode=yes -o ConnectTimeout=5 %s@%s echo ok 2>&1'
ssh_cmd = ssh_cmd % (self["rsynth_user"], self["rsynth_server"]) ssh_cmd = ssh_cmd % (self["rsynth_user"], self["rsynth_server"])
ssh_out = Popen(ssh_cmd, shell=True, stdin=PIPE, stdout=PIPE, close_fds=True) ssh_out = Popen(ssh_cmd, shell=True, stdin=PIPE, stdout=PIPE, close_fds=not is_windows)
ssh_response = ssh_out.stdout.readlines()[0].strip() ssh_response = ssh_out.stdout.readlines()[0].strip()
if ssh_response == "ok": if ssh_response == "ok":
print("Can connect to the remote machine: %s@%s." % (self["rsynth_user"], self["rsynth_server"])) print("Can connect to the remote machine: %s@%s." % (self["rsynth_user"], self["rsynth_server"]))
...@@ -173,7 +177,7 @@ class Env(dict): ...@@ -173,7 +177,7 @@ class Env(dict):
if can_connect and self[remote_path_key] is not None: if can_connect and self[remote_path_key] is not None:
ssh_cmd = 'ssh -o BatchMode=yes -o ConnectTimeout=5 %s@%s test -e %s 2>&1' ssh_cmd = 'ssh -o BatchMode=yes -o ConnectTimeout=5 %s@%s test -e %s 2>&1'
ssh_cmd = ssh_cmd % (self["rsynth_user"], self["rsynth_server"], self[remote_path_key]) ssh_cmd = ssh_cmd % (self["rsynth_user"], self["rsynth_server"], self[remote_path_key])
ssh_out = Popen(ssh_cmd, shell=True, stdin=PIPE, stdout=PIPE, close_fds=True) ssh_out = Popen(ssh_cmd, shell=True, stdin=PIPE, stdout=PIPE, close_fds=not is_windows)
ssh_response = ssh_out.returncode ssh_response = ssh_out.returncode
if ssh_response == 0: if ssh_response == 0:
print("%s found on remote machine under %s." % (name, self[remote_path_key])) print("%s found on remote machine under %s." % (name, self[remote_path_key]))
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
import os import os
from hdlmake.util import path from hdlmake.util import path
import logging import logging
import platform
from tempfile import TemporaryFile from tempfile import TemporaryFile
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from .constants import (GIT, GITSUBMODULE) from .constants import (GIT, GITSUBMODULE)
...@@ -168,6 +169,8 @@ submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git ...@@ -168,6 +169,8 @@ submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git
commit = None commit = None
stderr = TemporaryFile() stderr = TemporaryFile()
try: try:
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
os.chdir(path) os.chdir(path)
git_cmd = 'git log -1 --format="%H" | cut -c1-32' git_cmd = 'git log -1 --format="%H" | cut -c1-32'
git_out = Popen(git_cmd, git_out = Popen(git_cmd,
...@@ -175,7 +178,7 @@ submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git ...@@ -175,7 +178,7 @@ submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git
stdin=PIPE, stdin=PIPE,
stdout=PIPE, stdout=PIPE,
stderr=stderr, stderr=stderr,
close_fds=True) close_fds=not is_windows)
errmsg = stderr.readlines() errmsg = stderr.readlines()
if errmsg: if errmsg:
logging.debug("git error message (in %s): %s" % (path, '\n'.join(errmsg))) logging.debug("git error message (in %s): %s" % (path, '\n'.join(errmsg)))
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
import os import os
import logging import logging
import platform
from tempfile import TemporaryFile from tempfile import TemporaryFile
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from hdlmake.util import path from hdlmake.util import path
...@@ -66,9 +67,11 @@ class Svn(Fetcher): ...@@ -66,9 +67,11 @@ class Svn(Fetcher):
stderr = TemporaryFile() stderr = TemporaryFile()
try: try:
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
os.chdir(path) os.chdir(path)
svn_cmd = "svn info 2>/dev/null | awk '{if(NR == 5) {print $2}}'" svn_cmd = "svn info 2>/dev/null | awk '{if(NR == 5) {print $2}}'"
svn_out = Popen(svn_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=stderr, close_fds=True) svn_out = Popen(svn_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=stderr, close_fds=not is_windows)
errmsg = stderr.readlines() errmsg = stderr.readlines()
if errmsg: if errmsg:
logging.debug("svn error message (in %s): %s" % (path, '\n'.join(errmsg))) logging.debug("svn error message (in %s): %s" % (path, '\n'.join(errmsg)))
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
from __future__ import print_function from __future__ import print_function
import os import os
import logging import logging
import platform
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
import sys import sys
...@@ -114,14 +115,16 @@ class ModulePool(list): ...@@ -114,14 +115,16 @@ class ModulePool(list):
"""Guess origin (git, svn, local) of a module at given path""" """Guess origin (git, svn, local) of a module at given path"""
cwd = self.top_module.path cwd = self.top_module.path
try: try:
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
os.chdir(path) os.chdir(path)
git_out = Popen("git config --get remote.origin.url", stdout=PIPE, shell=True, close_fds=True) git_out = Popen("git config --get remote.origin.url", stdout=PIPE, shell=True, close_fds=not is_windows)
lines = git_out.stdout.readlines() lines = git_out.stdout.readlines()
if len(lines) == 0: if len(lines) == 0:
return None return None
url = lines[0].strip() url = lines[0].strip()
if not url: # try svn if not url: # try svn
svn_out = Popen("svn info | grep 'Repository Root' | awk '{print $NF}'", stdout=PIPE, shell=True, close_fds=True) svn_out = Popen("svn info | grep 'Repository Root' | awk '{print $NF}'", stdout=PIPE, shell=True, close_fds=not is_windows)
url = svn_out.stdout.readlines()[0].strip() url = svn_out.stdout.readlines()[0].strip()
if url: if url:
return url return url
......
...@@ -27,6 +27,7 @@ import xml.parsers.expat ...@@ -27,6 +27,7 @@ import xml.parsers.expat
import logging import logging
import re import re
import os import os
import platform
import string import string
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
...@@ -66,15 +67,9 @@ class ToolControls(MakefileWriter): ...@@ -66,15 +67,9 @@ class ToolControls(MakefileWriter):
return ISE_STANDARD_LIBS return ISE_STANDARD_LIBS
def detect_version(self, path): def detect_version(self, path):
if platform.system() == 'Windows': is_windows = True
#xst = Popen('which xst', shell=True, stdin=PIPE, else: is_windows = False
# stdout=PIPE, close_fds=True)
#lines = xst.stdout.readlines()
#if not lines:
# return None
#xst = str(lines[0].strip())
version_pattern = re.compile('.*?(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d).*') version_pattern = re.compile('.*?(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d).*')
# First check if we have version in path # First check if we have version in path
...@@ -83,7 +78,7 @@ class ToolControls(MakefileWriter): ...@@ -83,7 +78,7 @@ class ToolControls(MakefileWriter):
ise_version = "%s.%s" % (match.group('major'), match.group('minor')) ise_version = "%s.%s" % (match.group('major'), match.group('minor'))
else: # If it is not the case call the "xst -h" to get version else: # If it is not the case call the "xst -h" to get version
xst_output = Popen('xst -h', shell=True, stdin=PIPE, xst_output = Popen('xst -h', shell=True, stdin=PIPE,
stdout=PIPE, close_fds=True) stdout=PIPE, close_fds=not is_windows)
xst_output = xst_output.stdout.readlines()[0] xst_output = xst_output.stdout.readlines()[0]
xst_output = xst_output.strip() xst_output = xst_output.strip()
version_pattern = re.compile('Release\s(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d)\s.*') version_pattern = re.compile('Release\s(?P<major>\d|\d\d)[^\d](?P<minor>\d|\d\d)\s.*')
...@@ -99,10 +94,12 @@ class ToolControls(MakefileWriter): ...@@ -99,10 +94,12 @@ class ToolControls(MakefileWriter):
def generate_remote_synthesis_makefile(self, files, name, cwd, user, server): def generate_remote_synthesis_makefile(self, files, name, cwd, user, server):
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
if name is None: if name is None:
import random import random
name = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8)) name = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8))
whoami = Popen('whoami', shell=True, stdin=PIPE, stdout=PIPE, close_fds=True) whoami = Popen('whoami', shell=True, stdin=PIPE, stdout=PIPE, close_fds=not is_windows)
name = whoami.stdout.readlines()[0].strip() + '/' + name name = whoami.stdout.readlines()[0].strip() + '/' + name
user_tmpl = "USER:={0}" user_tmpl = "USER:={0}"
server_tmpl = "SERVER:={0}" server_tmpl = "SERVER:={0}"
......
...@@ -29,6 +29,7 @@ from subprocess import Popen, PIPE ...@@ -29,6 +29,7 @@ from subprocess import Popen, PIPE
import logging import logging
import sys import sys
import string import string
import platform
from hdlmake.makefile_writer import MakefileWriter from hdlmake.makefile_writer import MakefileWriter
...@@ -54,9 +55,11 @@ class ToolControls(MakefileWriter): ...@@ -54,9 +55,11 @@ class ToolControls(MakefileWriter):
return ISIM_STANDARD_LIBS return ISIM_STANDARD_LIBS
def detect_version(self, path): def detect_version(self, path):
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
isim = Popen("%s --version | awk '{print $2}'" % os.path.join(path, "vlogcomp"), isim = Popen("%s --version | awk '{print $2}'" % os.path.join(path, "vlogcomp"),
shell=True, shell=True,
close_fds=True, close_fds=not is_windows,
stdin=PIPE, stdin=PIPE,
stdout=PIPE) stdout=PIPE)
print os.path.join(path, "vlogcomp") print os.path.join(path, "vlogcomp")
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import string import string
import os import os
import platform
import logging import logging
from hdlmake.makefile_writer import MakefileWriter from hdlmake.makefile_writer import MakefileWriter
...@@ -51,11 +52,13 @@ class ToolControls(MakefileWriter): ...@@ -51,11 +52,13 @@ class ToolControls(MakefileWriter):
return IVERILOG_STANDARD_LIBS return IVERILOG_STANDARD_LIBS
def detect_version(self, path): def detect_version(self, path):
if platform.system() == 'Windows': is_windows = True
else: is_windows = False
iverilog = Popen("iverilog -v 2>/dev/null| awk '{if(NR==1) print $4}'", iverilog = Popen("iverilog -v 2>/dev/null| awk '{if(NR==1) print $4}'",
shell=True, shell=True,
stdin=PIPE, stdin=PIPE,
stdout=PIPE, stdout=PIPE,
close_fds=True) close_fds=not is_windows)
version = iverilog.stdout.readlines()[0].strip() version = iverilog.stdout.readlines()[0].strip()
return version return version
......
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