def _fix_subdir_sip(self, buildable, sip_installable): subdirs = ["ksoapi", "wpsapiex"] for subdir in subdirs: sub_installable = sipbuild.Installable( "sip_" + subdir, target_subdir=sip_installable.target_subdir + "/" + subdir) sub_path = "/" + subdir + "/" sub_installable.files = [ f for f in sip_installable.files if sub_path in f] sip_installable.files = [f for f in sip_installable.files if f not in sub_installable.files] buildable.installables.append(sub_installable)
def _gen_module_pro_file(self, buildable, target_dir, installed): self.project.progress("Generating the %s project" % buildable.target) with open(buildable.build_dir + "/" + buildable.target + ".pro", "w+") as f: f.write("TEMPLATE = lib\n") f.write("CONFIG += plugin no_plugin_name_prefix warn_off\n") f.write("CONFIG += %s\n" % ("debug" if buildable.debug else "release")) f.write("CONFIG += c++11 precompile_header\n") f.write("%s\n" % ' '.join(buildable.builder_settings)) f.write("TARGET = %s\n\n" % buildable.target) if buildable.define_macros: f.write("DEFINES += %s\n" % ' '.join(buildable.define_macros)) f.write("INCLUDEPATH += .\n") for dir in buildable.include_dirs: f.write("INCLUDEPATH += %s\n" % dir) f.write("INCLUDEPATH += %s\n\n" % self.project.py_include_dir) for dir in buildable.library_dirs: f.write("LIBS += -L%s\n" % dir) for lib in buildable.libraries: f.write("LIBS += -l%s\n" % lib) f.write('\n') # hidden symbols with open(buildable.build_dir + "/" + buildable.target + ".exp", "w+") as exp: exp.write("{ global: PyInit_%s; local: *; };" % buildable.target) f.write("QMAKE_LFLAGS += -Wl,--version-script=%s.exp\n" % buildable.target) if not buildable.debug: f.write("QMAKE_LFLAGS += -s\n") #f.write("QMAKE_LFLAGS_PLUGIN += -Wl,--no-undefined\n") f.write( "QMAKE_CXXFLAGS += -Wno-attributes -Wno-delete-non-virtual-dtor\n" ) f.write( "QMAKE_CXXFLAGS += -Wno-delete-incomplete -Wno-unused-variable\n" ) f.write( "QMAKE_RPATHDIR += $ORIGIN /opt/kingsoft/wps-office/office6\n") f.write("QMAKE_RPATHDIR += /usr/lib/office6\n\n") # for testing rpc_dir = os.path.join(self.project.build_dir, self.project.name) os.makedirs(rpc_dir, exist_ok=True) f.write("QMAKE_POST_LINK = $(COPY_FILE) $(TARGET) %s\n\n" % rpc_dir) f.write("PRECOMPILED_HEADER = stdafx.h\n\n") f.write("HEADERS = %s\n" % " \\\n\t".join(buildable.headers)) f.write("SOURCES = %s" % " \\\n\t".join(buildable.sources)) f.write('\n\n') f.write("target.path = %s\n" % (target_dir + "/" + self.project.name)) f.write("INSTALLS += target\n\n") # for dist-info target_installable = sipbuild.Installable( "target", target_subdir=buildable.get_install_subdir()) installed.append( target_installable.get_full_target_dir(target_dir) + "/%s.so" % buildable.target) for installable in buildable.installables: self._install(f, installable, target_dir, installed)
def build_project(self, target_dir, *, wheel_tag=None): installed = [] sub_dirs = [] for buildable in self.project.buildables: if isinstance(buildable, sipbuild.BuildableModule): self._gen_module_pro_file(buildable, target_dir, installed) elif type(buildable) is sipbuild.Buildable: for installable in buildable.installables: installable.install(target_dir, installed, do_install=False) else: raise sipbuild.UserException( "RpcApiBuilder cannot build '{0}' buildables".format( type(buildable).__name__)) sub_dirs.append(buildable.name) self._gen_sip_project(target_dir, sub_dirs, installed) self.project.progress("Generating the top-level project") with open(self.project.build_dir + "/" + self.project.name + ".pro", "w+") as f: f.write("TEMPLATE = subdirs\n") f.write("CONFIG += ordered\n\n") f.write("SUBDIRS = %s\n\n" % ' '.join(sub_dirs)) for installable in self.project.installables: self._install(f, installable, target_dir, installed) py_subdir = os.path.join(target_dir, self.project.name) sip_py = sipbuild.Installable("sip_py", target_subdir=py_subdir) py_dir = os.path.join(self.project.root_dir, "py") sip_py_files = [(py_dir + "/" + f) for f in os.listdir(py_dir) if f.endswith(".py") and f != "__init__.py"] sip_py.files.extend(sip_py_files) self._install(f, sip_py, target_dir, installed) fake_root = os.path.join(self.project.build_dir, self.project.name) for py in sip_py.files: shutil.copy(py, fake_root) shutil.copy(os.path.join(py_dir, "__init__.py"), fake_root) # for distinfo inventory_file = self.project.build_dir + "/inventory.txt" with open(inventory_file, "w+") as inventory: inventory.write('\n'.join(installed)) inventory.write('\n') distinfo = [ "sip-distinfo", "--project-root", self.project.root_dir, "--generator", os.path.basename(sys.argv[0]), "--prefix", '\\"$(INSTALL_ROOT)\\"', "--inventory", inventory_file ] if wheel_tag: distinfo.append("--wheel-tag") distinfo.append(wheel_tag) distinfo.append(self.project.get_distinfo_dir(target_dir)) f.write("distinfo.extra = %s\n" % ' '.join(distinfo)) f.write("distinfo.path = %s\n" % target_dir) f.write("INSTALLS += distinfo\n") old_dir = os.getcwd() os.chdir(self.project.build_dir) self.project.run_command( [self.qmake, "-recursive", self.project.name + ".pro"], fatal=True) self.project.progress("Compiling the project") self._run_make() os.chdir(old_dir)