Exemple #1
0
    def sh_configure(
        self,
        build: targets.Build,
        path: str | pathlib.Path,
        args: Mapping[str, str | pathlib.Path | None],
    ) -> str:
        conf_args = dict(args)
        shlib_paths = self.get_shlib_paths(build)
        ldflags = []
        for shlib_path in shlib_paths:
            ldflags.extend(
                build.target.get_shlib_path_run_time_ldflags(
                    build, shlex.quote(str(shlib_path))
                )
            )
        if ldflags:
            build.sh_append_flags(conf_args, "LDFLAGS", ldflags)

        if "--prefix" not in args:
            conf_args["--prefix"] = str(build.get_full_install_prefix())

        conf_args = build.sh_append_global_flags(conf_args)
        return build.sh_format_command(path, conf_args, force_args_eq=True)
Exemple #2
0
    def get_configure_script(self, build: targets.Build) -> str:
        extra_version = ""

        system = platform.system()
        if system.endswith("BSD"):
            uuid_lib = "bsd"
        elif system == "Linux" or system == "Darwin":
            # macOS actually ships the e2fs version despite being a "BSD"
            uuid_lib = "e2fs"
        else:
            raise NotImplementedError(f"unsupported target system: {system}")

        sdir = build.get_source_dir(self, relative_to="pkgbuild")
        configure = sdir / "configure"

        configure_flags: dict[str, str | pathlib.Path | None] = {
            "--sysconfdir": build.get_install_path("sysconf"),
            "--datarootdir": build.get_install_path("data"),
            "--bindir": build.get_install_path("bin"),
            "--libdir": build.get_install_path("lib"),
            "--includedir": build.get_install_path("include"),
            "--with-extra-version": extra_version,
            "--with-icu": None,
            "--without-pam": None,
            "--without-zlib": None,
            "--with-openssl": None,
            "--with-uuid": uuid_lib,
            "--without-readline": None,
        }

        icu_pkg = build.get_package("icu")
        if build.is_bundled(icu_pkg):
            icu_path = build.get_install_dir(icu_pkg, relative_to="pkgbuild")
            icu_path /= build.get_full_install_prefix().relative_to("/")
            icu_rel_path = f'$(pwd)/"{icu_path}"'
            configure_flags["ICU_CFLAGS"] = f"!-I{icu_rel_path}/include/"
            icu_ldflags = build.sh_get_bundled_shlib_ldflags(
                icu_pkg, relative_to="pkgbuild")
            configure_flags["ICU_LIBS"] = f"!{icu_ldflags}"

        uuid_pkg = build.get_package("uuid")
        if build.is_bundled(uuid_pkg):
            uuid_path = build.get_install_dir(uuid_pkg, relative_to="pkgbuild")
            uuid_path /= build.get_full_install_prefix().relative_to("/")
            uuid_rel_path = f'$(pwd)/"{uuid_path}"'
            configure_flags["UUID_CFLAGS"] = f"!-I{uuid_rel_path}/include/"
            uuid_ldflags = build.sh_get_bundled_shlib_ldflags(
                uuid_pkg, relative_to="pkgbuild")
            configure_flags["UUID_LIBS"] = f"!{uuid_ldflags}"

        openssl_pkg = build.get_package("openssl")
        if build.is_bundled(openssl_pkg):
            openssl_root = build.get_install_dir(openssl_pkg,
                                                 relative_to="pkgbuild")
            openssl_path = (openssl_root /
                            build.get_full_install_prefix().relative_to("/"))
            openssl_rel_path = f'$(pwd)/"{openssl_path}"'
            configure_flags[
                "OPENSSL_CFLAGS"] = f"!-I{openssl_rel_path}/include/"
            openssl_ldflags = build.sh_get_bundled_shlib_ldflags(
                openssl_pkg, relative_to="pkgbuild")
            configure_flags["OPENSSL_LIBS"] = f"!{openssl_ldflags}"

            ldflags = f"!-L{openssl_rel_path}/lib"

            if system == "Darwin":
                # ./configure tries to compile and test a program
                # and it fails because openssl is not yet installed
                # at its install_name location.
                configure_flags["DYLD_FALLBACK_LIBRARY_PATH"] = openssl_root
            else:
                ldflags += f'" "-Wl,-rpath-link,{openssl_rel_path}/lib'

            configure_flags["LDFLAGS"] = ldflags

        if build.target.has_capability("tzdata"):
            zoneinfo = build.target.get_resource_path(build, "tzdata")
            configure_flags["--with-system-tzdata"] = zoneinfo

        if build.target.has_capability("systemd"):
            configure_flags["--with-systemd"] = None

        if (build.extra_optimizations_enabled() and build.supports_lto()
                and build.uses_modern_gcc()):
            build.sh_append_flags(
                configure_flags,
                "CFLAGS",
                (
                    "-flto",
                    "-fuse-linker-plugin",
                    "-ffat-lto-objects",
                    "-flto-partition=none",
                ),
            )

        return self.sh_configure(build, configure, configure_flags)
