📄 python.jam
字号:
if $(install-path) { install-path = [ windows-path-to-native $(install-path) ] ; debug-message Registry indicates Python $(v) installed at \"$(install-path)\" ; } interpreters += $(:E=python:R=$(install-path)) ; } return $(interpreters) ;}local rule darwin-installed-pythons ( version ? ){ version ?= $(.version-countdown) ; local prefix = [ GLOB /System/Library/Frameworks /Library/Frameworks : Python.framework ] ; return $(prefix)/Versions/$(version)/bin/python ;}# Assume "python-cmd" invokes a python interpreter and invoke it to extract all# the information we care about from its "sys" module. Returns void if# unsuccessful.#local rule probe ( python-cmd ){ # Avoid invoking a Cygwin symlink on NT. local skip-symlink ; if [ os.name ] = NT { skip-symlink = [ invokes-cygwin-symlink $(python-cmd) ] ; } if $(skip-symlink) { debug-message -------------------------------------------------------------------- ; debug-message \"$(python-cmd)\" would attempt to invoke a Cygwin symlink, ; debug-message causing a bjam built for Windows to hang. ; debug-message ; debug-message If you intend to target a Cygwin build of Python, please ; debug-message replace the path to the link with the path to a real executable ; debug-message (guessing: \"$(skip-symlink)\") "in" your 'using python' line ; debug-message "in" user-config.jam or site-config.jam. Do not forget to escape ; debug-message backslashes ; debug-message -------------------------------------------------------------------- ; } else { # Prepare a List of Python format strings and expressions that can be # used to print the constants we want from the sys module. # We do not really want sys.version since that is a complicated string, # so get the information from sys.version_info instead. local format = "version=%d.%d" ; local exprs = "version_info[0]" "version_info[1]" ; for local s in $(sys-elements[2-]) { format += $(s)=%s ; exprs += $(s) ; } # Invoke Python and ask it for all those values. if [ version.check-jam-version 3 1 17 ] || ( [ os.name ] != NT ) { # Prior to version 3.1.17 Boost Jam's SHELL command did not support # quoted commands correctly on Windows. This means that on that # platform we do not support using a Python command interpreter # executable whose path contains a space character. python-cmd = \"$(python-cmd)\" ; } local full-cmd = $(python-cmd)" -c \"from sys import *; print '"$(format:J=\\n)"' % ("$(exprs:J=,)")\"" ; local output = [ shell-cmd $(full-cmd) ] ; if $(output) { # Parse the output to get all the results. local nl = "" ; for s in $(sys-elements) { # These variables are expected to be declared local in the # caller, so Jam's dynamic scoping will set their values there. sys.$(s) = [ SUBST $(output) \\<$(s)=([^$(nl)]+) $1 ] ; } } return $(output) ; }}# Make sure the "libraries" and "includes" variables (in an enclosing scope)# have a value based on the information given.#local rule compute-default-paths ( target-os : version ? : prefix ? : exec-prefix ? ){ exec-prefix ?= $(prefix) ; if $(target-os) = windows { # The exec_prefix is where you're supposed to look for machine-specific # libraries. local default-library-path = $(exec-prefix)\\libs ; local default-include-path = $(:E=Include:R=$(prefix)) ; # If the interpreter was found in a directory called "PCBuild" or # "PCBuild8," assume we're looking at a Python built from the source # distro, and go up one additional level to the default root. Otherwise, # the default root is the directory where the interpreter was found. # We ask Python itself what the executable path is in case of # intermediate symlinks or shell scripts. local executable-dir = $(sys.executable:D) ; if [ MATCH ^(PCBuild) : $(executable-dir:D=) ] { debug-message "This Python appears to reside in a source distribution;" ; debug-message "prepending \""$(executable-dir)"\" to default library search path" ; default-library-path = $(executable-dir) $(default-library-path) ; default-include-path = $(:E=PC:R=$(executable-dir:D)) $(default-include-path) ; debug-message "and \""$(default-include-path[1])"\" to default #include path" ; } libraries ?= $(default-library-path) ; includes ?= $(default-include-path) ; } else { includes ?= $(prefix)/include/python$(version) ; local lib = $(exec-prefix)/lib ; libraries ?= $(lib)/python$(version)/config $(lib) ; }}# The version of the python interpreter to use.feature.feature python : : propagated ;feature.feature python.interpreter : : free ;toolset.flags python.capture-output PYTHON : <python.interpreter> ;## Support for Python configured --with-pydebug#feature.feature python-debugging : off on : propagated ;builtin.variant debug-python : debug : <python-debugging>on ;# Return a list of candidate commands to try when looking for a Python# interpreter. prefix is expected to be a native path.#local rule candidate-interpreters ( version ? : prefix ? : target-os ){ local bin-path = bin ; if $(target-os) = windows { # On Windows, look in the root directory itself and, to work with the # result of a build-from-source, the PCBuild directory. bin-path = PCBuild8 PCBuild "" ; } bin-path = $(bin-path:R=$(prefix)) ; if $(target-os) in windows darwin { return # Search: $(:E=python:R=$(bin-path)) # Relative to the prefix, if any python # In the PATH [ $(target-os)-installed-pythons $(version) ] # Standard install locations ; } else { # Search relative to the prefix, or if none supplied, in PATH. local unversioned = $(:E=python:R=$(bin-path:E=)) ; # If a version was specified, look for a python with that specific # version appended before looking for one called, simply, "python" return $(unversioned)$(version) $(unversioned) ; }}# Compute system library dependencies for targets linking with static Python# libraries.## On many systems, Python uses libraries such as pthreads or libdl. Since static# libraries carry no library dependency information of their own that the linker# can extract, these extra dependencies have to be given explicitly on the link# line of the client. The information about these dependencies is packaged into# the "python" target below.## Even where Python itself uses pthreads, it never allows extension modules to# be entered concurrently (unless they explicitly give up the interpreter lock).# Therefore, extension modules do not need the efficiency overhead of threadsafe# code as produced by <threading>multi, and we handle libpthread along with# other libraries here. Note: this optimization is based on an assumption that# the compiler generates link-compatible code in both the single- and# multi-threaded cases, and that system libraries do not change their ABIs# either.## Returns a list of usage-requirements that link to the necessary system# libraries.#local rule system-library-dependencies ( target-os ){ switch $(target-os) { case s[uo][nl]* : # solaris, sun, sunos # Add a librt dependency for the gcc toolset on SunOS (the sun # toolset adds -lrt unconditionally). While this appears to # duplicate the logic already in gcc.jam, it does not as long as # we are not forcing <threading>multi. # On solaris 10, distutils.sysconfig.get_config_var('LIBS') yields # '-lresolv -lsocket -lnsl -lrt -ldl'. However, that does not seem # to be the right list for extension modules. For example, on my # installation, adding -ldl causes at least one test to fail because # the library can not be found and removing it causes no failures. # Apparently, though, we need to add -lrt for gcc. return <toolset>gcc:<library>rt ; case osf : return <library>pthread <toolset>gcc:<library>rt ; case qnx* : return ; case darwin : return ; case windows : return ; case hpux : return <library>rt ; case *bsd : return <library>pthread <toolset>gcc:<library>util ; case aix : return <library>pthread <library>dl ; case * : return <library>pthread <library>dl <toolset>gcc:<library>util ; }}# Declare a target to represent Python's library.#local rule declare-libpython-target ( version ? : requirements * ){ # Compute the representation of Python version in the name of Python's # library file. local lib-version = $(version) ; if <target-os>windows in $(requirements) { local major-minor = [ split-version $(version) ] ; lib-version = $(major-minor:J="") ; if <python-debugging>on in $(requirements) { lib-version = $(lib-version)_d ; } } if ! $(lib-version) { ECHO *** warning: could not determine Python version, which will ; ECHO *** warning: probably prevent us from linking with the python ; ECHO *** warning: library. Consider explicitly passing the version ; ECHO *** warning: to 'using python'. ; } # Declare it. lib python.lib : : <name>python$(lib-version) $(requirements) ;}# Implementation of init.local rule configure ( version ? : cmd-or-prefix ? : includes * : libraries ? : condition * : extension-suffix ? ){ local prefix ; local exec-prefix ; local cmds-to-try ; local interpreter-cmd ; local target-os = [ feature.get-values target-os : $(condition) ] ; target-os ?= [ feature.defaults target-os ] ; target-os = $(target-os:G=) ; if $(target-os) = windows && <python-debugging>on in $(condition) { extension-suffix ?= _d ; } extension-suffix ?= "" ; # Normalize and dissect any version number. local major-minor ; if $(version) { major-minor = [ split-version $(version) ] ; version = $(major-minor:J=.) ; } local cmds-to-try ; if ! $(cmd-or-prefix) || [ GLOB $(cmd-or-prefix) : * ] { # If the user did not pass a command, whatever we got was a prefix. prefix = $(cmd-or-prefix) ; cmds-to-try = [ candidate-interpreters $(version) : $(prefix) : $(target-os) ] ; } else { # Work with the command the user gave us. cmds-to-try = $(cmd-or-prefix) ; # On Windows, do not nail down the interpreter command just yet in case # the user specified something that turns out to be a cygwin symlink, # which could bring down bjam if we invoke it. if $(target-os) != windows { interpreter-cmd = $(cmd-or-prefix) ; } } # Values to use in case we can not really find anything in the system. local fallback-cmd = $(cmds-to-try[1]) ; local fallback-version ; # Anything left to find or check? if ! ( $(interpreter-cmd) && $(includes) && $(libraries) ) { # Values to be extracted from python's sys module. These will be set by # the probe rule, above, using Jam's dynamic scoping. local sys-elements = version platform prefix exec_prefix executable ; local sys.$(sys-elements) ; # Compute the string Python's sys.platform needs to match. If not # targeting Windows or cygwin we will assume only native builds can # possibly run, so we will not require a match and we leave sys.platform # blank. local platform ; switch $(target-os) { case windows : platform = win32 ; case cygwin : platform = cygwin ; } while $(cmds-to-try) { # Pop top command. local cmd = $(cmds-to-try[1]) ; cmds-to-try = $(cmds-to-try[2-]) ; debug-message Checking interpreter command \"$(cmd)\"... ; if [ probe $(cmd) ] { fallback-version ?= $(sys.version) ; # Check for version/platform validity. for local x in version platform { if $($(x)) && $($(x)) != $(sys.$(x)) { debug-message ...$(x) "mismatch (looking for" $($(x)) but found $(sys.$(x))")" ; cmd = ; } } if $(cmd) { debug-message ...requested configuration matched! ; exec-prefix = $(sys.exec_prefix) ; compute-default-paths $(target-os) : $(sys.version) : $(sys.prefix) : $(sys.exec_prefix) ; version = $(sys.version) ; interpreter-cmd ?= $(cmd) ; cmds-to-try = ; # All done. } } else { debug-message ...does not invoke a working interpreter ; } } } # Anything left to compute? if $(includes) && $(libraries) { .configured = true ; } else { version ?= $(fallback-version) ; version ?= 2.5 ; exec-prefix ?= $(prefix) ; compute-default-paths $(target-os) : $(version) : $(prefix:E=) ; } if ! $(interpreter-cmd) { fallback-cmd ?= python ; debug-message No working Python interpreter found. ; if [ os.name ] != NT || ! [ invokes-cygwin-symlink $(fallback-cmd) ]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -