diff --git a/.circleci/config.yml b/.circleci/config.yml index 58bcb2b9fb81..5d3db526ad41 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -182,17 +182,12 @@ commands: # -------------------------------------------------------------------------- # Build Commands - setup_prerelease_commit_hash: + setup_prerelease: steps: - run: - name: Store commit hash and prerelease + name: Store prerelease suffix command: | - if [[ $CIRCLE_BRANCH == release || -n $CIRCLE_TAG ]]; then - echo -n > prerelease.txt; - else - date -u +"nightly.%Y.%-m.%-d" > prerelease.txt; - fi - echo -n "$CIRCLE_SHA1" > commit_hash.txt + "scripts/prerelease_suffix.sh" nightly "$CIRCLE_TAG" > prerelease.txt install_and_check_minimum_requirements: parameters: @@ -1006,6 +1001,7 @@ jobs: <<: *base_ubuntu2404_xlarge steps: - build + - run: cat prerelease.txt # x64 ASAN build, for testing for memory related bugs b_ubu_asan: &b_ubu_asan @@ -1115,7 +1111,7 @@ jobs: <<: *base_ubuntu_clang_large steps: - checkout - - setup_prerelease_commit_hash + - setup_prerelease - run_build_ossfuzz - persist_ossfuzz_executables_to_workspace - matrix_notify_failure_unless_pr @@ -1225,7 +1221,7 @@ jobs: <<: *base_ubuntu2404_small steps: - checkout - - setup_prerelease_commit_hash + - setup_prerelease - run: name: Install build system dependencies command: | diff --git a/docs/conf.py b/docs/conf.py index 3f7dc3e350ac..e71535b9a786 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -126,10 +126,12 @@ def get_github_username_repo(url): with open('../CMakeLists.txt', 'r', encoding='utf8') as f: version = re.search('PROJECT_VERSION "([^"]+)"', f.read()).group(1) # The full version, including alpha/beta/rc tags. -if not os.path.isfile('../prerelease.txt') or os.path.getsize('../prerelease.txt') == 0: +if os.path.isfile('../prerelease.txt') and os.path.getsize('../prerelease.txt') == 0: release = version +elif os.path.isfile('../prerelease.txt'): + with open('../prerelease.txt', 'r', encoding='utf8') as prerelease_file: + release = version + '-' + prerelease_file.read() else: - # This is a prerelease version release = version + '-develop' # The language for content autogenerated by Sphinx. Refer to documentation diff --git a/scripts/build.sh b/scripts/build.sh index 5d7765e6b27d..33d7bb7c5104 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -10,8 +10,10 @@ else BUILD_TYPE="$1" fi -if [[ $(git tag --points-at HEAD 2> /dev/null) == v* ]]; then - touch "${ROOTDIR}/prerelease.txt" +# Intentionally not using prerelease_suffix.sh here. We do not want lingering prerelease.txt in +# dev builds, accidentally overriding version when someone runs the build manually. +if [[ $(git tag --points-at HEAD 2> /dev/null) =~ ^v[0-9.]+$ ]]; then + echo -n > prerelease.txt fi mkdir -p "$BUILDDIR" diff --git a/scripts/ci/build.sh b/scripts/ci/build.sh index 1acec5a20113..b7f7e92f5708 100755 --- a/scripts/ci/build.sh +++ b/scripts/ci/build.sh @@ -9,23 +9,12 @@ prerelease_source="${1:-ci}" cd "${ROOTDIR}" -if [[ $CIRCLE_BRANCH == release || -n $CIRCLE_TAG || -n $FORCE_RELEASE ]]; then - echo -n > prerelease.txt -else - # Use last commit date rather than build date to avoid ending up with builds for - # different platforms having different version strings (and therefore producing different bytecode) - # if the CI is triggered just before midnight. - TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="${prerelease_source}.%cd" > prerelease.txt -fi - -if [[ -n $CIRCLE_SHA1 ]]; then - echo -n "$CIRCLE_SHA1" > commit_hash.txt -fi +"${ROOTDIR}/scripts/prerelease_suffix.sh" "$prerelease_source" "$CIRCLE_TAG" > prerelease.txt mkdir -p build cd build -[[ -n $COVERAGE && $CIRCLE_BRANCH != release && -z $CIRCLE_TAG ]] && CMAKE_OPTIONS="$CMAKE_OPTIONS -DCOVERAGE=ON" +[[ -n $COVERAGE && -z $CIRCLE_TAG ]] && CMAKE_OPTIONS="$CMAKE_OPTIONS -DCOVERAGE=ON" # shellcheck disable=SC2086 cmake .. -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}" $CMAKE_OPTIONS diff --git a/scripts/ci/build_emscripten.sh b/scripts/ci/build_emscripten.sh index 836c4d41c553..50c851af8448 100755 --- a/scripts/ci/build_emscripten.sh +++ b/scripts/ci/build_emscripten.sh @@ -45,17 +45,7 @@ function build() { cd "${ROOT_DIR}" - if [[ $CIRCLE_BRANCH == release || -n $CIRCLE_TAG || -n $FORCE_RELEASE || $(git tag --points-at HEAD 2> /dev/null) == v* ]]; then - echo -n > prerelease.txt - else - # Use last commit date rather than build date to avoid ending up with builds for - # different platforms having different version strings (and therefore producing different bytecode) - # if the CI is triggered just before midnight. - TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="${prerelease_source}.%cd" > prerelease.txt - fi - if [[ -n $CIRCLE_SHA1 ]]; then - echo -n "$CIRCLE_SHA1" > commit_hash.txt - fi + "${SCRIPT_DIR}/prerelease_suffix.sh" "$prerelease_source" "$(git tag --points-at HEAD 2> /dev/null)" > prerelease.txt # Disable warnings for unqualified `move()` calls, introduced and enabled by # default in clang-16 which is what the emscripten docker image uses. diff --git a/scripts/ci/build_win.sh b/scripts/ci/build_win.sh index 647cb02d95b6..64d63c58f4ef 100755 --- a/scripts/ci/build_win.sh +++ b/scripts/ci/build_win.sh @@ -8,20 +8,7 @@ FORCE_RELEASE="${FORCE_RELEASE:-}" CIRCLE_TAG="${CIRCLE_TAG:-}" cd "$ROOTDIR" -if [[ $FORCE_RELEASE != "" || $CIRCLE_TAG != "" ]]; then - echo -n > prerelease.txt -else - # Use last commit date rather than build date to avoid ending up with builds for - # different platforms having different version strings (and therefore producing different bytecode) - # if the CI is triggered just before midnight. - # NOTE: The -local suffix makes git not use the timezone from the commit but instead convert to - # local one, which we explicitly set to UTC. - # NOTE: git --date is supposed to support the %-m/%-d format too, but it does not seem to - # work on Windows. Without it we get leading zeros for month and day. - last_commit_date=$(TZ=UTC git show --quiet --date="format-local:%Y-%m-%d" --format="%cd") - last_commit_date_stripped=$(date --date="$last_commit_date" "+%Y.%-m.%-d") - echo -n "${prerelease_source}.${last_commit_date_stripped}" > prerelease.txt -fi +"${ROOTDIR}/scripts/prerelease_suffix.sh" "$prerelease_source" "$CIRCLE_TAG" > prerelease.txt mkdir -p build/ cd build/ diff --git a/scripts/create_source_tarball.sh b/scripts/create_source_tarball.sh index 1a3099245352..0e135ad8242e 100755 --- a/scripts/create_source_tarball.sh +++ b/scripts/create_source_tarball.sh @@ -2,18 +2,36 @@ set -euo pipefail REPO_ROOT="$(dirname "$0")"/.. +# shellcheck source=scripts/common.sh +source "${REPO_ROOT}/scripts/common.sh" + cd "$REPO_ROOT" version=$(scripts/get_version.sh) commit_hash=$(git rev-parse --short=8 HEAD) -commit_date=$(git show --format=%ci HEAD | head -n 1 | cut - -b1-10 | sed -e 's/-0?/./' | sed -e 's/-0?/./') -# File exists and has zero size -> not a prerelease -if [[ -e prerelease.txt && ! -s prerelease.txt ]]; then - version_string="$version" +if [[ -e prerelease.txt ]]; then + prerelease_suffix=$(cat prerelease.txt) + if [[ $prerelease_suffix == "" ]]; then + # File exists and has zero size -> not a prerelease + version_string="$version" + elif [[ $prerelease_suffix == pre.* ]]; then + # Tagged prerelease -> unambiguous, so commit hash not needed + version_string="${version}-${prerelease_suffix}" + else + # Nightly/develop/other prerelease -> include commit hash + version_string="${version}-${prerelease_suffix}-${commit_hash}" + fi else + # Nightly/develop/other prerelease -> include commit hash + default prerelease suffix + commit_date=$(TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="%cd") version_string="${version}-nightly-${commit_date}-${commit_hash}" fi +# The only purpose of commit_hash.txt is to make it possible to build the compiler without git. +# It is not meant as an override of the real hash. +[[ ! -e commit_hash.txt ]] || \ + fail "commit_hash.txt is present in the repository root, but will not be used to override the commit hash for the source package." + TEMPDIR=$(mktemp -d -t "solc-src-tarball-XXXXXX") SOLDIR="${TEMPDIR}/solidity_${version_string}/" mkdir "$SOLDIR" diff --git a/scripts/prerelease_suffix.sh b/scripts/prerelease_suffix.sh new file mode 100755 index 000000000000..2913b12fb441 --- /dev/null +++ b/scripts/prerelease_suffix.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +(( $# <= 2 )) || { >&2 echo "Usage: $0 [PRERELEASE_SOURCE] [GIT_TAG]"; exit 1; } +prerelease_source="${1:-nightly}" +git_tag="${2:-}" +FORCE_RELEASE="${FORCE_RELEASE:-}" + +GNU_DATE="date" +if [[ "$OSTYPE" == "darwin"* ]]; then + GNU_DATE=gdate +fi + +if [[ $FORCE_RELEASE != "" || $git_tag =~ ^v[0-9.]+$ ]]; then + echo -n +elif [[ $git_tag =~ ^v[0-9.]+-pre. ]]; then + echo -n "pre.${git_tag#*-pre.}" +else + # Use last commit date rather than build date to avoid ending up with builds for + # different platforms having different version strings (and therefore producing different bytecode) + # if the CI is triggered just before midnight. + # NOTE: The -local suffix makes git not use the timezone from the commit but instead convert to + # local one, which we explicitly set to UTC. + # NOTE: git --date is supposed to support the %-m/%-d format too, but it does not seem to + # work on Windows. Without it we get leading zeros for month and day. + last_commit_date=$(TZ=UTC git show --quiet --date="format-local:%Y-%m-%d" --format="%cd") + last_commit_date_stripped=$("$GNU_DATE" --date "$last_commit_date" "+%Y.%-m.%-d") + echo -n "${prerelease_source}.${last_commit_date_stripped}" +fi