diff options
author | Roman Lacko <backup.rlacko@gmail.com> | 2013-04-25 15:16:22 +0200 |
---|---|---|
committer | Roman Lacko <backup.rlacko@gmail.com> | 2013-04-25 15:16:22 +0200 |
commit | f8ecd2380ff3d58429e9c99daacd7d913b14d7aa (patch) | |
tree | 14f33b133ced5eab301b5015863d09cda0ecfe82 | |
parent | 465311e322830c8621f3b47e5635b2e490e82fad (diff) |
Support for building windows binaries outside Visual Studio Command Prompt using the --msvc-version option. The MSVC environment is now properly initialized by setup script.
-rw-r--r-- | setup.py | 41 | ||||
-rw-r--r-- | utils.py | 11 |
2 files changed, 38 insertions, 14 deletions
@@ -245,11 +245,22 @@ class pyside_build(_build): self.py_version = None self.build_type = "Release" self.qtinfo = None - self.msvc_env = None def run(self): - # Try to get MSVC env + def update_env_path(newpaths): + paths = os.environ['PATH'].lower().split(os.pathsep) + for path in newpaths: + if not path.lower() in paths: + log.info("Inserting path \"%s\" to environment" % path) + paths.insert(0, path) + os.environ['PATH'] = os.pathsep.join(paths) + + platform_arch = platform.architecture()[0] + log.info("Python architekture is %s" % platform_arch) + + # Try to init the MSVC env if sys.platform == "win32" and OPTION_MSVCVERSION: + # Search for MSVC log.info("Searching vcvarsall.bat for MSVC version %s" % OPTION_MSVCVERSION) msvc_version = float(OPTION_MSVCVERSION) vcvarsall_path = find_vcvarsall(msvc_version) @@ -257,8 +268,21 @@ class pyside_build(_build): raise DistutilsSetupError( "Failed to find the vcvarsall.bat for MSVC version %s." % OPTION_MSVCVERSION) log.info("Found %s" % vcvarsall_path) - vcvarsall_cmd = ["call", vcvarsall_path] - self.msvc_env = get_environment_from_batch_command(vcvarsall_path) + # Get MSVC env + msvc_arch = "x86" if platform_arch.startswith("32") else "amd64" + log.info("Getting MSVC env for %s architecture" % msvc_arch) + vcvarsall_cmd = ["call", vcvarsall_path, msvc_arch] + msvc_env = get_environment_from_batch_command(vcvarsall_path) + msvc_env_paths = os.pathsep.join([msvc_env[k] for k in msvc_env if k.upper() == 'PATH']).split(os.pathsep) + msvc_env_without_paths = dict([(k, msvc_env[k]) for k in msvc_env if k.upper() != 'PATH']) + # Extend os.environ with MSVC env + log.info("Initializing MSVC env...") + update_env_path(msvc_env_paths) + for k in msvc_env_without_paths: + v = msvc_env_without_paths[k] + log.info("Inserting \"%s = %s\" to environment" % (k, v)) + os.environ[k] = v + log.info("Done initializing MSVC env") # Check env make_path = None @@ -368,14 +392,7 @@ class pyside_build(_build): sys.exit(1) # Update the PATH environment variable - def updatepath(path): - paths = os.environ['PATH'].lower().split(os.pathsep) - if not path.lower() in paths: - log.info("Inserting path \"%s\" to environment" % path) - paths.insert(0, path) - os.environ['PATH'] = os.pathsep.join(paths) - updatepath(py_scripts_dir) - updatepath(qt_dir) + update_env_path([py_scripts_dir, qt_dir]) build_name = "py%s-qt%s-%s-%s" % \ (py_version, qt_version, platform.architecture()[0], build_type.lower()) @@ -175,7 +175,7 @@ def rmtree(dirname): shutil.rmtree(dirname, ignore_errors=False, onerror=handleRemoveReadonly) -def run_process(args, logger=None): +def run_process(args, logger=None, initial_env=None): def log(buffer, checkNewLine=False): endsWithNewLine = False if buffer.endswith('\n'): @@ -207,13 +207,16 @@ def run_process(args, logger=None): if sys.platform == "win32": shell = True + if initial_env is None: + initial_env = os.environ + proc = popenasync.Popen(args, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, universal_newlines = 1, shell = shell, - env = os.environ) + env = initial_env) log_buffer = None; while proc.poll() is None: @@ -263,6 +266,10 @@ def get_environment_from_batch_command(env_cmd, initial=None): proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial) # parse the output sent to stdout lines = proc.stdout + if sys.version_info[0] > 2: + # make sure the lines are strings + make_str = lambda s: s.decode() + lines = map(make_str, lines) # consume whatever output occurs until the tag is reached consume(itertools.takewhile(lambda l: tag not in l, lines)) # define a way to handle each KEY=VALUE line |