Exemple #1
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
Exemple #2
0
    def sh_get_build_wheel_env(self, build: targets.Build, *,
                               site_packages_var: str) -> dict[str, str]:
        env = dict(super().sh_get_build_wheel_env(
            build, site_packages_var=site_packages_var))
        bindir = build.get_install_path("bin").relative_to("/")
        if build.target.is_portable():
            runstate = ""
        else:
            runstate = str(build.get_install_path("runstate") / "edgedb")
        shared_dir = (build.get_install_path("data") / "data").relative_to("/")
        temp_root = build.get_temp_root(relative_to="pkgsource")
        src_python = build.sh_get_command("python",
                                          package=self,
                                          relative_to="pkgsource")
        rel_bindir_script = ";".join((
            "import os.path",
            "rp = os.path.relpath",
            f"sp = rp('{site_packages_var}', start='{temp_root}')",
            f"print(rp('{bindir}', start=os.path.join(sp, 'edb')))",
        ))

        pg_config = f'!"$("{src_python}" -c "{rel_bindir_script}")"/pg_config'

        rel_datadir_script = ";".join((
            "import os.path",
            "rp = os.path.relpath",
            f"sp = rp('{site_packages_var}', start='{temp_root}')",
            f"print(rp('{shared_dir}', start=os.path.join(sp, 'edb')))",
        ))

        data_dir = f'!"$("{src_python}" -c "{rel_datadir_script}")"'

        env["EDGEDB_BUILD_PG_CONFIG"] = pg_config
        env["EDGEDB_BUILD_RUNSTATEDIR"] = runstate
        env["EDGEDB_BUILD_SHARED_DIR"] = data_dir

        return env
Exemple #3
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}"
Exemple #4
0
    def get_build_script(self, build: targets.Build) -> str:
        make = build.sh_get_command("make")

        prefix = build.get_full_install_prefix().relative_to("/")
        dest = build.get_temp_root(relative_to="pkgbuild")

        if platform.system() == "Darwin":
            exe_suffix = ".exe"
        else:
            exe_suffix = ""

        sitescript = (f"import site; import pathlib; "
                      f"print(pathlib.Path( "
                      f'site.getsitepackages([\\"${{p}}\\"])[0]).resolve())')

        python = f"python{exe_suffix}"

        wrapper_env = self._get_make_env(build, "${d}")
        bash = build.sh_get_command("bash")

        make_wrapper = textwrap.dedent(f"""\
            echo '#!{bash}' > python-wrapper
            echo set -Exe -o pipefail >> python-wrapper
            echo 'd=$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)' \\
                >> python-wrapper
            echo 'unset __PYVENV_LAUNCHER__' >> python-wrapper
            {f"echo 'export {wrapper_env}' >> python-wrapper"
             if wrapper_env else ""}
            echo 'p=${{d}}/{dest}/{prefix}' >> python-wrapper
            echo 's=$(${{d}}/{python} -c "{sitescript}")' >> python-wrapper
            echo export PYTHONPATH='${{s}}':"${{EXTRA_PYTHONPATH}}" \\
                >> python-wrapper
            echo exec '${{d}}/{python}' '"$@"' >> python-wrapper
            chmod +x python-wrapper
            cat python-wrapper
        """)

        disabled_modules = [
            "_sqlite3",
            "_tkinter",
            "_dbm",
            "_gdbm",
            "_lzma",
            "_bz2",
            "_curses",
            "_curses_panel",
            "_crypt",
            "audioop",
            "readline",
            "nis",
            "ossaudiodev",
            "spwd",
        ]

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

        return textwrap.dedent(f"""\
            # make sure no funny business is going on if metapkg
            # is ran from a venv.
            unset __PYVENV_LAUNCHER__
            echo '*disabled*' >> Modules/Setup.local
            echo '' >> Modules/Setup.local
            echo {' '.join(disabled_modules)} >> Modules/Setup.local
            # make sure config.c is regenerated reliably by make
            rm Modules/config.c
            ls -al Modules/
            {make} {make_env}
            ./{python} -m ensurepip --root "{dest}"
            {make_wrapper}""")
Exemple #5
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}"
        """)