From 2adaefd46cefe3792c33d2369913258ca5c50a8d Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Fri, 28 May 2021 14:16:13 +1000 Subject: [PATCH] Install more conventionally The current move script does not work for M1 macs, or for anybody with a custom homebrew prefix. There's also no need for the extra step if the extension is exposed at a conventional location which homebrew can link into place. --- timescaledb.rb | 67 +++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/timescaledb.rb b/timescaledb.rb index 2dbac4e..ff0e9f4 100644 --- a/timescaledb.rb +++ b/timescaledb.rb @@ -5,8 +5,9 @@ class Timescaledb < Formula version "2.3.0" sha256 "baa8a60230320838c6d5d143846c14edc5238e2979ed2408a980280f05a81b3e" + depends_on "postgresql" + depends_on "cmake" => :build - depends_on "postgresql" => :build depends_on "openssl" => :build depends_on "xz" => :build depends_on "timescaledb-tools" => :recommended @@ -14,44 +15,48 @@ class Timescaledb < Formula option "with-oss-only", "Build TimescaleDB with only Apache-2 licensed code" def install - ossvar = "" - if build.with?("oss-only") - ossvar = " -DAPACHE_ONLY=1" - end - system "./bootstrap -DREGRESS_CHECKS=OFF -DPROJECT_INSTALL_METHOD=\"brew\"#{ossvar}" - system "cd ./build && make" - system "cd ./build && make install DESTDIR=#{buildpath}/stage" - libdir = `pg_config --pkglibdir` - sharedir = `pg_config --sharedir` - `touch timescaledb_move.sh` - `chmod +x timescaledb_move.sh` - `echo "#!/bin/bash" >> timescaledb_move.sh` - `echo "echo 'Moving files into place...'" >> timescaledb_move.sh` - `echo "/usr/bin/install -c -m 755 \\\$(find #{lib} -name timescaledb*.so) #{libdir.strip}/" >> timescaledb_move.sh` - `echo "/usr/bin/install -c -m 644 #{share}/timescaledb/* #{sharedir.strip}/extension/" >> timescaledb_move.sh` - `echo "echo 'Success.'" >> timescaledb_move.sh` - bin.install "timescaledb_move.sh" - (lib/"timescaledb").install Dir["stage/**/lib/*"] - (share/"timescaledb").install Dir["stage/**/share/postgresql*/extension/*"] + system "./bootstrap -DREGRESS_CHECKS=OFF -DPROJECT_INSTALL_METHOD=\"brew\"#{" -DAPACHE_ONLY=1" if build.with?("oss-only")}" + + (buildpath/"build").cd do + system "make" + + # CMake installs the files into DESTDIR/$HOMEBREW_PREFIX, so stage it and then unwrap it + stage = buildpath/"stage" + stage.mkdir + + system "make install DESTDIR=#{stage}" + + # Something like: + # /var/tmp/abc123/stage/usr/local + # + # which contains files like + # /var/tmp/abc123/stage/usr/local/lib/postgresql/timescaledb.so + # + stage_prefix = (stage/HOMEBREW_PREFIX.to_s.delete_prefix("/")) + + prefix.install stage_prefix.children end + end test do - system "test", "-e", "#{lib}/timescaledb/timescaledb.so" + system "test", "-e", "#{lib}/postgresql/timescaledb.so" end def caveats - pgvar = `find /usr/local/var/postgres* -name "postgresql.conf" | head -n 1` - s = "RECOMMENDED: Run 'timescaledb-tune' to update your config settings for TimescaleDB.\n\n" - s += " timescaledb-tune --quiet --yes\n\n" + <<~EOS + RECOMMENDED: Run 'timescaledb-tune' to update your config settings for TimescaleDB. + + timescaledb-tune --quiet --yes --conf-path #{var/"postgres/postgresql.conf"} + + IF NOT, you'll need to make sure to update #{var/"postgres/postgresql.conf"} + to include the extension: + + shared_preload_libraries = 'timescaledb' - s += "IF NOT, you'll need to make sure to update #{pgvar.strip}\nto include the extension:\n\n" - s += " shared_preload_libraries = 'timescaledb'\n\n" + If PostgreSQL is installed via Homebrew, restart it: - s += "To finish the installation, you will need to run:\n\n" - s += " timescaledb_move.sh\n\n" + brew services restart postgresql - s += "If PostgreSQL is installed via Homebrew, restart it:\n\n" - s += " brew services restart postgresql\n\n" - s + EOS end end