Exemple #3
0
    def get_configure_script(self, build: targets.Build) -> str:
        sdir = build.get_source_dir(self, relative_to="pkgbuild")

        configure = sdir / "configure"

        configure_flags = {
            "--prefix": build.get_full_install_prefix(),
            "--sysconfdir": build.get_install_path("sysconf"),
            "--datarootdir": build.get_install_path("data"),
            "--bindir": build.get_install_path("bin"),
            "--libdir": build.get_install_path("lib"),
            "--includedir": build.get_install_path("include"),
            "--enable-ipv6": None,
            "--with-dbmliborder": "bdb:gdbm",
            "--with-computed-gotos": None,
        }

        if build.extra_optimizations_enabled():
            if build.supports_pgo():
                configure_flags["--enable-optimizations"] = None
            if build.supports_lto():
                configure_flags["--with-lto"] = None
            if build.uses_modern_gcc():
                build.sh_append_flags(
                    configure_flags,
                    "CFLAGS",
                    (
                        "-fgraphite-identity",
                        "-floop-nest-optimize",
                        "-fipa-pta",
                        "-fno-semantic-interposition",
                    ),
                )

        libffi_pkg = build.get_package("libffi")
        if build.is_bundled(libffi_pkg):
            libffi_path = build.get_install_dir(libffi_pkg,
                                                relative_to="pkgbuild")
            libffi_path /= build.get_full_install_prefix().relative_to("/")
            libffi_rel_path = f'$(pwd)/"{libffi_path}"'
            configure_flags["LIBFFI_CFLAGS"] = f"!-I{libffi_rel_path}/include/"
            libffi_ldflags = build.sh_get_bundled_shlib_ldflags(
                libffi_pkg, relative_to="pkgbuild")
            configure_flags["LIBFFI_LIBS"] = f"!{libffi_ldflags}"
        else:
            configure_flags["--with-system-ffi"] = None

        if platform.system() == "Darwin":
            configure_flags[
                "--enable-universalsdk"] = "!$(xcrun --show-sdk-path)"
            configure_flags["--with-universal-archs"] = "intel-64"

        openssl_pkg = build.get_package("openssl")
        if build.is_bundled(openssl_pkg):
            openssl_path = build.get_install_dir(openssl_pkg,
                                                 relative_to="pkgbuild")
            openssl_path /= build.get_full_install_prefix().relative_to("/")
            configure_flags["--with-openssl"] = openssl_path
            configure_flags[
                "--with-openssl-rpath"] = openssl_pkg.get_shlib_paths(build)[0]

        uuid_pkg = build.get_package("uuid")
        if build.is_bundled(uuid_pkg):
            uuid_path = build.get_install_dir(uuid_pkg, relative_to="pkgbuild")
            uuid_path /= build.get_full_install_prefix().relative_to("/")
            uuid_rel_path = f'$(pwd)/"{uuid_path}"'
            configure_flags["UUID_CFLAGS"] = f"!-I{uuid_rel_path}/include/"
            uuid_ldflags = build.sh_get_bundled_shlib_ldflags(
                uuid_pkg, relative_to="pkgbuild")
            configure_flags["UUID_LIBS"] = f"!{uuid_ldflags}"

        zlib_pkg = build.get_package("zlib")
        if build.is_bundled(zlib_pkg):
            zlib_path = build.get_install_dir(zlib_pkg, relative_to="pkgbuild")
            zlib_path /= build.get_full_install_prefix().relative_to("/")
            zlib_rel_path = f'$(pwd)/"{zlib_path}"'
            configure_flags["ZLIB_CFLAGS"] = f"!-I{zlib_rel_path}/include/"
            zlib_ldflags = build.sh_get_bundled_shlib_ldflags(
                zlib_pkg, relative_to="pkgbuild")
            configure_flags["ZLIB_LIBS"] = f"!{zlib_ldflags}"

        return build.sh_configure(configure, configure_flags)
