diff --git a/Changes.md b/Changes.md index 31df57f5a..f77cae8ab 100644 --- a/Changes.md +++ b/Changes.md @@ -2,6 +2,8 @@ libhxcpp 6.1.0 (unreleased) ------------------------------------------------------------ +* Fixed a checkout of libhxcpp, as haxelib dev and haxelib git install it, defining libhxcpp and hxcpp as 6.0.0 whatever its version: extraParams.hxml named 6.0.0 in every commit, and a release corrected it only in the package it built. So (libhxcpp >= version("6.0.2")) was false in a build against a checkout of 6.1.0, and against the commit a release tag names, and a C++ build against one warned that Haxe generated this code for hxcpp 6.0.0. extraParams.hxml names the version haxelib.json gives in every commit now: a test holds the two together, and a release stops when they differ instead of correcting the line in its package + libhxcpp 6.0.4 ------------------------------------------------------------ diff --git a/RELEASING.md b/RELEASING.md index f083c4d5e..81cf1258b 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -33,13 +33,14 @@ libhxcpp 6.0.0 (unreleased) ------------------------------------------------------------ ``` -`haxelib.json` carries the same version. Each pull request that changes something a user would notice adds its line to this section. +`haxelib.json` carries the same version, and so do the two lines of `extraParams.hxml` that define `libhxcpp` and `hxcpp` for a build. `haxelib dev` and `haxelib git` install a commit as it is, so both files name the version in every commit, and CI on `main` fails when they differ. Each pull request that changes something a user would notice adds its line to this section. ### 2. Make the release commit One commit, and nothing else in it: - set `"version"` in `haxelib.json` to exactly the version being released, for example `6.0.0-beta.1` or `6.0.0`; +- set the same version in the `libhxcpp` and `hxcpp` lines of `extraParams.hxml`; - change the top heading of Changes.md to match it, without "(unreleased)": `libhxcpp 6.0.0-beta.1`. Check it locally before pushing: @@ -60,10 +61,11 @@ In the Actions tab, open **release** and run it on `main` (or on a release branc - it is not run on `main` or a `release/.` branch; - the version in `haxelib.json` is not one haxelib accepts; - the top heading of Changes.md does not name that version; +- `extraParams.hxml` does not define `libhxcpp` and `hxcpp` as that version; - `v` is already released; - CI did not pass on the commit. If a failure is known and unrelated, run it again with **allow_failed_ci** and say why in the release notes. -Otherwise it writes the version into `include/HxcppVersion.h` (`HXCPP_VERSION` and `LIBHXCPP_VERSION`) and `extraParams.hxml` (the `libhxcpp` and `hxcpp` defines, set by a macro rather than `-D` lines, which hxp misreads), builds the build tool and the cppia host for Windows, macOS and Linux, tags `v`, and publishes the release with the top section of Changes.md as its notes. A pre-release version is published as a GitHub pre-release. +Otherwise it writes the version into `include/HxcppVersion.h` (`HXCPP_VERSION` and `LIBHXCPP_VERSION`), builds the build tool and the cppia host for Windows, macOS and Linux, tags `v`, and publishes the release with the top section of Changes.md as its notes. A pre-release version is published as a GitHub pre-release. Then submit the release's zip to haxelib, from an account listed in `contributors` in `haxelib.json`: @@ -75,7 +77,7 @@ haxelib finds the package's `haxelib.json` inside the zip's top folder. Only the ### 4. Open the next cycle -Straight after the release, one commit that sets `haxelib.json` to the version `main` now works toward and adds a new section above the released one: +Straight after the release, one commit that sets `haxelib.json` and `extraParams.hxml` to the version `main` now works toward and adds a new section above the released one: ``` libhxcpp 6.0.1 (unreleased) diff --git a/extraParams.hxml b/extraParams.hxml index 289f5cd92..bfea45675 100644 --- a/extraParams.hxml +++ b/extraParams.hxml @@ -1,3 +1,3 @@ ---macro haxe.macro.Compiler.define("libhxcpp","6.0.0") ---macro haxe.macro.Compiler.define("hxcpp","6.0.0") +--macro haxe.macro.Compiler.define("libhxcpp","6.1.0") +--macro haxe.macro.Compiler.define("hxcpp","6.1.0") --macro hxcpp.IncrementalGcConfig.configure() diff --git a/test/haxelib/check.sh b/test/haxelib/check.sh index 1acb9e1b6..0b2dc35e3 100755 --- a/test/haxelib/check.sh +++ b/test/haxelib/check.sh @@ -132,6 +132,17 @@ haxelib run libhxcpp setup > /dev/null 2>&1 out=$(haxelib run libhxcpp off 2>&1) contains "off without hxcpp says how to install it" "$out" "haxelib install hxcpp" +# This checkout, as haxelib dev and haxelib git install it: no release made +# it, and a build still gets the version in its haxelib.json +checkout="$ROOT" +if command -v cygpath > /dev/null; then + checkout=$(cygpath -m "$ROOT") +fi +version=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$ROOT/haxelib.json") +haxelib dev libhxcpp "$checkout" > /dev/null +out=$(haxe -cp "$WORK" -lib libhxcpp --macro "Probe.run()" --no-output 2>&1) +contains "a checkout gets the version in its haxelib.json" "$out" "hxcpp=$version libhxcpp=$version" + echo if [ "$failures" -eq 0 ]; then echo "all checks passed" diff --git a/test/release_stamp/check.sh b/test/release_stamp/check.sh index 490b71c1d..fc13d9ea9 100755 --- a/test/release_stamp/check.sh +++ b/test/release_stamp/check.sh @@ -19,37 +19,52 @@ check() { fi } -# A release commit of 6.0.1: the version in haxelib.json and the top heading of Changes.md +# The checkout itself. haxelib dev and haxelib git install a commit as it is, +# with no release in between, so the defines extraParams.hxml gives a build +# have to be the version haxelib.json gives in every commit +version=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$ROOT/haxelib.json") +here=$(tr -d '\r' < "$ROOT/extraParams.hxml") +for name in libhxcpp hxcpp; do + check "the checkout's extraParams defines $name as haxelib.json's $version" \ + "$(printf '%s\n' "$here" | grep "Compiler.define(\"$name\",")" "--macro haxe.macro.Compiler.define(\"$name\",\"$version\")" +done + +# A release commit of 6.0.1: the version in haxelib.json, in extraParams.hxml +# and in the top heading of Changes.md sed 's/"version": "[^"]*"/"version": "6.0.1"/' "$ROOT/haxelib.json" > "$WORK/haxelib.json" printf 'libhxcpp 6.0.1\n------------------------------------------------------------\n\n* A change\n' > "$WORK/Changes.md" -cp "$ROOT/extraParams.hxml" "$WORK/" +sed 's/,"[^"]*")/,"6.0.1")/' "$ROOT/extraParams.hxml" > "$WORK/extraParams.hxml" +cp "$WORK/extraParams.hxml" "$WORK/commit.hxml" mkdir -p "$WORK/include" out=$(cd "$WORK" && haxe -p "$ROOT/tools/release" --run Release stamp 2>&1) check "stamp succeeds" "$?" "0" check "stamp reports the version" "$(printf '%s\n' "$out" | tr -d '\r' | head -1)" "version=6.0.1" - -stamped=$(tr -d '\r' < "$WORK/extraParams.hxml") -for name in libhxcpp hxcpp; do - check "extraParams defines $name as the version" \ - "$(printf '%s\n' "$stamped" | grep -c "^--macro haxe.macro.Compiler.define(\"$name\",\"6.0.1\")\$")" "1" -done -check "extraParams keeps no other version" "$(printf '%s\n' "$stamped" | grep -c 'Compiler.define("\(lib\)\?hxcpp","6.0.0")')" "0" - -# Every other line of the checkout's extraParams.hxml, such as the incremental -# collector's configuration macro, reaches the release as it is -while IFS= read -r line; do - case "$line" in - ""|*'Compiler.define("libhxcpp",'*|*'Compiler.define("hxcpp",'*) continue ;; - esac - check "extraParams keeps: $line" "$(printf '%s\n' "$stamped" | grep -cxF -- "$line")" "1" -done < <(tr -d '\r' < "$ROOT/extraParams.hxml") - check "HxcppVersion.h names the version" "$(grep -c '"6.0.1"' "$WORK/include/HxcppVersion.h")" "2" +# The package gets the commit's extraParams.hxml, so the tag and the package agree +check "stamp leaves extraParams.hxml as the commit has it" "$(cmp -s "$WORK/commit.hxml" "$WORK/extraParams.hxml" && echo same)" "same" + +# A release commit that left extraParams.hxml behind, in either line or both, +# or lost a line: the release stops and says which line it needs +refused() { + out=$(cd "$WORK" && haxe -p "$ROOT/tools/release" --run Release check 2>&1) + check "check stops on $1" "$?" "1" + check "and names the line $2 needs" \ + "$(printf '%s\n' "$out" | grep -cF -- "--macro haxe.macro.Compiler.define(\"$2\",\"6.0.1\")")" "1" +} +sed 's/"libhxcpp","6.0.1"/"libhxcpp","6.0.0"/' "$WORK/commit.hxml" > "$WORK/extraParams.hxml" +refused "a libhxcpp define of another version" libhxcpp +sed 's/"hxcpp","6.0.1"/"hxcpp","6.0.0"/' "$WORK/commit.hxml" > "$WORK/extraParams.hxml" +refused "an hxcpp define of another version" hxcpp +sed 's/,"6.0.1")/,"6.0.10")/' "$WORK/commit.hxml" > "$WORK/extraParams.hxml" +refused "a version that only starts the same" libhxcpp +grep -v '"hxcpp",' "$WORK/commit.hxml" > "$WORK/extraParams.hxml" +refused "a missing hxcpp define" hxcpp +{ cat "$WORK/commit.hxml"; echo '--macro haxe.macro.Compiler.define("hxcpp","6.0.0")'; } > "$WORK/extraParams.hxml" +refused "a second hxcpp define, which would be the one a build keeps" hxcpp -# Stamping twice changes nothing more -cp "$WORK/extraParams.hxml" "$WORK/first.hxml" -(cd "$WORK" && haxe -p "$ROOT/tools/release" --run Release stamp > /dev/null 2>&1) -check "a second stamp leaves extraParams as it was" "$(cmp -s "$WORK/first.hxml" "$WORK/extraParams.hxml" && echo same)" "same" +cp "$WORK/commit.hxml" "$WORK/extraParams.hxml" +(cd "$WORK" && haxe -p "$ROOT/tools/release" --run Release check > /dev/null 2>&1) +check "check passes once extraParams.hxml is the commit's again" "$?" "0" exit $failures diff --git a/tools/release/Release.hx b/tools/release/Release.hx index c48c85125..815d4c6fc 100644 --- a/tools/release/Release.hx +++ b/tools/release/Release.hx @@ -8,17 +8,19 @@ using StringTools; The version is the one written in haxelib.json, used as it is: nothing is counted up. The top section of Changes.md has to be headed with the same - version, so a release is always a deliberate commit with its notes. + version, so a release is always a deliberate commit with its notes, and + extraParams.hxml has to define libhxcpp and hxcpp as that version. Usage, from the repository root: haxe -p tools/release --run Release check - Validates the version and the Changes.md heading, then prints - version= and prerelease=. + Validates the version, the Changes.md heading and the defines of + extraParams.hxml, then prints version= and + prerelease=. haxe -p tools/release --run Release stamp - Does what check does, then writes include/HxcppVersion.h and - extraParams.hxml for the version. + Does what check does, then writes include/HxcppVersion.h for the + version. haxe -p tools/release --run Release notes Writes the body of the top Changes.md section to . @@ -67,6 +69,25 @@ class Release if (heading != expected) throw new ReleaseError('The top section of Changes.md is headed "$heading"; a release of $version needs "$expected"'); + // extraParams.hxml gives every build that uses the library its libhxcpp + // and hxcpp defines: -D libhxcpp=, so code can tell it is on + // libhxcpp and compare with version("x.y.z"), and -D hxcpp, so code that + // checks for hxcpp works the same whichever name it asked for. They are + // set by a macro rather than -D lines: tools such as hxp take the line + // before a library's -D line in `haxelib path` output as its path. + // The commit has to name the version there itself, and nothing is written + // into the package for it: haxelib dev and haxelib git install a commit + // as it is, so a line a release alone corrected was wrong in every + // checkout, and in the commit its own tag names. + final lines = [for (line in File.getContent("extraParams.hxml").replace("\r", "").split("\n")) line.trim()]; + for (name in ["libhxcpp", "hxcpp"]) + { + final needed = '--macro haxe.macro.Compiler.define("$name","$version")'; + final defining = [for (line in lines) if (line.startsWith('--macro haxe.macro.Compiler.define("$name",')) line]; + if (defining.length != 1 || defining[0] != needed) + throw new ReleaseError('extraParams.hxml does not define $name as $version and nothing else; a release of $version needs the one line $needed'); + } + return version; } @@ -92,24 +113,6 @@ class Release '#endif', '' ].join("\n")); - - // Builds that use the library get -D libhxcpp=, so code can tell - // it is on libhxcpp and compare with version("x.y.z"), and -D hxcpp, so code - // that checks for hxcpp works the same whether it asked for hxcpp or libhxcpp. - // A macro rather than -D lines: tools such as hxp take the line before a - // library's -D line in `haxelib path` output as its path. - // Only those two lines are rewritten: the file's other lines, such as the - // incremental collector's configuration macro, ship as they are. - File.saveContent("extraParams.hxml", stampedExtraParams(File.getContent("extraParams.hxml"), version)); - } - - static final DEFINE_LINE = ~/^--macro haxe\.macro\.Compiler\.define\("(libhxcpp|hxcpp)",/; - - static function stampedExtraParams(current:String, version:String):String - { - final defines = [for (name in ["libhxcpp", "hxcpp"]) '--macro haxe.macro.Compiler.define("$name","$version")']; - final kept = [for (line in current.replace("\r", "").split("\n")) if (line.trim() != "" && !DEFINE_LINE.match(line.trim())) line]; - return defines.concat(kept).join("\n") + "\n"; } // The first section of Changes.md: a heading line underlined with dashes,