Skip to content

Commit

Permalink
Implementation of 'build-git' command.
Browse files Browse the repository at this point in the history
This command acts as an alias for 'build dev', that is introduces
the special version 'dev' to instrument the build process to download
the source tree via git instead of getting a tarball.

If the 'dev' version has never been created, than a complete checkout
is performed; otherwise a fetch is done.
The build process continues as usual, with patching, make, and etc.

At the end, the 'pgenv-dev' directory will be in place to indicate the
new version of PostgreSQL.

It is possible to configure the git process via two special variables, that
have not been introduced in the configuration mechanism because they
represent developer tweaks; they can be manually added in any case.

Documentation updated.

See theory#25
  • Loading branch information
fluca1978 committed Oct 29, 2018
1 parent 0cc7bfe commit 321038e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 31 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Synopsis
# Build PostgreSQL server
pgenv build 10.4

# Build from git
pgenv build-git

# Use PostgreSQL version
pgenv use 10.4

Expand Down Expand Up @@ -110,7 +113,8 @@ $ git pull
* curl - Used to download files
* sed, grep, cat, tar, sort, tr, uname - General Unix command line utilities
* patch - For patching versions that need patching
* make - Builds PostgreSQL
* make - Builds PostgreSQL
* git - Used to download the current source tree
Optional dependencies:
Expand Down Expand Up @@ -270,6 +274,38 @@ file. As an example
### pgenv build-git
This command fetches the current source tree from the official PostgreSQL git repository
and builds it as special version `dev`. This is an option aimed to help developers
to keep a version up-to-date with the current PostgreSQL source tree.
Actually, the command is an *alias* for `build dev`, meaning that the following
two commands are identical:
$ pgenv build-git
$ pgenv build dev
The first time the command is called a source directory `dev` is created and the
default branch is checked out. On a further execution, the command
will fetch updates from the repository.
It is possible to configure both the repository and the branch to fetch
using the variables:
- `PGENV_GIT_REPO` which defaults to `https://git.postgresql.org/git/postgresql.git`;
- `PGENV_GIT_CHECKOUT_BRANCH` which if not set defaults to fetching the `master` branch, while
if set creates a tracking branch.
The above variable have not been included in the configuration mechanism because they
represent advanced tweaks. It is however possible to include them in the configuration file
for this particular version (`.pgenv.dev.conf`) or in the global configuration file
to drive the checkout and fetch process.
Patching of the special `dev` version happens as for regular versions, but using the special
`dev` version identifier, and therefore the patch index is searched with such string
in place of a regular version number.
### pgenv remove
Removes the specified version of PostgreSQL unless it is the currently-active
Expand Down
111 changes: 81 additions & 30 deletions bin/pgenv
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pgenv_input_version_or_exit() {
local verbose=$2
local hint=$3

echo "version $version"

if [ -z "$version" ]; then
if [ ! -z "$hint" ]; then
# count the versions
Expand Down Expand Up @@ -214,6 +216,8 @@ pgenv_input_version_or_exit() {
return # versions 9.5.4 or 10.1 and alike
elif [[ $version =~ ^[1-9][1-9](beta|rc)[1-9]?$ ]]; then
return # versions 11beta1 and alike
elif [ $version = 'dev' ]; then
return # building from git or alike
else
echo "Value \"$version\" does not appear to be a PostgreSQL valid version number"
exit 1
Expand Down Expand Up @@ -685,8 +689,17 @@ case $1 in
exit
;;

build)
v=$2
build|build-git)

# in the case of 'build-git'
# the version defaults to 'dev'
case $1 in
build) v=$2 ;;
build-git) v='dev'
shift # remove the command
;;
esac

# sanity checks before building
pgenv_input_version_or_exit "$v"
pgenv_configuration_load $v
Expand All @@ -705,40 +718,76 @@ case $1 in
fi
cd src

# Download the source if wee don't already have it.
# WARNING: older PostgreSQL used .tar.gz instead of .tar.bz2,
# so if the version is behind 8 use the first format, otherwise
# try to get the most compressed archive
if [[ $v =~ ^[1-7]\. ]]; then
PG_TARBALL="postgresql-$v.tar.gz"
TAR_OPTS="zxf"

