Skip to content

Commit

Permalink
civimix-schema - Split off major-version from core. Keep 5.x.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
totten committed Jan 14, 2025
1 parent 129c65a commit c1b30b0
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 65 deletions.
2 changes: 1 addition & 1 deletion CRM/Core/I18n/SchemaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Upgrade/Incremental/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 7 additions & 8 deletions mixin/lib/pathload.index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -18,7 +20,4 @@
}, $version6);

// Register [email protected]
\pathload()->addSearchItem('civimix-schema', $version5, __DIR__ . '/civimix-schema');

// (Optional) Register [email protected]
// \pathload()->addSearchItem('civimix-schema', $version6, __DIR__ . '/civimix-schema');
\pathload()->addSearchItem('civimix-schema@5', $version5, __DIR__ . '/civimix-schema');
136 changes: 81 additions & 55 deletions tools/mixin/bin/build-lib
Original file line number Diff line number Diff line change
@@ -1,70 +1,96 @@
#!/usr/bin/env bash

#!/usr/bin/env php
<?php

## Take the contents of 'mixin/lib/' and export reusable library files.

###############################################################################
## Bootstrap

## Determine the absolute path of the directory with the file
## usage: absdirname <file-path>
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 <output-dir>"
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 <output-dir>\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");

0 comments on commit c1b30b0

Please sign in to comment.