Mentions légales du service

Skip to content
Snippets Groups Projects
Commit e4309f51 authored by ADILI Robin's avatar ADILI Robin
Browse files

fbxsdkbuilder inherits from distutilbuilder

parent 9373e899
No related branches found
No related tags found
No related merge requests found
# Copyright (c) 2020, Riverbank Computing Limited from distutils.command.build_ext import build_ext
# All rights reserved. from distutils.dist import Distribution
# from distutils.extension import Extension
# This copy of SIP is licensed for use under the terms of the SIP License from distutils.log import ERROR, INFO, set_threshold
# Agreement. See the file LICENSE for more details.
# import os
# This copy of SIP may also used under the terms of the GNU General Public import sys
# License v2 or v3 as published by the Free Software Foundation which can be
# found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package. from sipbuild.buildable import BuildableModule
# from sipbuild.distutils_builder import DistutilsBuilder, ExtensionCommand
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" from sipbuild.exceptions import UserException
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE from sipbuild.installable import Installable
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR class FBXSDKBuilder(DistutilsBuilder):
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF """ Custom Builder for FBX SDK"""
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN def _build_extension_module(self, buildable):
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE project = self.project
# POSSIBILITY OF SUCH DAMAGE.
set_threshold(INFO if project.verbose else ERROR)
from distutils.command.build_ext import build_ext distribution = Distribution()
from distutils.dist import Distribution
from distutils.extension import Extension module_builder = ExtensionCommand(distribution, buildable)
from distutils.log import ERROR, INFO, set_threshold module_builder.build_lib = buildable.build_dir
module_builder.debug = buildable.debug
import os
import sys module_builder.ensure_finalized()
from sipbuild.buildable import BuildableModule define_macros = []
from sipbuild.builder import Builder for macro in buildable.define_macros:
from sipbuild.exceptions import UserException parts = macro.split("=", maxsplit=1)
from sipbuild.installable import Installable name = parts[0]
try:
value = parts[1]
class FBXSDKBuilder(Builder): except IndexError:
""" The implementation of a distutils-based project builder. """ value = None
def build_executable(self, buildable, *, fatal=True): define_macros.append((name, value))
""" Build an executable from a BuildableExecutable object and return
the relative pathname of the executable. buildable.make_names_relative()
"""
if sys.platform == "linux":
raise UserException("DistutilsBuilder cannot build executables") linux_static_libs = [
os.path.abspath(a) for a in project.linux_static_libraries
def build_project(self, target_dir, *, wheel_tag=None): ]
""" Build the project. """ extra_compile_args = ["-std=c++11"]
else:
for buildable in self.project.buildables: linux_static_libs = []
if isinstance(buildable, BuildableModule): extra_compile_args = []
if buildable.static:
raise UserException( module_builder.extensions = [
"DistutilsBuilder cannot build static modules") Extension(
buildable.fq_name,
self._build_extension_module(buildable) buildable.sources,
else: define_macros=define_macros,
raise UserException( include_dirs=buildable.include_dirs,
"DistutilsBuilder cannot build '{0}' buildables".format( libraries=buildable.libraries,
type(buildable).__name__)) library_dirs=buildable.library_dirs,
extra_link_args=linux_static_libs,
def install_project(self, target_dir, *, wheel_tag=None): extra_compile_args=extra_compile_args,
""" Install the project into a target directory. """ )
]
project = self.project
project.progress(
installed = [] "Compiling the '{0}' module".format(buildable.fq_name)
)
# Install any project-level installables.
for installable in project.installables: saved_cwd = os.getcwd()
installable.install(target_dir, installed) os.chdir(buildable.build_dir)
# Install any installables from built buildables. try:
for buildable in project.buildables: module_builder.run()
for installable in buildable.installables: except Exception as e:
installable.install(target_dir, installed) raise UserException(
"Unable to compile the '{0}' module".format(buildable.fq_name),
if project.distinfo: detail=str(e),
from sipbuild.distinfo import create_distinfo )
create_distinfo(project.get_distinfo_dir(target_dir), wheel_tag, installable = Installable(
installed, project.metadata, project.get_requires_dists(), "module", target_subdir=buildable.get_install_subdir()
project.root_dir, project.console_scripts, )
project.gui_scripts) installable.files.append(
module_builder.get_ext_fullpath(buildable.fq_name)
def _build_extension_module(self, buildable): )
""" Build an extension module from the sources. """ buildable.installables.append(installable)
project = self.project os.chdir(saved_cwd)
set_threshold(INFO if project.verbose else ERROR)
distribution = Distribution()
module_builder = ExtensionCommand(distribution, buildable)
module_builder.build_lib = buildable.build_dir
module_builder.debug = buildable.debug
if buildable.debug:
# Enable assert().
module_builder.undef = 'NDEBUG'
module_builder.ensure_finalized()
# Convert the #defines.
define_macros = []
for macro in buildable.define_macros:
parts = macro.split('=', maxsplit=1)
name = parts[0]
try:
value = parts[1]
except IndexError:
value = None
define_macros.append((name, value))
buildable.make_names_relative()
if sys.platform == "linux":
linux_static_libs = [ os.path.abspath(a) for a in project.linux_static_libraries ]
extra_compile_args = [ "-std=c++11" ]
else:
linux_static_libs = []
extra_compile_args = []
module_builder.extensions = [
Extension(buildable.fq_name, buildable.sources,
define_macros=define_macros,
include_dirs=buildable.include_dirs,
libraries=buildable.libraries,
library_dirs=buildable.library_dirs,
extra_link_args=linux_static_libs,
extra_compile_args=extra_compile_args)]
project.progress(
"Compiling the '{0}' module".format(buildable.fq_name))
saved_cwd = os.getcwd()
os.chdir(buildable.build_dir)
try:
module_builder.run()
except Exception as e:
raise UserException(
"Unable to compile the '{0}' module".format(
buildable.fq_name),
detail=str(e))
# Add the extension module to the buildable's list of installables.
installable = Installable('module',
target_subdir=buildable.get_install_subdir())
installable.files.append(
module_builder.get_ext_fullpath(buildable.fq_name))
buildable.installables.append(installable)
os.chdir(saved_cwd)
class ExtensionCommand(build_ext):
""" Extend the distutils command to build an extension module. """
def __init__(self, distribution, buildable):
""" Initialise the object. """
super().__init__(distribution)
self._buildable = buildable
def get_ext_filename(self, ext_name):
""" Reimplemented to handle modules that use the limited API. """
return os.path.join(*ext_name.split('.')) + self._buildable.get_module_extension()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment