Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bazel php:release target for PECL tgz using generated package.xml #10830

Merged
merged 17 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,10 @@ pkg_files(
],
visibility = ["//pkg:__pkg__"],
)

# Version JSON file for release
zhangskz marked this conversation as resolved.
Show resolved Hide resolved
filegroup(
name = "version_json",
srcs = ["version.json"],
visibility=["//visibility:public"],
)
54 changes: 54 additions & 0 deletions php/ext/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

# Protobuf PHP extension (PECL)
load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix")

filegroup(
zhangskz marked this conversation as resolved.
Show resolved Hide resolved
name = "template_package_xml",
srcs = ["template_package.xml"],
)

pkg_files(
name = "utf8_range_files",
srcs = [
"@utf8_range//:utf8_range_srcs",
"@utf8_range//:LICENSE",
],
)

pkg_files(
name = "protobuf_files",
srcs = glob([
"*.h",
"*.c",
]) + [
"//:LICENSE",
"config.m4",
"wkt.inc",
],
)

pkg_filegroup(
name = "release_files",
srcs = [
":protobuf_files",
":utf8_range_files",
],
)

genrule(
name = "pecl_dist",
zhangskz marked this conversation as resolved.
Show resolved Hide resolved
srcs = [
":release_files",
":template_package_xml",
"//:version_json",
zhangskz marked this conversation as resolved.
Show resolved Hide resolved
],
outs = ["package.xml"],
cmd = " ".join([
"$(location :generate_package_xml.sh)",
"$(location :template_package_xml)",
"$(location //:version_json)",
"$$(echo $(locations :release_files) | sed -e 's; ;,;g')",
"$(location package.xml)"
]),
tools = ["generate_package_xml.sh"],
)
42 changes: 42 additions & 0 deletions php/ext/google/protobuf/generate_package_xml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

template_package_xml=$1
version_json=$2
release_files=$3
out=$4

date=$(date +%Y-%m-%d)
time=$(date +%H:%M:%S)

php_version_json=$(
cat $version_json |
python -c "import json, sys; v=json.load(sys.stdin); print(v.popitem()[1]['languages']['php'])")
php_version_array=(${php_version_json//-rc/ })
api_version=${php_version_array[0]}
if [ ${#php_version_array[@]} -eq 2 ]; then
rc=${php_version_array[1]}
release_version=${api_version}RC${rc}
stability='beta'
else
release_version=${api_version}
stability='stable'
fi

files="\\n"
for file in ${release_files//,/ }; do
name=$(echo $file | sed -e 's;php/ext/google/protobuf/;;')
if [[ $name =~ LICENSE$ ]]; then
role='doc'
else
role='src'
fi
files+=" <file baseinstalldir=\"/\" name=\"${name}\" role=\"${role}\"/>\\n"
done

cat $template_package_xml |
sed -e "s;TEMPLATE_DATE;${date};" |
sed -e "s;TEMPLATE_TIME;${time};" |
sed -e "s;TEMPLATE_PHP_RELEASE;${release_version};" |
sed -e "s;TEMPLATE_PHP_API;${api_version};" |
sed -e "s;TEMPLATE_PHP_STABILITY;${stability};g" |
sed -e "s;TEMPLATE_FILES;${files};" > $out
Loading