if [ "$v" != 'dev' ]; then
# Download the source if wee don't already have it.
# WARNING: older PostgreSQL used .tar.gz instead of .tar.bz2,
# so if the version is behind 8 use the first format, otherwise
# try to get the most compressed archive
if [[ $v =~ ^[1-7]\. ]]; then
PG_TARBALL="postgresql-$v.tar.gz"
TAR_OPTS="zxf"
else
PG_TARBALL="postgresql-$v.tar.bz2"
TAR_OPTS="jxf"
fi

if [ ! -f $PG_TARBALL ]; then
$PGENV_CURL -fLO ${PGENV_DOWNLOAD_ROOT}/v$v/${PG_TARBALL}
fi


# warn if no configuration was loaded
if [ -z "$PGENV_CONFIGURATION_FILE" ]; then
echo "WARNING: no configuration file found for version $v"
echo "HINT: if you wish to customize the build process please"
echo "stop the execution within 5 seconds (CTRL-c) and run "
echo " pgenv config write $v && pgenv config edit $v"
echo "adjust 'configure' and 'make' options and flags and run again"
echo " pgenv build $v"
echo
sleep 5
fi


# Unpack the source.
rm -rf "postgresql-$v"
$PGENV_TAR $TAR_OPTS $PG_TARBALL
cd postgresql-$v


else
PG_TARBALL="postgresql-$v.tar.bz2"
TAR_OPTS="jxf"
fi
# here there is the build from git for 'dev'

if [ ! -f $PG_TARBALL ]; then
$PGENV_CURL -fLO ${PGENV_DOWNLOAD_ROOT}/v$v/${PG_TARBALL}
fi
# initialize variables if not explicitly set
if [ -z "$PGENV_GIT_REPO" ]; then
PGENV_GIT_REPO="https://git.postgresql.org/git/postgresql.git"
fi

# if the user wants a specific branch, build the
# command line options
if [ ! -z "$PGENV_GIT_CHECKOUT_BRANCH" ]; then
PGENV_GIT_CHECKOUT="-b $PGENV_GIT_CHECKOUT_BRANCH --track origin/$PGENV_GIT_CHECKOUT_BRANCH"
else
# avoid tainting
PGENV_GIT_CHECKOUT=""
fi

pgenv_debug "Checking out [$PGENV_GIT_REPO] @ [$PGENV_GIT_CHECKOUT]"

# warn if no configuration was loaded
if [ -z "$PGENV_CONFIGURATION_FILE" ]; then
echo "WARNING: no configuration file found for version $v"
echo "HINT: if you wish to customize the build process please"
echo "stop the execution within 5 seconds (CTRL-c) and run "
echo " pgenv config write $v && pgenv config edit $v"
echo "adjust 'configure' and 'make' options and flags and run again"
echo " pgenv build $v"
echo
sleep 5
# download the sources
if [ -d 'dev' ]; then
# directory already existing, fetch new sources
cd dev
git fetch $PGENV_GIT_REPO
else
# first checkout
git clone $PGENV_GIT_REPO $PGENV_GIT_CHECKOUT dev
cd dev
fi
fi


# Unpack the source.
rm -rf "postgresql-$v"
$PGENV_TAR $TAR_OPTS $PG_TARBALL
cd postgresql-$v

# patch the source tree if required
pgenv_debug "Patching version $v"
Expand All @@ -748,7 +797,7 @@ case $1 in
pgenv_debug "configure command line [--prefix=$PGENV_ROOT/pgsql-$v] + [$PGENV_CONFIGURE_OPTS]"
# need to keep a single string to pass to configure or
# will get an 'invalid package'
./configure --prefix=$PGENV_ROOT/pgsql-$v $PGENV_CONFIGURE_OPTS
./configure --prefix=$PGENV_ROOT/pgsql-$v $PGENV_CONFIGURE_OPTS --without-readline

# make and make install
if [[ $v =~ ^[1-8]\. ]]; then
Expand All @@ -758,6 +807,8 @@ case $1 in
cd contrib
$PGENV_MAKE $PGENV_MAKE_OPTS
$PGENV_MAKE install
elif [ "$v" = 'dev' ]; then
$PGENV_MAKE world $PGENV_MAKE_OPTS
else
# Yay, make world!
$PGENV_MAKE world $PGENV_MAKE_OPTS
Expand Down

0 comments on commit 321038e

Please sign in to comment.