示例#1
0
 def _get_make_env(self, build: targets.Build, wd: str) -> str:
     openssl_pkg = build.get_package("openssl")
     libffi_pkg = build.get_package("libffi")
     uuid_pkg = build.get_package("uuid")
     zlib_pkg = build.get_package("zlib")
     env = build.get_ld_env([openssl_pkg, libffi_pkg, uuid_pkg, zlib_pkg],
                            wd)
     return " ".join(env)
示例#2
0
    def get_build_install_script(self, build: targets.Build) -> str:
        script = super().get_build_install_script(build)
        srcdir = build.get_source_dir(self, relative_to="pkgbuild")
        dest = build.get_install_dir(self, relative_to="pkgbuild")

        datadir = build.get_install_path("data")
        script += textwrap.dedent(f"""\
            mkdir -p "{dest}/{datadir}"
            cp -a "{srcdir}/tests" "{dest}/{datadir}"
            mkdir -p "{dest}/{datadir}/data/"
            cp -a ./share/* "{dest}/{datadir}/data/"
            chmod 644 "{dest}/{datadir}/data/"*
            """)

        if build.target.is_portable():
            bindir = build.get_install_path("bin").relative_to("/")

            ep_helper_pkg = build.get_package("pyentrypoint")
            ep_helper = (
                build.get_temp_dir(ep_helper_pkg, relative_to="pkgbuild") /
                "bin" / "pyentrypoint")

            script += textwrap.dedent(f"""\
                for p in "{dest}/{bindir}"/*; do
                    if [ -f "$p" ]; then
                        mv "$p" "${{p}}.py"
                        cp "{ep_helper}" "$p"
                    fi
                done
                """)

        return script
示例#3
0
    def get_build_install_script(self, build: targets.Build) -> str:
        script = super().get_build_install_script(build)
        installdest = build.get_install_dir(self, relative_to="pkgbuild")
        make = build.sh_get_command("make")

        openssl_pkg = build.get_package("openssl")
        if build.is_bundled(openssl_pkg):
            # We must bundle the CA certificates if OpenSSL is bundled.
            python = build.sh_get_command("python", package=self)
            temp = build.get_temp_root(relative_to="pkgbuild")
            sslpath = ("import ssl; "
                       "print(ssl.get_default_verify_paths().openssl_cafile)")
            certifipath = "import certifi; " "print(certifi.where())"
            extra_install = textwrap.dedent(f"""\
                "{python}" -m pip install \\
                    --upgrade --force-reinstall \\
                    --root "{temp}" "certifi"
                sslpath=$("{python}" -c "{sslpath}")
                ssl_instpath="$(pwd)/{installdest}/${{sslpath}}"
                mkdir -p "$(dirname ${{ssl_instpath}})"
                certifipath=$("{python}" -c "{certifipath}")
                cp "${{certifipath}}" "${{ssl_instpath}}"
                """)
        else:
            extra_install = ""

        env = self._get_make_env(build, "$(pwd)")

        script += textwrap.dedent(f"""\
            {make} -j1 DESTDIR=$(pwd)/"{installdest}" {env} \
                ENSUREPIP=no install
            {extra_install}
            """)

        return script
示例#4
0
    def get_install_list_script(self, build: targets.Build) -> str:
        script = super().get_install_list_script(build)
        openssl_pkg = build.get_package("openssl")
        python = build.sh_get_command("python", package=self)
        if build.is_bundled(openssl_pkg):
            sslpath = ("import ssl; "
                       "print(ssl.get_default_verify_paths().openssl_cafile)")
            script += f'\n"{python}" -c "{sslpath}"'

        return script
示例#5
0
    def get_build_script(self, build: targets.Build) -> str:
        # Run edgedb-server --bootstrap to produce stdlib cache
        # for the benefit of faster bootstrap in the package.
        common_script = super().get_build_script(build)

        pg_pkg = build.get_package("postgresql-edgedb")
        icu_pkg = build.get_package("icu")
        openssl_pkg = build.get_package("openssl")
        uuid_pkg = build.get_package("uuid")

        build_python = build.sh_get_command("python")
        temp_dir = build.get_temp_dir(self, relative_to="pkgbuild")
        cachedir = temp_dir / "_datacache"
        pg_temp_install_path = (
            build.get_build_dir(pg_pkg, relative_to="pkgbuild") / "_install")
        bindir = build.get_install_path("bin").relative_to("/")
        libdir = build.get_install_path("lib").relative_to("/")
        pg_config = pg_temp_install_path / bindir / "pg_config"
        pg_libpath = pg_temp_install_path / libdir

        temp_install_dir = build.get_temp_root(
            relative_to="pkgbuild") / build.get_full_install_prefix(
            ).relative_to("/")
        sitescript = (
            f"import site; "
            f'print(site.getsitepackages(["{temp_install_dir}"])[0])')
        runstatescript = "import tempfile; " "print(tempfile.mkdtemp())"
        abspath = (
            "import pathlib, sys; print(pathlib.Path(sys.argv[1]).resolve())")

        ld_env = " ".join(
            build.get_ld_env(
                deps=[icu_pkg, openssl_pkg, uuid_pkg],
                wd="${_wd}",
                extra=["${_ldlibpath}"],
            ))

        if platform.system() == "Darwin":
            # Workaround SIP madness on macOS and allow popen() calls
            # in postgres to inherit DYLD_LIBRARY_PATH.
            extraenv = "PGOVERRIDESTDSHELL=1"
        else:
            extraenv = ""

        data_cache_script = textwrap.dedent(f"""\
            mkdir -p "{cachedir}"
            _tempdir=$("{build_python}" -c '{runstatescript}')
            if [ "$(whoami)" = "root" ]; then
                chown nobody "{cachedir}"
                chown nobody "${{_tempdir}}"
                _sudo="sudo -u nobody"
            else
                _sudo=""
            fi
            _pythonpath=$("{build_python}" -c '{sitescript}')
            _pythonpath=$("{build_python}" -c '{abspath}' "${{_pythonpath}}")
            _cachedir=$("{build_python}" -c '{abspath}' "{cachedir}")
            _pg_config=$("{build_python}" -c '{abspath}' "{pg_config}")
            _ldlibpath=$("{build_python}" -c '{abspath}' "{pg_libpath}")
            _build_python=$("{build_python}" -c '{abspath}' "{build_python}")
            _wd=$("{build_python}" -c '{abspath}' "$(pwd)")

            (
                cd ../;
                ${{_sudo}} env \\
                    {ld_env} {extraenv} \\
                    PYTHONPATH="${{_pythonpath}}" \\
                    _EDGEDB_BUILDMETA_PG_CONFIG_PATH="${{_pg_config}}" \\
                    _EDGEDB_WRITE_DATA_CACHE_TO="${{_cachedir}}" \\
                    "${{_build_python}}" \\
                        -m edb.server.main \\
                        --data-dir="${{_tempdir}}" \\
                        --runstate-dir="${{_tempdir}}" \\
                        --bootstrap-only
                    rm -rf "${{_tempdir}}"
            )

            mkdir ./share/
            cp "${{_cachedir}}"/* ./share/
            pwd
            ls -al ./share/
        """)

        return f"{common_script}\n{data_cache_script}"
示例#6
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)
示例#7
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)