From efe9fdbbe640c15b7ff01ccb82ecc4d7792e2ecd Mon Sep 17 00:00:00 2001 From: Stas Kelvich Date: Mon, 22 Mar 2021 17:56:00 +0300 Subject: [PATCH] Add 'make postgres' Makefile target. That would build postgres and install it into REPO_ROOT/tmp_install where pageserver integration tests would be able to find it. --- .gitignore | 1 + Makefile | 34 ++++++++++++++++++++++++++++++++++ build.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/control_plane.rs | 5 ++--- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100644 build.rs diff --git a/.gitignore b/.gitignore index ea8c4bf7f3..cfa64b8f7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/tmp_install diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..2c800bc6b5 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +# +# Purpose of this Makefile is to build and install postgres in a local directory +# so that zenith intergation tests would find pg binaries and support files. +# +# 'make postgres' would do following: +# +# 1) run out-of-source build of postgres in REPO_ROOT/tmp_install/build directory (I'm reusing +# tmp_install path here since it is already present in .gitignore) +# +# 2) installs postgres to REPO_ROOT/tmp_install/ +# +# This Makefile is integrated with cargo build by the means of build.rs file (special file +# that cargo build would run if it is present) which will call `make postgres` if there is no +# tmp_install/bin/postgres binary. +# + +../tmp_install/build/Makefile: + mkdir -p ../tmp_install/build && \ + cd ../tmp_install/build && \ + ../../configure CFLAGS='-O0' --enable-debug --enable-cassert \ + --enable-depend --with-libxml --prefix=/ + +pg-configure: ../tmp_install/build/Makefile + +# this makefile would set env variables that would interfere with postgres build +# preventing it from finding autogenerated headers. Hence 'env -i' +pg-build: pg-configure + env -i make -j8 -C ../tmp_install/build + +postgres: pg-build + mkdir -p ../tmp_install/log + env -i make -C ../tmp_install/build \ + DESTDIR=/Users/stas/code/postgres/tmp_install install \ + > /Users/stas/code/postgres/tmp_install/log/install.log 2>&1 diff --git a/build.rs b/build.rs new file mode 100644 index 0000000000..cddd415ae5 --- /dev/null +++ b/build.rs @@ -0,0 +1,41 @@ +// +// Triggers postgres build if there is no postgres binary present at +// 'REPO_ROOT/tmp_install/bin/postgres'. +// +// I can see a lot of disadvantages with such automatization and main +// advantage here is ability to build everything and run integration tests +// in a bare repo by running 'cargo test'. +// +// We can interceipt whether it is debug or release build and run +// corresponding pg build. But it seems like an overkill for now. +// +// Problem #1 -- language server in my editor likes calling 'cargo build' +// by himself. So if I delete tmp_install directory it would magically reappear +// after some time. During this compilation 'cargo build' may whine about +// "waiting for file lock on build directory". +// +// Problem #2 -- cargo build would run this only if something is changed in +// the crate. +// +// And generally speaking postgres is not a build dependency for the pageserver, +// just for integration tests. So let's not mix that. I'll leave this file in +// place for some time just in case if anybody would start doing the same. +// + +// use std::path::Path; +// use std::process::{Command}; + +fn main() { + // // build some postgres if it is not done none yet + // if !Path::new("../tmp_install/bin/postgres").exists() { + // let make_res = Command::new("make") + // .arg("postgres") + // .env_clear() + // .status() + // .expect("failed to execute 'make postgres'"); + + // if !make_res.success() { + // panic!("postgres build failed"); + // } + // } +} diff --git a/src/control_plane.rs b/src/control_plane.rs index 38ca5158dd..db2a456710 100644 --- a/src/control_plane.rs +++ b/src/control_plane.rs @@ -45,10 +45,10 @@ impl ComputeControlPlane { pub fn local() -> ComputeControlPlane { // postgres configure and `make temp-install` are using this path let pg_install_dir = Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../build/tmp_install/usr/local/pgsql"); + .join("../tmp_install/"); let work_dir = Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../tmp_check/zenith"); + .join("tmp_install/"); ComputeControlPlane { pg_install_dir: pg_install_dir, @@ -190,7 +190,6 @@ impl PostgresNode { } impl Drop for PostgresNode { - // destructor to clean up state after test is done // TODO: leave everything in place if test is failed // TODO: put logs to a separate location to run `tail -F` on them