From 6c913c6778e105feede1ad4792b3a024c0926e5a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 13 Jan 2025 23:11:28 -0800 Subject: [PATCH] civimix-schema - Split off major-version from core. Keep 5.x. Before: * 'mixin/lib/civimix-schema' is numbered `5.x.x` * `mixin/lib/civimix-schema` is strictly pegged to the 'civicrm-core' After: * `mixin/lib/civimix-schema@5` is numbered `5.x.x.` * `mixin/lib/civimix-schema@5` is partially released from the numbering of `civicrm-core`. Comments: The version will still increment automatically (month-to-month; in parallel with core), but it will stay within 5.x. This is because it's supposed to be strictly SemVer, and we haven't actually made any major changes to it, so moving to 6.x would be a big hassle. --- CRM/Core/I18n/SchemaStructure.php | 2 +- CRM/Upgrade/Incremental/Base.php | 2 +- .../pathload.main.php | 0 .../src/AutomaticUpgrader.php | 0 .../src/CiviMixSchema.php | 0 .../src/DAO.php | 0 .../src/SchemaHelper.php | 0 .../src/SchemaHelperInterface.php | 0 .../src/SqlGenerator.php | 0 mixin/lib/pathload.index.php | 15 +- tools/mixin/bin/build-lib | 136 +++++++++++------- 11 files changed, 90 insertions(+), 65 deletions(-) rename mixin/lib/{civimix-schema => civimix-schema@5}/pathload.main.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/AutomaticUpgrader.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/CiviMixSchema.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/DAO.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/SchemaHelper.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/SchemaHelperInterface.php (100%) rename mixin/lib/{civimix-schema => civimix-schema@5}/src/SqlGenerator.php (100%) diff --git a/CRM/Core/I18n/SchemaStructure.php b/CRM/Core/I18n/SchemaStructure.php index 0b6453032daf..fe358ec65c09 100644 --- a/CRM/Core/I18n/SchemaStructure.php +++ b/CRM/Core/I18n/SchemaStructure.php @@ -26,7 +26,7 @@ public static function &columns() { if (!$result) { $result = []; global $civicrm_root; - $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema/src/SqlGenerator.php"; + $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema@5/src/SqlGenerator.php"; foreach (\Civi\Schema\EntityRepository::getEntities() as $entity) { if (empty($entity['getFields'])) { continue; diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 87ae6c5ed314..a9fa65348a08 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -404,7 +404,7 @@ public static function checkFKExists($table_name, $constraint_name) { public static function alterSchemaField($ctx, string $entityName, string $fieldName, array $fieldSpec): bool { $tableName = Civi::entity($entityName)->getMeta('table'); global $civicrm_root; - $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema/src/SqlGenerator.php"; + $sqlGenerator = require "$civicrm_root/mixin/lib/civimix-schema@5/src/SqlGenerator.php"; $fieldSql = $sqlGenerator::generateFieldSql($fieldSpec); if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists($tableName, $fieldName, FALSE)) { return self::alterColumn($ctx, $tableName, $fieldName, $fieldSql, !empty($fieldSpec['localizable'])); diff --git a/mixin/lib/civimix-schema/pathload.main.php b/mixin/lib/civimix-schema@5/pathload.main.php similarity index 100% rename from mixin/lib/civimix-schema/pathload.main.php rename to mixin/lib/civimix-schema@5/pathload.main.php diff --git a/mixin/lib/civimix-schema/src/AutomaticUpgrader.php b/mixin/lib/civimix-schema@5/src/AutomaticUpgrader.php similarity index 100% rename from mixin/lib/civimix-schema/src/AutomaticUpgrader.php rename to mixin/lib/civimix-schema@5/src/AutomaticUpgrader.php diff --git a/mixin/lib/civimix-schema/src/CiviMixSchema.php b/mixin/lib/civimix-schema@5/src/CiviMixSchema.php similarity index 100% rename from mixin/lib/civimix-schema/src/CiviMixSchema.php rename to mixin/lib/civimix-schema@5/src/CiviMixSchema.php diff --git a/mixin/lib/civimix-schema/src/DAO.php b/mixin/lib/civimix-schema@5/src/DAO.php similarity index 100% rename from mixin/lib/civimix-schema/src/DAO.php rename to mixin/lib/civimix-schema@5/src/DAO.php diff --git a/mixin/lib/civimix-schema/src/SchemaHelper.php b/mixin/lib/civimix-schema@5/src/SchemaHelper.php similarity index 100% rename from mixin/lib/civimix-schema/src/SchemaHelper.php rename to mixin/lib/civimix-schema@5/src/SchemaHelper.php diff --git a/mixin/lib/civimix-schema/src/SchemaHelperInterface.php b/mixin/lib/civimix-schema@5/src/SchemaHelperInterface.php similarity index 100% rename from mixin/lib/civimix-schema/src/SchemaHelperInterface.php rename to mixin/lib/civimix-schema@5/src/SchemaHelperInterface.php diff --git a/mixin/lib/civimix-schema/src/SqlGenerator.php b/mixin/lib/civimix-schema@5/src/SqlGenerator.php similarity index 100% rename from mixin/lib/civimix-schema/src/SqlGenerator.php rename to mixin/lib/civimix-schema@5/src/SqlGenerator.php diff --git a/mixin/lib/pathload.index.php b/mixin/lib/pathload.index.php index 3e2f211e9f5a..c3602022f2e3 100644 --- a/mixin/lib/pathload.index.php +++ b/mixin/lib/pathload.index.php @@ -5,11 +5,13 @@ // // pathload()->addSearchDir(__DIR__ . '/lib'); // -// However, that would detect version#'s from the filenames. In this folder, -// we want all subprojects to have the same version-number as the main -// project. It would be quite inconvenient to rename them every month. +// However, that would detect version#'s from the filenames. While that +// convention is handy for downstreams (using backports), it can be annoying +// here (as canonical source). It would be inconvenient to have to rename +// the canonical files/folders whenever we make an edit. // -// So instead, we use `addSearchItem()` and register with explicit versions. +// `addSearchItem()` allows us to register with a programmatic +// version-number -- so we don't have to manually set the number. $version6 = \CRM_Utils_System::version() . '.1'; /* Higher priority than contrib copies of same version... */ $version5 = preg_replace_callback(';^6\.(\d+)\.;', function ($m) { @@ -18,7 +20,4 @@ }, $version6); // Register civimix-schema@5.x -\pathload()->addSearchItem('civimix-schema', $version5, __DIR__ . '/civimix-schema'); - -// (Optional) Register civimix-schema@6.x -// \pathload()->addSearchItem('civimix-schema', $version6, __DIR__ . '/civimix-schema'); +\pathload()->addSearchItem('civimix-schema', $version5, __DIR__ . '/civimix-schema@5'); diff --git a/tools/mixin/bin/build-lib b/tools/mixin/bin/build-lib index b97d6ea30ce8..7f1b55c63ccc 100755 --- a/tools/mixin/bin/build-lib +++ b/tools/mixin/bin/build-lib @@ -1,70 +1,96 @@ -#!/usr/bin/env bash - +#!/usr/bin/env php + -function absdirname() { - pushd $(dirname $0) >> /dev/null - pwd - popd >> /dev/null -} -BINDIR=$(absdirname "$0") -set -e - -############################################################################### - -function getCiviVer() { - pushd "$1" >> /dev/null - if [ -f xml/version.xml ]; then - ## Works in any git-based build, even if gencode hasn't run yet. - php -r 'echo simplexml_load_file("xml/version.xml")->version_no;' - else - ## works in any tar-based build. - php -r 'require "civicrm-version.php"; $a = civicrmVersion(); echo $a["version"];' - fi - popd >> /dev/null +/** + * Get the CiviCRM version from the specified directory. + * + * @param string $directory + * @return string|null + */ +function getCiviVer(string $directory): ?string { + $version = NULL; + + if (file_exists($directory . '/xml/version.xml')) { + $version = simplexml_load_file($directory . '/xml/version.xml')->version_no; + } + elseif (file_exists($directory . '/civicrm-version.php')) { + require $directory . '/civicrm-version.php'; + $versionArray = civicrmVersion(); + $version = $versionArray['version'] ?? NULL; + } + + return $version; } +/** + * Execute a PHAR command. + * + * @param string $command + * @return void + */ +function executePhar(string $pwd, string $command): void { + $cmd = 'cd ' . escapeshellarg($pwd) . ' && '; + $cmd .= "php -d phar.readonly=0 `which phar` $command"; + // echo "$cmd\n"; + + passthru($cmd, $result); + if ($result !== 0) { + throw new \RuntimeException("Failed to execute command: $cmd"); + } +} -function PHAR() { - php -d phar.readonly=0 `which phar` "$@" +/** + * Take a source folder and generate a PHAR. + * + * @param string $src + * @param string $outputPhar + * @return void + */ +function buildLib(string $src, string $outputPhar): void { + echo "\n====================================\n"; + echo "Read $src\n"; + echo "Create $outputPhar\n"; + echo "\n"; + + if (file_exists($outputPhar)) { + unlink($outputPhar); + } + + $stubFile = escapeshellarg("$GLOBALS[toolMix]/src/empty-stub.php"); + $outputPhar = escapeshellarg($outputPhar); + executePhar($src, "pack -f $outputPhar -s $stubFile -i '.php$' ."); + + // Or for concatenated PHP format: + // php "$CIVI_CORE/scripts/concat-php.php" pathload.main.php $( find src -name '*.php' ) >"$OUTPUT_PHP" } ############################################################################### +## Setup -TOOLMIX=$(dirname "$BINDIR") -CIVI_CORE=$(dirname $(dirname "$TOOLMIX")) -OUTPUT="$1" -VERSION=$(getCiviVer "$CIVI_CORE") - -if [ -z "$OUTPUT" ]; then - echo 2>&1 "usage: $0 " - echo 2>&1 "example: $0 /tmp/civimix" - exit 1 -fi +$toolMix = dirname(__DIR__); +$civiCore = dirname(dirname($toolMix)); +$output = $argv[1] ?? NULL; +$version = getCiviVer($civiCore); -if [ ! -d "$OUTPUT" ]; then - mkdir "$OUTPUT" -fi - -for PACKAGE in civimix-schema ; do - - SRC="${CIVI_CORE}/mixin/lib/${PACKAGE}" - OUTPUT_PHAR="${OUTPUT}/${PACKAGE}@${VERSION}.phar" - #OUTPUT_PHP="${OUTPUT}/${PACKAGE}@${VERSION}.php" - - echo "Read $SRC" - echo "Create $OUTPUT_PHAR" +if (empty($output)) { + fwrite(STDERR, "usage: build-lib \n"); + fwrite(STDERR, "example: build-lib /tmp/civimix\n"); + exit(1); +} - [ -f "$OUTPUT_PHAR" ] && rm -f "$OUTPUT_PHAR" || true - #[ -f "$OUTPUT_PHP" ] && rm -f "$OUTPUT_PHP" || true +if (!is_dir($output)) { + mkdir($output, 0755, TRUE); +} - (cd "$SRC" ; PHAR pack -f "$OUTPUT_PHAR" -s "$TOOLMIX/src/empty-stub.php" -i '\.php$' . ) - #php "$CIVI_CORE/scripts/concat-php.php" pathload.main.php $( find src -name '*.php' ) >"$OUTPUT_PHP" +############################################################################### +## Build rules -done +/* Tracked core version up until 5.83. After 6.0 split, this stayed on 5.x.*/ +$civimixSchemaVer = preg_replace_callback(';^6\.(\d+)\.;', function ($m) { + return '5.' . (83 + $m[1]) . '.'; +}, getCiviVer($civiCore)); +buildLib("$civiCore/mixin/lib/civimix-schema@5", "$output/civimix-schema@$civimixSchemaVer.phar");