以下の内容はhttps://interdb.hatenablog.com/entry/2023/03/30/074018より取得しました。


pgindent

備忘録。自分で探すとき、いつも一旦hatenaを探してから自分のサイトにいくので、こちらにも書いておくことにした。

www.interdb.jp

インストール

前提として (1) postgresは"/usr/local/pgsql"にインストールされている、 (2) PostgreSQLソースコードは"/usr/local/src/postgresql"以下にあるとする。

詳細はsrc/tools/pgindent/README参照。

1. pg_bsd_indentをインストール

2023年以降、pg_bsd_indentはpostgresql本体に同梱されるようになったようだ。

$ src/tools/pg_bsd_indent

以下のようにしてpg_bsd_indentをどこか適当な場所にインストールする。

$ git clone https://git.postgresql.org/git/pg_bsd_indent.git
$ cd pg_bsd_indent/
$ make PG_CONFIG=/usr/local/pgsql/bin/pg_config 
$ cp pg_bsd_indent /usr/local/bin

2. Perl-Tidyをインストール

以下のように、Perl-Tidyをインストールする。バージョンは20170521以外ダメなようだ。 PG17devではPerl-Tidy-20230309を使うらしい。

$ wget https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20230309.tar.gz
$ tar xvfz Perl-Tidy-20230309.tar.gz 
$ cd Perl-Tidy-20170521
$ perl Makefile.PL 
$ make
$ make test
$ make install

3. typedefsをインストール

PostgreSQLソースコードのトップディレクトリに移動し、以下のコマンドを実行する。

$ cd /usr/local/src/postgresql
$ wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl

Note

上記のように、postgresql本体同梱のpg_bsd_indentを使えば問題なし。

PG17devで試すと、以下のようなエラーが出る。

$ ../../src/tools/pgindent/pgindent 
You do not appear to have pg_bsd_indent version 2.1.2 installed on your system.

が、pg_bsd_indentのTAGを調べると、version 2.1.1.までしかできていない。

$ ~/pg_bsd_indent$ git tag
REL_2_1_1

仕方ないので、pgindentの変数を変更して対処する。

#!/usr/bin/perl                                                                                                                                

# Copyright (c) 2021-2023, PostgreSQL Global Development Group                                                                                 
                                                                                                                                               
use strict;                                                                                                                                    
use warnings;
                                                                                                                                               
use Cwd qw(abs_path getcwd);                                                                                                                   
use File::Find;                                                                                                                                
use File::Spec qw(devnull);                                                                                                                    
use File::Temp;                                                                                                                                
use IO::Handle;                                                                                                                                
use Getopt::Long;

# Update for pg_bsd_indent version                                                                                                             
my $INDENT_VERSION = "2.1.1";     # "2.1.2"から"2.1.1"へ。

とりあえず動くのでヨシ。

Usage

$ cd /usr/local/src/postgresql
$ ./src/tools/pgindent/pgindet

If you make an extension that is located in the contrib sub-directory, do the following command.

$ cd /usr/local/src/postgresql/contirb/your_extension
$ ../../src/tools/pgindent/pgindent .

Don't forget the last comma "."




以上の内容はhttps://interdb.hatenablog.com/entry/2023/03/30/074018より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14