You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2017/02/01 21:25:02 UTC

[1/2] incubator-madlib git commit: Build: Use only major version for GPDB 5, HAWQ 2

Repository: incubator-madlib
Updated Branches:
  refs/heads/master 0e00a27f9 -> 071128d7c


Build: Use only major version for GPDB 5, HAWQ 2

GPDB, starting 5.0, and HAWQ, starting 2.0, are using semantic
versioning for releases. This implies a binary compatibility between
same major versions. Hence, we only need to compile a single MADlib
binary for the same major version, with the folder name being just the
major version instead of 'major.minor'.

Closes #79, closes #91

0e00a27 closes #76


Project: http://git-wip-us.apache.org/repos/asf/incubator-madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-madlib/commit/d65dca54
Tree: http://git-wip-us.apache.org/repos/asf/incubator-madlib/tree/d65dca54
Diff: http://git-wip-us.apache.org/repos/asf/incubator-madlib/diff/d65dca54

Branch: refs/heads/master
Commit: d65dca5450c68df00a2350648f12a72151676692
Parents: 0e00a27
Author: Rahul Iyer <ri...@apache.org>
Authored: Mon Jan 23 16:58:29 2017 -0800
Committer: Rahul Iyer <ri...@apache.org>
Committed: Wed Feb 1 13:15:31 2017 -0800

----------------------------------------------------------------------
 src/madpack/madpack.py                          | 44 +++++++++++++-------
 src/ports/greenplum/5.0/CMakeLists.txt          |  1 -
 src/ports/greenplum/5/CMakeLists.txt            |  1 +
 src/ports/greenplum/cmake/FindGreenplum_5.cmake |  2 +
 .../greenplum/cmake/FindGreenplum_5_0.cmake     |  2 -
 src/ports/hawq/2.0/CMakeLists.txt               | 20 ---------
 src/ports/hawq/2/CMakeLists.txt                 | 19 +++++++++
 src/ports/hawq/CMakeLists.txt                   |  2 +-
 src/ports/hawq/cmake/FindHAWQ_2.cmake           | 21 ++++++++++
 src/ports/hawq/cmake/FindHAWQ_2_0.cmake         | 21 ----------
 src/ports/postgres/cmake/PostgreSQLUtils.cmake  | 36 ++++++++++------
 11 files changed, 96 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/madpack/madpack.py
----------------------------------------------------------------------
diff --git a/src/madpack/madpack.py b/src/madpack/madpack.py
index e15bb4a..8b0e64d 100755
--- a/src/madpack/madpack.py
+++ b/src/madpack/madpack.py
@@ -317,13 +317,9 @@ def _get_dbver():
         if portid == 'postgres':
             match = re.search("PostgreSQL[a-zA-Z\s]*(\d+\.\d+)", versionStr)
         elif portid == 'greenplum':
-            match = re.search("Greenplum[a-zA-Z\s]*(\d+\.\d+)", versionStr)
-            # Due to the ABI incompatibility between 4.3.4 and 4.3.5,
-            # MADlib treat 4.3.5+ as DB version 4.3V2 that is different from 4.3
-            if match and match.group(1) == '4.3':
-                match_details = re.search("Greenplum[a-zA-Z\s]*(\d+\.\d+.\d+)", versionStr)
-                if _is_rev_gte(_get_rev_num(match_details.group(1)), _get_rev_num('4.3.5')):
-                    return '4.3ORCA'
+            # for Greenplum the 3rd digit is necessary to differentiate
+            # 4.3.5+ from versions < 4.3.5
+            match = re.search("Greenplum[a-zA-Z\s]*(\d+\.\d+\.\d+)", versionStr)
         elif portid == 'hawq':
             match = re.search("HAWQ[a-zA-Z\s]*(\d+\.\d+)", versionStr)
         return None if match is None else match.group(1)
@@ -1098,11 +1094,6 @@ def main(argv):
 
         # Get DB version
         dbver = _get_dbver()
