def get_build_tools(self, build: targets.Build) -> dict[str, pathlib.Path]: bindir = build.get_install_path("bin").relative_to("/") datadir = build.get_install_path("data") libdir = build.get_install_path("lib") temp_install_path = build.get_build_dir(self) / "_install" # Since we are using a temporary Postgres installation, # pg_config will return paths together with the temporary # installation prefix, so we need to wrap it to strip # it from certain paths. wrapper = textwrap.dedent(f"""\ import pathlib import subprocess import sys path = ( pathlib.Path(__file__).parent.parent.parent / '{temp_install_path}' ).resolve() pgc = path / '{bindir}' / 'pg_config' proc = subprocess.run( [pgc] + sys.argv[1:], check=True, stdout=subprocess.PIPE, universal_newlines=True) for line in proc.stdout.split('\\n'): if ('{datadir}' in line or ('{libdir}' in line and 'pgxs' not in line)): line = line.replace(str(path), '') print(line) """) wrapper_cmd = build.write_helper("pg_config_wrapper.py", wrapper, relative_to="sourceroot") return { "pg_config_wrapper": wrapper_cmd, "pg_config": temp_install_path / "pg_config_wrapper", }
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}"
def get_build_tools(self, build: targets.Build) -> dict[str, pathlib.Path]: build_dir = build.get_build_dir(self) return {"python": build_dir / "python-wrapper"}