summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yaml43
-rw-r--r--.gitignore1
-rw-r--r--README.md59
-rw-r--r--composer.json13
-rw-r--r--package.xml25
-rw-r--r--php_rpminfo.h2
-rw-r--r--rpminfo.c74
-rw-r--r--rpminfo.stub.php7
-rw-r--r--rpminfo_arginfo.h20
-rw-r--r--tests/004-constants.phpt2
-rw-r--r--tests/015-rpmmacro.phpt25
11 files changed, 254 insertions, 17 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index b0bc6f8..77aab63 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -11,7 +11,7 @@ jobs:
matrix:
distro: ['rockylinux']
el: [8]
- php: ['8.0', '8.2', 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3']
+ php: ['8.0', '8.2', 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3', 'remi-8.4']
container:
image: ${{ matrix.distro }}:${{ matrix.el }}
steps:
@@ -43,7 +43,7 @@ jobs:
matrix:
distro: ['rockylinux']
el: [9]
- php: [0, '8.1', '8.2', 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3']
+ php: [0, '8.2', '8.3', 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3', 'remi-8.4']
container:
image: ${{ matrix.distro }}:${{ matrix.el }}
steps:
@@ -69,12 +69,47 @@ jobs:
TEST_PHP_ARGS: '-q --show-diff'
run: |
make test
+ Linux_EL10:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ distro: ['almalinux']
+ el: [10]
+ php: [0, 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3', 'remi-8.4']
+ container:
+ image: ${{ matrix.distro }}:${{ matrix.el }}
+ steps:
+ - name: Install gzip
+ run: |
+ dnf install -y "gzip"
+ - name: Checkout
+ uses: actions/checkout@v4
+ - name: Setup PHP module
+ if: ${{ matrix.php }}
+ run: |
+ dnf install -y "https://rpms.remirepo.net/enterprise/remi-release-${{ matrix.el }}.rpm"
+ dnf module enable -y "php:${{ matrix.php }}"
+ - name: Install PHP
+ run: |
+ dnf install -y "php" "php-devel" "rpm-devel"
+ - name: Show PHP version
+ run: php -v
+ - name: Make php-rpminfo
+ run: |
+ phpize
+ ./configure
+ make -j"$(nproc)"
+ - name: Test php-rpminfo
+ env:
+ TEST_PHP_ARGS: '-q --show-diff'
+ run: |
+ make test
Linux_Fedora:
runs-on: ubuntu-latest
strategy:
matrix:
- fedora: [39, 40, 41]
- php: [0, 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3']
+ fedora: [41, 42]
+ php: [0, 'remi-8.0', 'remi-8.1', 'remi-8.2', 'remi-8.3', 'remi-8.4']
container:
image: fedora:${{ matrix.fedora }}
steps:
diff --git a/.gitignore b/.gitignore
index 54b9e13..f9067ad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,7 @@ modules
run-tests.php
run-tests.log
tmp-php.ini
+sendpackagist
# Archives
rpminfo-*.tgz
diff --git a/README.md b/README.md
index bea5c81..9d19947 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+[![CI](https://github.com/remicollet/rpminfo/actions/workflows/ci.yaml/badge.svg)](https://github.com/remicollet/rpminfo/actions/workflows/ci.yaml)
+
# RPM information extension for PHP
Retrieve RPM information from PHP code using librpm.
@@ -23,6 +25,15 @@ From the sources tree
$ make
$ make test
+From https://pecl.php.net/ using pecl command
+
+ $ pecl install rpminfo
+
+From https://packagist.org/ using PHP Installer for Extensions
+
+ $ pie install remi/rpminfo
+
+
----
# Usage
@@ -42,7 +53,7 @@ Allow to compare 2 EVR (epoch:version-release) strings. The return value is < 0
## rpminfo
- array rpminfo(string path [, bool full [, string &error]]);
+ rpminfo(string path [, bool full [, string &error]]): array;
Retrieve information from a rpm file, reading its metadata.
If given `error` will be used to store error message instead of raising a warning.
@@ -86,7 +97,7 @@ The return value is a hash table, or false if it fails.
## rpmdbinfo
- array rpmdbinfo(string path [, bool full ]);
+ rpmdbinfo(string path [, bool full ]): array;
Retrieve information from rpm database about an installed package.
The return value is an array of hash tables, or false if it fails.
@@ -182,6 +193,50 @@ The return value is an array of hash tables, or false if it fails.
)
)
+## rpmexpand
+
+ rpmexpand($text): string
+
+Retrieve expanded value of a RPM macro
+
+ $ php -a
+ php > var_dump(rpmexpand("%{?fedora:Fedora %{fedora}}%{?rhel:Enterprise Linux %{rhel}}"));
+ string(9) "Fedora 41"
+
+## rpmexpandnumeric
+
+ rpmexpandnumeric($text): int
+
+Retrieve numerical value of a RPM macro
+
+ $ php -a
+ php > var_dump(rpmexpandnumeric("%__isa_bits"));
+ int(64)
+
+## rpmdefine
+
+ rpmdefine($text): bool
+
+Define or change a RPM macro value.
+
+For example, can be used to set the Database path and backend
+
+ $ mock -r almalinux-8-x86_64 init
+ ...
+ $ mock -r fedora-41-x86_64 init
+ ...
+ $ php -a
+ php > // use an old database (bdb) from an EL-8 chroot
+ php > rpmdefine("_dbpath /var/lib/mock/almalinux-8-x86_64/root/var/lib/rpm");
+ php > rpmdefine("_db_backend bdb_ro");
+ php > var_dump(rpmdbinfo("almalinux-release")[0]["Summary"]);
+ string(22) "AlmaLinux release file"
+ php > // use a new database (sqlite) from a Fedora-41 chroot
+ php > rpmdefine("_dbpath /var/lib/mock/fedora-41-x86_64/root/usr/lib/sysimage/rpm");
+ php > rpmdefine("_db_backend sqlite");
+ php > var_dump(rpmdbinfo("fedora-release")[0]["Summary"]);
+ string(20) "Fedora release files"
+
----
# LICENSE
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..a76d2b7
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,13 @@
+{
+ "name": "remi/rpminfo",
+ "type": "php-ext",
+ "license": "PHP-3.01",
+ "description": "RPM information",
+ "require": {
+ "php": ">= 8.0.0"
+ },
+ "php-ext": {
+ "extension-name": "rpminfo",
+ "configure-options": []
+ }
+}
diff --git a/package.xml b/package.xml
index 9f29bbe..27831c9 100644
--- a/package.xml
+++ b/package.xml
@@ -13,10 +13,10 @@ Documentation: https://www.php.net/rpminfo
<email>remi@php.net</email>
<active>yes</active>
</lead>
- <date>2024-09-03</date>
+ <date>2024-12-19</date>
<version>
- <release>1.1.2dev</release>
- <api>1.1.0</api>
+ <release>1.2.1dev</release>
+ <api>1.2.0</api>
</version>
<stability>
<release>stable</release>
@@ -24,7 +24,7 @@ Documentation: https://www.php.net/rpminfo
</stability>
<license uri="https://www.php.net/license/3_01.txt" filesource="LICENSE">PHP-3.01</license>
<notes><![CDATA[
--
+-
]]></notes>
<contents>
<dir name="/">
@@ -57,6 +57,7 @@ Documentation: https://www.php.net/rpminfo
<file name="012-rpmaddtag.phpt" role="test"/>
<file name="013-rpmdbsearch-error.phpt" role="test"/>
<file name="014-stream.phpt" role="test"/>
+ <file name="015-rpmmacro.phpt" role="test"/>
<file name="bidon.rpm" role="test"/>
<file name="bidon-src.rpm" role="test"/>
</dir>
@@ -76,6 +77,22 @@ Documentation: https://www.php.net/rpminfo
<extsrcrelease/>
<changelog>
<release>
+ <date>2024-12-19</date>
+ <version>
+ <release>1.2.0</release>
+ <api>1.2.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="https://www.php.net/license/3_01.txt" filesource="LICENSE">PHP-3.01</license>
+ <notes><![CDATA[
+- add rpmexpand, rpmexpandnumeric to retrieve rpm macro value
+- add rpmdefine to set rpm macro value
+ ]]></notes>
+ </release>
+ <release>
<date>2024-09-03</date>
<version>
<release>1.1.1</release>
diff --git a/php_rpminfo.h b/php_rpminfo.h
index 6f54208..98b8439 100644
--- a/php_rpminfo.h
+++ b/php_rpminfo.h
@@ -22,7 +22,7 @@
extern zend_module_entry rpminfo_module_entry;
#define phpext_rpminfo_ptr &rpminfo_module_entry
-#define PHP_RPMINFO_VERSION "1.1.2-dev"
+#define PHP_RPMINFO_VERSION "1.2.1-dev"
#define PHP_RPMINFO_AUTHOR "Remi Collet"
#define PHP_RPMINFO_LICENSE "PHP-3.01"
diff --git a/rpminfo.c b/rpminfo.c
index 55a5351..ae8b8e7 100644
--- a/rpminfo.c
+++ b/rpminfo.c
@@ -30,6 +30,7 @@
#include <rpm/rpmio.h>
#include <rpm/rpmlib.h>
#include <rpm/rpmts.h>
+#include <rpm/rpmmacro.h>
#include "php_rpminfo.h"
@@ -69,6 +70,13 @@ static rpmdb rpminfo_getdb(void) {
return RPMINFO_G(db);
}
+static void rpminfo_closedb(void) {
+ if (RPMINFO_G(db)) {
+ rpmtsCloseDB(RPMINFO_G(ts));
+ RPMINFO_G(db) = NULL;
+ }
+}
+
static void rpm_header_to_zval(zval *return_value, Header h, zend_bool full)
{
HeaderIterator hi;
@@ -867,6 +875,66 @@ PHP_FUNCTION(rpmgetsymlink)
}
/* }}} */
+/* {{{ proto array rpmexpand(string $text): string
+ Expand macro in text */
+PHP_FUNCTION(rpmexpand)
+{
+ char *text, *result;
+ size_t len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
+ (void)rpminfo_getts(); /* read config files */
+
+ result = rpmExpand(text, NULL);
+ RETVAL_STRING(result);
+ free(result);
+}
+/* }}} */
+
+/* {{{ proto array rpmexpandnumeric(string $text): int
+ Expand macro in text */
+PHP_FUNCTION(rpmexpandnumeric)
+{
+ char *text;
+ size_t len;
+ int result;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
+ (void)rpminfo_getts(); /* read config files */
+
+ result = rpmExpandNumeric(text);
+
+ RETURN_LONG(result);
+}
+/* }}} */
+
+/* {{{ proto array rpmdefine(string $macro): bool
+ Define a new macro */
+PHP_FUNCTION(rpmdefine)
+{
+ char *macro;
+ size_t len;
+ int result;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &macro, &len) == FAILURE) {
+ RETURN_THROWS();
+ }
+
+ (void)rpminfo_getts(); /* read config files */
+
+ rpminfo_closedb(); /* Close the DB to allow path change */
+
+ result = rpmDefineMacro(NULL, macro, RMIL_GLOBAL);
+
+ RETURN_BOOL(result == 0);
+}
+/* }}} */
/* {{{ PHP_MINIT_FUNCTION
*/
@@ -940,10 +1008,8 @@ PHP_RINIT_FUNCTION(rpminfo)
PHP_RSHUTDOWN_FUNCTION(rpminfo)
{
if (RPMINFO_G(ts)) {
- if (RPMINFO_G(db)) {
- rpmtsCloseDB(RPMINFO_G(ts));
- RPMINFO_G(db) = NULL;
- }
+ rpminfo_closedb();
+
rpmtsFree(RPMINFO_G(ts));
RPMINFO_G(ts) = NULL;
}
diff --git a/rpminfo.stub.php b/rpminfo.stub.php
index aa87215..026df4b 100644
--- a/rpminfo.stub.php
+++ b/rpminfo.stub.php
@@ -13,3 +13,10 @@ function rpminfo(string $path, bool $full = false, ?string &$error = null): Arra
function rpmvercmp(string $evr1, string $evr2, ?string $operator = null): int|bool {}
function rpmgetsymlink(string $path, string $name): string|null {}
+
+function rpmexpand(string $text): string {}
+
+function rpmexpandnumeric(string $text): int {}
+
+function rpmdefine(string $macro): bool {}
+
diff --git a/rpminfo_arginfo.h b/rpminfo_arginfo.h
index 0764f6f..6db4fed 100644
--- a/rpminfo_arginfo.h
+++ b/rpminfo_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 6b129e53b21eb21027683874775c2cdb7d1d485d */
+ * Stub hash: dc980a56084190700162f5a8c70b54fcdbc30ced */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmaddtag, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, rpmtag, IS_LONG, 0)
@@ -34,6 +34,18 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmgetsymlink, 0, 2, IS_STRING,
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmexpand, 0, 1, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmexpandnumeric, 0, 1, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rpmdefine, 0, 1, _IS_BOOL, 0)
+ ZEND_ARG_TYPE_INFO(0, macro, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
ZEND_FUNCTION(rpmaddtag);
ZEND_FUNCTION(rpmdbinfo);
@@ -41,6 +53,9 @@ ZEND_FUNCTION(rpmdbsearch);
ZEND_FUNCTION(rpminfo);
ZEND_FUNCTION(rpmvercmp);
ZEND_FUNCTION(rpmgetsymlink);
+ZEND_FUNCTION(rpmexpand);
+ZEND_FUNCTION(rpmexpandnumeric);
+ZEND_FUNCTION(rpmdefine);
static const zend_function_entry ext_functions[] = {
@@ -50,5 +65,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(rpminfo, arginfo_rpminfo)
ZEND_FE(rpmvercmp, arginfo_rpmvercmp)
ZEND_FE(rpmgetsymlink, arginfo_rpmgetsymlink)
+ ZEND_FE(rpmexpand, arginfo_rpmexpand)
+ ZEND_FE(rpmexpandnumeric, arginfo_rpmexpandnumeric)
+ ZEND_FE(rpmdefine, arginfo_rpmdefine)
ZEND_FE_END
};
diff --git a/tests/004-constants.phpt b/tests/004-constants.phpt
index 397c97f..18104cc 100644
--- a/tests/004-constants.phpt
+++ b/tests/004-constants.phpt
@@ -8,5 +8,5 @@ var_dump(RPMVERSION);
?>
Done
--EXPECTF--
-string(%d) "4.%s"
+string(%d) "%s"
Done
diff --git a/tests/015-rpmmacro.phpt b/tests/015-rpmmacro.phpt
new file mode 100644
index 0000000..794cabf
--- /dev/null
+++ b/tests/015-rpmmacro.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Check for rpmdefine, rpmexpand, rpmexpandnumeric
+--SKIPIF--
+<?php if (!extension_loaded("rpminfo")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(is_dir(rpmexpand("%{_dbpath}")));
+
+var_dump(rpmexpandnumeric("%__isa_bits") === PHP_INT_SIZE * 8);
+var_dump(is_int(rpmexpandnumeric("0%{?fedora}%{?rhel}")));
+
+$name = "_my_test_macro_for_rpminfo_";
+$val = __FILE__;
+var_dump(rpmexpand("%$name") === "%$name" );
+var_dump(rpmdefine("$name $val"));
+var_dump(rpmexpand("%$name") === __FILE__);
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+