From fe944a16b5a5db8a03aadb61b223b3065ce0fa06 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 19 Apr 2021 17:03:57 +0530 Subject: [PATCH] Use EXTENSION_PATH to specify subdirectory in add_extension_from_source --- __tests__/extensions.test.ts | 4 ++-- __tests__/utils.test.ts | 8 ++++---- dist/index.js | 9 +++------ src/scripts/ext/cubrid.sh | 2 +- src/scripts/ext/firebird.sh | 3 ++- src/scripts/ext/geos.sh | 2 +- src/scripts/ext/http.sh | 4 ++-- src/scripts/ext/oci.sh | 3 ++- src/scripts/ext/source.sh | 10 +++++----- src/utils.ts | 8 +++----- 10 files changed, 25 insertions(+), 28 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 3fefb877..58463ef3 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -154,7 +154,7 @@ describe('Extension tests', () => { 'linux' ); expect(linux).toContain( - 'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver . master extension' + 'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension' ); }); @@ -252,7 +252,7 @@ describe('Extension tests', () => { 'darwin' ); expect(darwin).toContain( - 'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver . master extension' + 'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension' ); }); }); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 7618b07d..180c0c07 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -267,7 +267,7 @@ describe('Utils tests', () => { 'extension' ) ).toContain( - '\nadd_extension_from_source ext https://github.com org-name repo-name . release extension' + '\nadd_extension_from_source ext https://github.com org-name repo-name release extension' ); expect( await utils.parseExtensionSource( @@ -275,15 +275,15 @@ describe('Utils tests', () => { 'extension' ) ).toContain( - '\nadd_extension_from_source ext https://sub.domain.tld org repo . release extension' + '\nadd_extension_from_source ext https://sub.domain.tld org repo release extension' ); expect( await utils.parseExtensionSource( - 'ext-https://sub.domain.XN--tld/org/repo/sub/dir@release', + 'ext-https://sub.domain.XN--tld/org/repo@release', 'extension' ) ).toContain( - '\nadd_extension_from_source ext https://sub.domain.XN--tld org repo sub/dir release extension' + '\nadd_extension_from_source ext https://sub.domain.XN--tld org repo release extension' ); }); }); diff --git a/dist/index.js b/dist/index.js index fb7cf7e4..75580a9a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2978,13 +2978,10 @@ exports.customPackage = customPackage; * @param extension */ async function parseExtensionSource(extension, prefix) { - var _a, _b; - // Groups: extension, domain url, org, repo, subdirectory, release - // https://regex101.com/r/P3rJiy/1 - const regex = /(\w+)-(.+:\/\/.+(?:[.:][^/]+)+)?(?:\/)?([^/]+)\/([^/]+)(?:\/)?(.+)*@(.+)/; + // Groups: extension, domain url, org, repo, release + const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+(?:\/))?([\w.-]+)\/([\w.-]+)@(.+)/; const matches = regex.exec(extension); - matches[2] = (_a = matches[2]) !== null && _a !== void 0 ? _a : 'https://github.com'; - matches[5] = (_b = matches[5]) !== null && _b !== void 0 ? _b : '.'; + matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com'; return await joins('\nadd_extension_from_source', ...matches.splice(1, matches.length), prefix); } exports.parseExtensionSource = parseExtensionSource; diff --git a/src/scripts/ext/cubrid.sh b/src/scripts/ext/cubrid.sh index 72d9370b..36feeaec 100644 --- a/src/scripts/ext/cubrid.sh +++ b/src/scripts/ext/cubrid.sh @@ -43,7 +43,7 @@ add_cubrid_helper() { patch_phpize read -r "${ext}_PREFIX_CONFIGURE_OPTS" <<< "CFLAGS=-Wno-implicit-function-declaration" read -r "${ext}_CONFIGURE_OPTS" <<< "--with-php-config=$(command -v php-config)" - add_extension_from_source "$ext" https://github.com CUBRID "$cubrid_repo" . "$cubrid_branch" extension + add_extension_from_source "$ext" https://github.com CUBRID "$cubrid_repo" "$cubrid_branch" extension restore_phpize fi } diff --git a/src/scripts/ext/firebird.sh b/src/scripts/ext/firebird.sh index 27cbe684..d7585d6b 100644 --- a/src/scripts/ext/firebird.sh +++ b/src/scripts/ext/firebird.sh @@ -12,7 +12,8 @@ add_firebird_helper() { tag="$(php_src_tag)" export PDO_FIREBIRD_CONFIGURE_OPTS="--with-pdo-firebird=$firebird_dir" export PDO_FIREBIRD_LINUX_LIBS="firebird-dev" - add_extension_from_source pdo_firebird https://github.com php php-src ext/pdo_firebird "$tag" extension get + export PDO_FIREBIRD_PATH="ext/pdo_firebird" + add_extension_from_source pdo_firebird https://github.com php php-src "$tag" extension get } add_firebird() { diff --git a/src/scripts/ext/geos.sh b/src/scripts/ext/geos.sh index 54d57b26..c685f866 100644 --- a/src/scripts/ext/geos.sh +++ b/src/scripts/ext/geos.sh @@ -2,7 +2,7 @@ add_geos_helper() { export GEOS_LINUX_LIBS='libgeos-dev' export GEOS_DARWIN_LIBS='geos' - add_extension_from_source geos https://github.com libgeos php-geos . 1.0.0 extension get + add_extension_from_source geos https://github.com libgeos php-geos 1.0.0 extension get } # Function to add geos diff --git a/src/scripts/ext/http.sh b/src/scripts/ext/http.sh index 918ed900..35d25c5b 100644 --- a/src/scripts/ext/http.sh +++ b/src/scripts/ext/http.sh @@ -68,9 +68,9 @@ add_http_helper() { export HTTP_LINUX_LIBS="zlib1g libbrotli-dev libcurl4-openssl-dev libevent-dev libicu-dev libidn2-dev" export HTTP_DARWIN_LIBS="brotli curl icu4c libevent libidn2" if [[ "${version:?}" =~ ${nightly_versions:?} ]]; then - add_extension_from_source http https://github.com m6w6 ext-http . master extension + add_extension_from_source http https://github.com m6w6 ext-http master extension else - add_extension_from_source pecl_http https://pecl.php.net http http . "${ext##*-}" extension pecl + add_extension_from_source pecl_http https://pecl.php.net http http "${ext##*-}" extension pecl fi } diff --git a/src/scripts/ext/oci.sh b/src/scripts/ext/oci.sh index c7e13f96..ec1b9c7c 100644 --- a/src/scripts/ext/oci.sh +++ b/src/scripts/ext/oci.sh @@ -37,8 +37,9 @@ add_oci_helper() { status='Installed and enabled' read -r "${ext}_LINUX_LIBS" <<< "libaio-dev" read -r "${ext}_CONFIGURE_OPTS" <<< "--with-php-config=$(command -v php-config) --with-${ext/_/-}=instantclient,$oracle_client" + read -r "${ext}_PATH" <<< "ext/$ext" patch_phpize - add_extension_from_source "$ext" https://github.com php php-src ext/"$ext" "$(php_src_tag)" extension get + add_extension_from_source "$ext" https://github.com php php-src "$(php_src_tag)" extension get restore_phpize fi } diff --git a/src/scripts/ext/source.sh b/src/scripts/ext/source.sh index 5387dd8d..a575ff7d 100644 --- a/src/scripts/ext/source.sh +++ b/src/scripts/ext/source.sh @@ -5,7 +5,7 @@ parse_args() { up_ext_name=$(echo "$extension" | tr '[:lower:]' '[:upper:]') var="${extension}_${suffix}" up_var="${up_ext_name}_${suffix}" - ! [[ "$suffix" =~ .*PREFIX|LIBS.* ]] && hyp='-' + ! [[ "$suffix" =~ .*PREFIX|LIBS|PATH.* ]] && hyp='-' output=$(echo "${!var} ${!up_var}" | sed "s/, *$hyp/ $hyp/g" | sed -E "s/^,|,$//g") echo "$output" | xargs -n 1 | sort | uniq | xargs } @@ -114,16 +114,16 @@ add_extension_from_source() { url=$2 org=$3 repo=$4 - sub_dir=$5 - release=$6 - prefix=$7 - fetch=${8:-clone} + release=$5 + prefix=$6 + fetch=${7:-clone} slug="$extension-$release" source="$url/$org/$repo" libraries="$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)" opts="$(parse_args "$extension" CONFIGURE_OPTS)" prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)" suffix_opts="$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)" + sub_dir="$(parse_args "$extension" PATH)" step_log "Setup $slug" ( add_devtools phpize >/dev/null 2>&1 diff --git a/src/utils.ts b/src/utils.ts index 82c4f4eb..2591c7e2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -448,12 +448,10 @@ export async function parseExtensionSource( extension: string, prefix: string ): Promise { - // Groups: extension, domain url, org, repo, subdirectory, release - // https://regex101.com/r/P3rJiy/1 - const regex = /(\w+)-(.+:\/\/.+(?:[.:][^/]+)+)?(?:\/)?([^/]+)\/([^/]+)(?:\/)?(.+)*@(.+)/; + // Groups: extension, domain url, org, repo, release + const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+(?:\/))?([\w.-]+)\/([\w.-]+)@(.+)/; const matches = regex.exec(extension) as RegExpExecArray; - matches[2] = matches[2] ?? 'https://github.com'; - matches[5] = matches[5] ?? '.'; + matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com'; return await joins( '\nadd_extension_from_source', ...matches.splice(1, matches.length),