-        portdir = os.path.join(maddir, "ports", portid)
-        if portid == "hawq" and _is_rev_gte(_get_rev_num(dbver), _get_rev_num('2.0')):
-            is_hawq2 = True
-        else:
-            is_hawq2 = False
 
         # Get MADlib version in DB
         dbrev = _get_madlib_dbrev(schema)
@@ -1111,12 +1102,14 @@ def main(argv):
         if portid == 'hawq' and not is_hawq2 and schema.lower() != 'madlib':
             _error("*** Installation is currently restricted only to 'madlib' schema ***", True)
 
+        portdir = os.path.join(maddir, "ports", portid)
         supportedVersions = [dirItem for dirItem in os.listdir(portdir)
                              if os.path.isdir(os.path.join(portdir, dirItem)) and
-                             re.match("^\d+\.\d+", dirItem)]
+                             re.match("^\d+", dirItem)]
         if dbver is None:
-            dbver = ".".join(map(str, max([map(int, versionStr.split('.'))
-                                           for versionStr in supportedVersions])))
+            dbver = ".".join(
+                map(str, max([versionStr.split('.')
+                              for versionStr in supportedVersions])))
             _info("Could not parse version string reported by {DBMS}. Will "
                   "default to newest supported version of {DBMS} "
                   "({version}).".format(DBMS=ports[portid]['name'],
@@ -1124,6 +1117,27 @@ def main(argv):
         else:
             _info("Detected %s version %s." % (ports[portid]['name'], dbver),
                   True)
+
+            if portid == "hawq":
+                # HAWQ (starting 2.0) and GPDB (starting 5.0) uses semantic versioning,
+                # which implies all HAWQ 2.x or GPDB 5.x versions will have binary
+                # compatibility. Hence, we can keep single folder for all 2.X / 5.X.
+                if (_is_rev_gte(_get_rev_num(dbver), _get_rev_num('2.0')) and
+                        not _is_rev_gte(_get_rev_num(dbver), _get_rev_num('3.0'))):
+                    is_hawq2 = True
+                    dbver = '2'
+            elif portid == 'greenplum':
+                # similar to HAWQ above, collapse all 5.X versions
+                if (_is_rev_gte(_get_rev_num(dbver), _get_rev_num('5.0')) and
+                        not _is_rev_gte(_get_rev_num(dbver), _get_rev_num('6.0'))):
+                    dbver = '5'
+                # Due to the ABI incompatibility between 4.3.4 and 4.3.5,
+                # MADlib treats 4.3.5+ as DB version 4.3ORCA which is different
+                # from 4.3. The name is suffixed with ORCA since optimizer (ORCA) is
+                # 'on' by default in 4.3.5
+                elif _is_rev_gte(_get_rev_num(dbver), _get_rev_num('4.3.4')):
+                    dbver = '4.3ORCA'
+
             if not os.path.isdir(os.path.join(portdir, dbver)):
                 _error("This version is not among the %s versions for which "
                        "MADlib support files have been installed (%s)." %

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/greenplum/5.0/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/ports/greenplum/5.0/CMakeLists.txt b/src/ports/greenplum/5.0/CMakeLists.txt
deleted file mode 100644
index 015d76e..0000000
--- a/src/ports/greenplum/5.0/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-add_current_greenplum_version()

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/greenplum/5/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/ports/greenplum/5/CMakeLists.txt b/src/ports/greenplum/5/CMakeLists.txt
new file mode 100644
index 0000000..015d76e
--- /dev/null
+++ b/src/ports/greenplum/5/CMakeLists.txt
@@ -0,0 +1 @@
+add_current_greenplum_version()

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/greenplum/cmake/FindGreenplum_5.cmake
----------------------------------------------------------------------
diff --git a/src/ports/greenplum/cmake/FindGreenplum_5.cmake b/src/ports/greenplum/cmake/FindGreenplum_5.cmake
new file mode 100644
index 0000000..fe15861
--- /dev/null
+++ b/src/ports/greenplum/cmake/FindGreenplum_5.cmake
@@ -0,0 +1,2 @@
+set(_FIND_PACKAGE_FILE "${CMAKE_CURRENT_LIST_FILE}")
+include("${CMAKE_CURRENT_LIST_DIR}/FindGreenplum.cmake")

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/greenplum/cmake/FindGreenplum_5_0.cmake
----------------------------------------------------------------------
diff --git a/src/ports/greenplum/cmake/FindGreenplum_5_0.cmake b/src/ports/greenplum/cmake/FindGreenplum_5_0.cmake
deleted file mode 100644
index fe15861..0000000
--- a/src/ports/greenplum/cmake/FindGreenplum_5_0.cmake
+++ /dev/null
@@ -1,2 +0,0 @@
-set(_FIND_PACKAGE_FILE "${CMAKE_CURRENT_LIST_FILE}")
-include("${CMAKE_CURRENT_LIST_DIR}/FindGreenplum.cmake")

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/hawq/2.0/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/ports/hawq/2.0/CMakeLists.txt b/src/ports/hawq/2.0/CMakeLists.txt
deleted file mode 100644
index 0a2eb24..0000000
--- a/src/ports/hawq/2.0/CMakeLists.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-# ------------------------------------------------------------------------------
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# ------------------------------------------------------------------------------
-
-add_current_hawq_version()

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/hawq/2/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/ports/hawq/2/CMakeLists.txt b/src/ports/hawq/2/CMakeLists.txt
new file mode 100644
index 0000000..a024a53
--- /dev/null
+++ b/src/ports/hawq/2/CMakeLists.txt
@@ -0,0 +1,19 @@
+# ------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ------------------------------------------------------------------------------
+add_current_hawq_version()

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/hawq/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/ports/hawq/CMakeLists.txt b/src/ports/hawq/CMakeLists.txt
index 8610238..2ba532d 100644
--- a/src/ports/hawq/CMakeLists.txt
+++ b/src/ports/hawq/CMakeLists.txt
@@ -85,7 +85,7 @@ add_sql_files(
     "../postgres/modules"
     "${CMAKE_CURRENT_BINARY_DIR}/modules"
 )
-# Add Greenplum-specific modules. Files will be appended to SQL_TARGET_FILES.
+# Add HAWQ-specific modules. Files will be appended to SQL_TARGET_FILES.
 add_sql_files(
     SQL_TARGET_FILES
     "modules"

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/hawq/cmake/FindHAWQ_2.cmake
----------------------------------------------------------------------
diff --git a/src/ports/hawq/cmake/FindHAWQ_2.cmake b/src/ports/hawq/cmake/FindHAWQ_2.cmake
new file mode 100644
index 0000000..0cdbf63
--- /dev/null
+++ b/src/ports/hawq/cmake/FindHAWQ_2.cmake
@@ -0,0 +1,21 @@
+# ------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ------------------------------------------------------------------------------
+
+set(_FIND_PACKAGE_FILE "${CMAKE_CURRENT_LIST_FILE}")
+include("${CMAKE_CURRENT_LIST_DIR}/FindHAWQ.cmake")

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/hawq/cmake/FindHAWQ_2_0.cmake
----------------------------------------------------------------------
diff --git a/src/ports/hawq/cmake/FindHAWQ_2_0.cmake b/src/ports/hawq/cmake/FindHAWQ_2_0.cmake
deleted file mode 100644
index 0cdbf63..0000000
--- a/src/ports/hawq/cmake/FindHAWQ_2_0.cmake
+++ /dev/null
@@ -1,21 +0,0 @@
-# ------------------------------------------------------------------------------
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# ------------------------------------------------------------------------------
-
-set(_FIND_PACKAGE_FILE "${CMAKE_CURRENT_LIST_FILE}")
-include("${CMAKE_CURRENT_LIST_DIR}/FindHAWQ.cmake")

http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/d65dca54/src/ports/postgres/cmake/PostgreSQLUtils.cmake
----------------------------------------------------------------------
diff --git a/src/ports/postgres/cmake/PostgreSQLUtils.cmake b/src/ports/postgres/cmake/PostgreSQLUtils.cmake
index e5e4228..7acdf9a 100644
--- a/src/ports/postgres/cmake/PostgreSQLUtils.cmake
+++ b/src/ports/postgres/cmake/PostgreSQLUtils.cmake
@@ -4,7 +4,7 @@ function(define_postgresql_features IN_VERSION OUT_FEATURES)
     if(NOT ${IN_VERSION} VERSION_LESS "9.0")
         list(APPEND ${OUT_FEATURES} __HAS_ORDERED_AGGREGATES__)
     endif()
-    
+
     # Pass values to caller
     set(${OUT_FEATURES} "${${OUT_FEATURES}}" PARENT_SCOPE)
 endfunction(define_postgresql_features)
@@ -54,7 +54,7 @@ endfunction(cpack_add_version_component)
 #
 function(determine_target_versions OUT_VERSIONS)
     get_subdirectories("${CMAKE_CURRENT_SOURCE_DIR}" SUPPORTED_VERSIONS)
-    get_filtered_list(SUPPORTED_VERSIONS "^[0-9]+.[0-9]+.*$" ${SUPPORTED_VERSIONS})
+    get_filtered_list(SUPPORTED_VERSIONS "^[0-9]+.*$" ${SUPPORTED_VERSIONS})
 
     foreach(VERSION ${SUPPORTED_VERSIONS})
         string(REPLACE "." "_" VERSION_UNDERSCORE "${VERSION}")
@@ -64,18 +64,28 @@ function(determine_target_versions OUT_VERSIONS)
     endforeach(VERSION)
     if(NOT DEFINED ${OUT_VERSIONS})
         find_package(${PORT})
-
         if(${PORT_UC}_FOUND)
-            # Due to the ABI incompatibility between 4.3.4 and 4.3.5,
-            # MADlib treat 4.3.5+ as DB version that is different from 4.3
-            if(${PORT_UC} STREQUAL "GREENPLUM" AND
-                    ${${PORT_UC}_VERSION_MAJOR} EQUAL 4 AND
-                    ${${PORT_UC}_VERSION_MINOR} EQUAL 3 AND
-                    ${${PORT_UC}_VERSION_PATCH} GREATER 4)
-                set(VERSION "4.3ORCA")
-            else()
-                set(VERSION "${${PORT_UC}_VERSION_MAJOR}.${${PORT_UC}_VERSION_MINOR}")
+            set(VERSION "${${PORT_UC}_VERSION_MAJOR}.${${PORT_UC}_VERSION_MINOR}")
+            if(${PORT_UC} STREQUAL "GREENPLUM")
+                # Starting GPDB 5.0, semantic versioning will be followed,
+                # implying we only need 1 folder for same major versions
+                if(${${PORT_UC}_VERSION_MAJOR} EQUAL 5)
+                    set(VERSION "5")
+
+                # Due to the ABI incompatibility between 4.3.4 and 4.3.5,
+                # MADlib treat 4.3.5+ as DB version that is different from 4.3
+                elseif(${${PORT_UC}_VERSION_MAJOR} EQUAL 4 AND
+                        ${${PORT_UC}_VERSION_MINOR} EQUAL 3 AND
+                        ${${PORT_UC}_VERSION_PATCH} GREATER 4)
+                    set(VERSION "4.3ORCA")
+                endif()
+            elseif(${PORT_UC} STREQUAL "HAWQ" AND
+                    ${${PORT_UC}_VERSION_MAJOR} EQUAL 2)
+                # Starting HAWQ 2.0, semantic versioning will be followed,
+                # implying we only need 1 folder for same major versions
+                set(VERSION "2")
             endif()
+
             list(FIND SUPPORTED_VERSIONS "${VERSION}" _POS)
             if(_POS EQUAL -1)
                 string(REPLACE ";" ", " _SUPPORTED_VERSIONS_STR "${SUPPORTED_VERSIONS}")
@@ -96,7 +106,7 @@ function(determine_target_versions OUT_VERSIONS)
             endif(_POS EQUAL -1)
         endif(${PORT_UC}_FOUND)
     endif(NOT DEFINED ${OUT_VERSIONS})
-    
+
     # Pass values to caller
     set(${OUT_VERSIONS} "${${OUT_VERSIONS}}" PARENT_SCOPE)
     # ${PORT_UC}_${_VERSION_UNDERSCORE}_PG_CONFIG might have been set earlier!


[2/2] incubator-madlib git commit: Build: Use relative path for installation using GPPKG

Posted by ri...@apache.org.
Build: Use relative path for installation using GPPKG

GPDB and HAWQ use a relative link outside GPHOME to indicate the current
version of the database. During a DB upgrade, this relative link is
updated to point to the right location. Installing MADlib using GPPKG
leads to madlib files within GPHOME, but the functions use the absolute
path instead of this symbolic link. This commit changes those locations
to employ the symbolic link, allowing easy DB upgrades.

Closes #94


Project: http://git-wip-us.apache.org/repos/asf/incubator-madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-madlib/commit/071128d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-madlib/tree/071128d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-madlib/diff/071128d7

Branch: refs/heads/master
Commit: 071128d7cbf8cefe3b3bb72fea3978bd4f5837dd
Parents: d65dca5
Author: Rahul Iyer <ri...@apache.org>
Authored: Tue Jan 24 16:59:50 2017 -0800
Committer: Rahul Iyer <ri...@apache.org>
Committed: Wed Feb 1 13:16:36 2017 -0800

----------------------------------------------------------------------
 src/madpack/madpack.py | 82 ++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 69 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-madlib/blob/071128d7/src/madpack/madpack.py
----------------------------------------------------------------------
diff --git a/src/madpack/madpack.py b/src/madpack/madpack.py
index 8b0e64d..ddd75df 100755
--- a/src/madpack/madpack.py
+++ b/src/madpack/madpack.py
@@ -35,8 +35,7 @@ if sys.version_info[:2] < py_min_ver:
 # two levels up in the directory hierarchy. We use (a) os.path.realpath and
 # (b) __file__ (instead of sys.argv[0]) because madpack.py could be called
 # (a) through a symbolic link and (b) not as the main module.
-maddir = os.path.abspath(os.path.dirname(os.path.realpath(
-    __file__)) + "/..")   # MADlib root dir
+maddir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/..")   # MADlib root dir
 sys.path.append(maddir + "/madpack")
 
 # Import MADlib python modules
@@ -57,6 +56,8 @@ portid_list = []
 for port in ports:
     portid_list.append(port)
 
+SUPPORTED_PORTS = ('postgres', 'greenplum', 'hawq')
+
 # Global variables
 portid = None       # Target port ID (eg: pg90, gp40)
 dbconn = None       # DB Connection object
@@ -182,10 +183,48 @@ def _internal_run_query(sql, show_error):
 # ------------------------------------------------------------------------------
 
 
+def _get_relative_maddir(maddir, port):
+    """ Return a relative path version of maddir
+
+    GPDB and HAWQ installations have a symlink outside of GPHOME that
+    links to the current GPHOME. After a DB upgrade, this symlink is updated to
+    the new GPHOME.
+
+    'maddir_lib', which uses the absolute path of GPHOME, is hardcoded into each
+    madlib function definition. Replacing the GPHOME path with the equivalent
+    relative path makes it simpler to perform DB upgrades without breaking MADlib.
+    """
+    if port not in ('greenplum', 'hawq'):
+        # do nothing for postgres
+        return maddir
+
+    # e.g. maddir_lib = $GPHOME/madlib/Versions/1.9/lib/libmadlib.so
+    # 'madlib' is supposed to be in this path, which is the default folder
+    # used by GPPKG to install madlib
+    try:
+        abs_gphome, tail = maddir.split('madlib/')
+    except ValueError:
+        return maddir
+
+    link_name = 'greenplum-db' if port == 'greenplum' else 'hawq'
+
+    # Check outside $GPHOME if there is a symlink to this absolute path
+    # os.pardir is equivalent to ..
+    # os.path.normpath removes the extraneous .. from that path
+    rel_gphome = os.path.normpath(os.path.join(abs_gphome, os.pardir, link_name))
+    if os.path.islink(rel_gphome) and os.path.realpath(rel_gphome) == os.path.realpath(abs_gphome):
+        # if the relative link exists and is pointing to current location
+        return os.path.join(rel_gphome, 'madlib', tail)
+    else:
+        return maddir
+# ------------------------------------------------------------------------------
+
+
 def _run_sql_file(schema, maddir_mod_py, module, sqlfile,
                   tmpfile, logfile, pre_sql, upgrade=False,
                   sc=None):
-    """Run SQL file
+    """
+        Run SQL file
             @param schema name of the target schema
             @param maddir_mod_py name of the module dir with Python code
             @param module  name of the module
@@ -955,8 +994,7 @@ def parseConnectionStr(connectionStr):
 # ------------------------------------------------------------------------------
 
 
-def main(argv):
-
+def parse_arguments():
     parser = argparse.ArgumentParser(
         prog="madpack",
         description='MADlib package manager (' + str(rev) + ')',
@@ -1018,7 +1056,12 @@ def main(argv):
                         help="Module names to test, comma separated. Effective only for install-check.")
 
     # Get the arguments
-    args = parser.parse_args()
+    return parser.parse_args()
+
+
+def main(argv):
+    args = parse_arguments()
+
     global verbose
     verbose = args.verbose
     _info("Arguments: " + str(args), verbose)
@@ -1040,9 +1083,6 @@ def main(argv):
 
     # Parse DB Platform (== PortID) and compare with Ports.yml
     global portid
-    global dbver
-    global is_hawq2
-
     if args.platform:
         try:
             # Get the DB platform name == DB port id
@@ -1060,7 +1100,7 @@ def main(argv):
         (c_user, c_pass, c_host, c_port, c_db) = parseConnectionStr(connStr)
 
         # Find the default values for PG and GP
-        if portid in ('postgres', 'greenplum', 'hawq'):
+        if portid in SUPPORTED_PORTS:
             if c_user is None:
                 c_user = os.environ.get('PGUSER', getpass.getuser())
             if c_pass is None:
@@ -1093,15 +1133,25 @@ def main(argv):
             _error('Failed to connect to database', True)
 
         # Get DB version
+        global dbver
         dbver = _get_dbver()
-
-        # Get MADlib version in DB
-        dbrev = _get_madlib_dbrev(schema)
+        global is_hawq2
+        if portid == "hawq" and _is_rev_gte(_get_rev_num(dbver), _get_rev_num('2.0')):
+            is_hawq2 = True
+        else:
+            is_hawq2 = False
 
         # HAWQ < 2.0 has hard-coded schema name 'madlib'
         if portid == 'hawq' and not is_hawq2 and schema.lower() != 'madlib':
             _error("*** Installation is currently restricted only to 'madlib' schema ***", True)
 
+        # update maddir to use a relative path if available
+        global maddir
+        maddir = _get_relative_maddir(maddir, portid)
+
+        # Get MADlib version in DB
+        dbrev = _get_madlib_dbrev(schema)
+
         portdir = os.path.join(maddir, "ports", portid)
         supportedVersions = [dirItem for dirItem in os.listdir(portdir)
                              if os.path.isdir(os.path.join(portdir, dirItem)) and
@@ -1151,11 +1201,17 @@ def main(argv):
         global maddir_conf
         if os.path.isdir(maddir + "/ports/" + portid + "/" + dbver + "/config"):
             maddir_conf = maddir + "/ports/" + portid + "/" + dbver + "/config"
+        else:
+            maddir_conf = maddir + "/config"
+
         global maddir_lib
         if os.path.isfile(maddir + "/ports/" + portid + "/" + dbver +
                           "/lib/libmadlib.so"):
             maddir_lib = maddir + "/ports/" + portid + "/" + dbver + \
                 "/lib/libmadlib.so"
+        else:
+            maddir_lib = maddir + "/lib/libmadlib.so"
+
         # Get the list of modules for this port
         global portspecs
         portspecs = configyml.get_modules(maddir_conf)