mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-07-31 02:37:16 +07:00
Add support for any git repository to compile extension from source
Add support for extensions in a subdirectory to compile from source
This commit is contained in:
@ -17,25 +17,15 @@ export async function addExtensionDarwin(
|
||||
const version_extension: string = version + extension;
|
||||
const [ext_name, ext_version]: string[] = extension.split('-');
|
||||
const ext_prefix = await utils.getExtensionPrefix(ext_name);
|
||||
let matches: RegExpExecArray;
|
||||
|
||||
switch (true) {
|
||||
// match :extension
|
||||
case /^:/.test(ext_name):
|
||||
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
||||
return;
|
||||
// match extensions from GitHub. Do this before checking for semver as
|
||||
// the version may match that as well
|
||||
// match extensions for compiling from source.
|
||||
case /.+-.+\/.+@.+/.test(extension):
|
||||
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension) as RegExpExecArray;
|
||||
add_script += await utils.joins(
|
||||
'\nadd_extension_from_github',
|
||||
ext_name,
|
||||
matches[1],
|
||||
matches[2],
|
||||
matches[3],
|
||||
ext_prefix
|
||||
);
|
||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||
return;
|
||||
// match 5.3blackfire...8.0blackfire
|
||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||
@ -236,25 +226,15 @@ export async function addExtensionLinux(
|
||||
const version_extension: string = version + extension;
|
||||
const [ext_name, ext_version]: string[] = extension.split('-');
|
||||
const ext_prefix = await utils.getExtensionPrefix(ext_name);
|
||||
let matches: RegExpExecArray;
|
||||
|
||||
switch (true) {
|
||||
// Match :extension
|
||||
case /^:/.test(ext_name):
|
||||
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
||||
return;
|
||||
// match extensions from GitHub. Do this before checking for semver as
|
||||
// the version may match that as well
|
||||
// match extensions for compiling from source.
|
||||
case /.+-.+\/.+@.+/.test(extension):
|
||||
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension) as RegExpExecArray;
|
||||
add_script += await utils.joins(
|
||||
'\nadd_extension_from_github',
|
||||
ext_name,
|
||||
matches[1],
|
||||
matches[2],
|
||||
matches[3],
|
||||
ext_prefix
|
||||
);
|
||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||
return;
|
||||
// match 5.3blackfire...8.0blackfire
|
||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||
|
@ -312,23 +312,26 @@ add_libs() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to install extension from a GitHub repository
|
||||
add_extension_from_github() {
|
||||
# Function to install extension from a git repository
|
||||
add_extension_from_source() {
|
||||
extension=$1
|
||||
org=$2
|
||||
repo=$3
|
||||
release=$4
|
||||
prefix=$5
|
||||
slug="$extension-$org/$repo@$release"
|
||||
domain=$2
|
||||
org=$3
|
||||
repo=$4
|
||||
sub_dir=$5
|
||||
release=$6
|
||||
prefix=$7
|
||||
slug="$extension-$release"
|
||||
IFS=' ' read -r -a libs <<< "$(parse_args "$extension" LIBS)"
|
||||
IFS=' ' read -r -a opts <<< "$(parse_args "$extension" CONFIGURE_OPTS)"
|
||||
IFS=' ' read -r -a prefix_opts <<< "$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
|
||||
IFS=' ' read -r -a suffix_opts <<< "$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
|
||||
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$slug" "Click for $extension installation logs"
|
||||
(
|
||||
add_devtools phpize >/dev/null
|
||||
delete_extension "$extension"
|
||||
git clone -q -n https://github.com/"$org"/"$repo" /tmp/"$repo-$release"
|
||||
cd /tmp/"$repo-$release" || exit 1
|
||||
git clone -q -n "$domain/$org/$repo" /tmp/"$repo-$release"
|
||||
cd /tmp/"$repo-$release/$sub_dir" || exit 1
|
||||
git checkout -q "$release"
|
||||
if [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \;| wc -l)" != "0" ]; then
|
||||
git submodule -q update --init --recursive
|
||||
@ -337,11 +340,9 @@ add_extension_from_github() {
|
||||
sudo make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" && sudo make install
|
||||
enable_extension "$extension" "$prefix"
|
||||
else
|
||||
add_log "$cross" "$slug" "Provided repository does not contain a PHP extension"
|
||||
add_log "$cross" "$domain/$org/$repo" "Provided repository does not contain a PHP extension"
|
||||
fi
|
||||
) | sudo tee "/tmp/$extension@$release.log" >/dev/null
|
||||
add_extension_log "$slug" "Installed and enabled"
|
||||
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$slug" "Click to get the logs of compiling $extension"
|
||||
cat "/tmp/$extension@$release.log"
|
||||
)
|
||||
echo "::endgroup::"
|
||||
add_extension_log "$slug" "Installed and enabled from $domain/$org/$repo"
|
||||
}
|
||||
|
22
src/utils.ts
22
src/utils.ts
@ -438,3 +438,25 @@ export async function customPackage(
|
||||
const command: string = await getCommand(os_version, pkg_name);
|
||||
return '\n. ' + script + '\n' + command + version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to extension input for installation from source.
|
||||
*
|
||||
* @param extension
|
||||
*/
|
||||
export async function parseExtensionSource(
|
||||
extension: string,
|
||||
prefix: string
|
||||
): Promise<string> {
|
||||
// Groups: extension, domain url, org, repo, subdirectory, release
|
||||
// https://regex101.com/r/P3rJiy/1
|
||||
const regex = /(\w+)-(.+:\/\/.+(?:[.:][^/]+)+)?(?:\/)?([^/]+)\/([^/]+)(?:\/)?(.+)*@(.+)/;
|
||||
const matches = regex.exec(extension) as RegExpExecArray;
|
||||
matches[2] = matches[2] ?? 'https://github.com';
|
||||
matches[5] = matches[5] ?? '.';
|
||||
return await joins(
|
||||
'\nadd_extension_from_source',
|
||||
...matches.splice(1, matches.length),
|
||||
prefix
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user