Esempio n. 1
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
Esempio n. 2
0
    def get_build_install_script(self, build: targets.Build) -> str:
        script = super().get_build_install_script(build)
        cargo = build.sh_get_command("cargo")
        sed = build.sh_get_command("sed")
        installdest = build.get_temp_dir(self, relative_to="pkgbuild")
        src = build.get_source_dir(self, relative_to="pkgbuild")
        bindir = build.get_install_path("systembin").relative_to("/")
        install_bindir = (build.get_install_dir(self, relative_to="pkgbuild") /
                          bindir)
        if isinstance(build.target, targets.linux.LinuxMuslTarget):
            target = "--target x86_64-unknown-linux-musl"
        else:
            target = ""

        env = build.sh_append_global_flags({})
        env["RUST_BACKTRACE"] = "1"
        env_str = build.sh_format_command("env", env, force_args_eq=True)
        script += textwrap.dedent(f"""\
            {sed} -i -e '/\\[package\\]/,/\\[.*\\]/{{
                    s/^version\\s*=.*/version = "{self.version.text}"/;
                }}' \\
                "{src}/Cargo.toml"
            {env_str} \\
                {cargo} install {target} \\
                    --verbose --verbose \\
                    --root "{installdest}" \\
                    --path "{src}" \\
                    --locked
            mkdir -p "{install_bindir}"
            cp -a "{installdest}/bin/"* "{install_bindir}/"
            """)
        return script
Esempio n. 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}"