Exemple #4
0
    def get_build_script(self, build: targets.Build) -> str:
        sdir = build.get_source_dir(self, relative_to="pkgbuild")
        src_python = build.sh_get_command("python",
                                          package=self,
                                          relative_to="pkgsource")
        build_python = build.sh_get_command("python")
        dest = build.get_temp_root(
            relative_to="pkgbuild") / build.get_full_install_prefix(
            ).relative_to("/")

        sitescript = (f"import site; "
                      f'print(site.getsitepackages(["{dest}"])[0])')

        src_dest = build.get_temp_root(
            relative_to="pkgsource") / build.get_full_install_prefix(
            ).relative_to("/")

        src_sitescript = (f"import site; "
                          f'print(site.getsitepackages(["{src_dest}"])[0])')

        wheeldir_script = 'import pathlib; print(pathlib.Path(".").resolve())'

        abspath = (
            "import pathlib, sys; print(pathlib.Path(sys.argv[1]).resolve())")

        pkgname = getattr(self, "dist_name", None)
        if pkgname is None:
            pkgname = self.name
            if pkgname.startswith("pypkg-"):
                pkgname = pkgname[len("pypkg-"):]

        env = build.sh_append_global_flags({
            "SETUPTOOLS_SCM_PRETEND_VERSION":
            self.pretty_version,
            "PIP_DISABLE_PIP_VERSION_CHECK":
            "1",
        })

        dep_names = [dep.name for dep in self.build_requires]
        build_deps = build.get_packages(dep_names)

        if pkgname == "wheel":
            build_command = f'"{src_python}" setup.py sdist -d ${{_wheeldir}}'
            binary = False
        else:
            args = [
                src_python,
                "-m",
                "pip",
                "wheel",
                "--verbose",
                "--wheel-dir",
                "${_wheeldir}",
                "--no-binary=:all:",
                "--no-build-isolation",
                "--use-feature=in-tree-build",
                "--no-deps",
                ".",
            ]
            build_command = " ".join(
                shlex.quote(c) if c[0] != "$" else c for c in args)
            env.update(
                self.sh_get_build_wheel_env(
                    build, site_packages_var="${_sitepkg_from_src}"))

            cflags = build.sh_get_bundled_shlibs_cflags(
                build_deps,
                relative_to="pkgsource",
            )

            if cflags:
                build.sh_append_flags(env, "CFLAGS", cflags)

            ldflags = build.sh_get_bundled_shlibs_ldflags(
                build_deps,
                relative_to="pkgsource",
            )

            if ldflags:
                build.sh_append_flags(env, "LDFLAGS", ldflags)

            binary = True

        all_build_deps = build.get_packages(dep_names, recursive=True)
        env_str = build.sh_format_command("env", env, force_args_eq=True)
        env_str += " " + " ".join(build.get_ld_env(all_build_deps, "${_wd}"))

        return textwrap.dedent(f"""\
            _wheeldir=$("{build_python}" -c '{wheeldir_script}')
            _target=$("{build_python}" -c '{sitescript}')
            _sitepkg_from_src=$("{build_python}" -c '{src_sitescript}')
            _wd=$("{build_python}" -c '{abspath}' "$(pwd)")
            (cd "{sdir}"; \\
             {env_str} \\
                 {build_command})
            "{build_python}" -m pip install \\
                --no-build-isolation \\
                --no-warn-script-location \\
                --no-index \\
                --no-deps \\
                --upgrade \\
                -f "file://${{_wheeldir}}" \\
                {'--only-binary' if binary else '--no-binary'} :all: \\
                --target "${{_target}}" \\
                "{pkgname}"
        """)