|
1 | 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license
|
2 | 2 |
|
| 3 | +# Internal changes mechanism. |
| 4 | +# Instructions for Julia Core Developers: |
| 5 | +# 1. When making a breaking change that is known to be depnedet upon by an |
| 6 | +# important and closely coupled package, decide on a unique `change_name` |
| 7 | +# for your PR and add it to the list below. In general, is is better to |
| 8 | +# err on the side of caution and assign a `change_name` even if it is not |
| 9 | +# clear that it is required. `change_name`s may also be assigned after the |
| 10 | +# fact in a separate PR. (Note that this may cause packages to misbehave |
| 11 | +# on versions in between the change and the assignment of the `change_name`, |
| 12 | +# but this is often still better than the alternative of misbehaving on unknown |
| 13 | +# versions). |
| 14 | + |
| 15 | +# Instructions for Release Managers: |
| 16 | +# 1. Upon tagging any release, clear the list of internal changes. |
| 17 | +# 2. Upon tagging an -alpha version |
| 18 | +# a. On master, set __next_removal_version to v"1.(x+1)-alpha" |
| 19 | +# b. On the release branch, set __next_removal_version to v"1.x" (no -alpha) |
| 20 | +# 3. Upong tagging a release candidate, clear the list of internal changes and |
| 21 | +# set __next_removal_version to `nothing`. |
| 22 | +const __next_removal_version = v"1.12-alpha" |
| 23 | +const __internal_changes_list = ( |
| 24 | + :invertedlinetables, |
| 25 | + :codeinforefactor, |
| 26 | + # Add new change names above this line |
| 27 | +) |
| 28 | + |
| 29 | +if !isempty(__internal_changes_list) |
| 30 | + if VERSION == __next_removal_version |
| 31 | + error("You have tagged a new release without clearing the internal changes list.") |
| 32 | + end |
| 33 | +elseif __next_removal_version === nothing |
| 34 | + error("You have tagged a new release candidate without clearing the internal changes list.") |
| 35 | +end |
| 36 | + |
| 37 | +""" |
| 38 | + __has_internal_change(version_or::VersionNumber, change_name::Symbol) |
| 39 | +
|
| 40 | +Some Julia packages have known dependencies on Julia internals (e.g. for introspection of |
| 41 | +internal julia datastructures). To ease the co-development of such packages with julia, |
| 42 | +a `change_name` is assigned on a best-effort basis or when explicitly requested. |
| 43 | +This `change_name` can be used to probe whether or not the particular pre-release build of julia has |
| 44 | +a particular change. In particular this function tests change scheduled for `version_or` |
| 45 | +is present in our current julia build, either because our current version |
| 46 | +is greater than `version_or` or because we're running a pre-release build that |
| 47 | +includes the change. |
| 48 | +
|
| 49 | +Using this mechanism is a superior alternative to commit-number based `VERSION` |
| 50 | +comparisons, which can be brittle during pre-release stages when there are multiple |
| 51 | +actively developed branches. |
| 52 | +
|
| 53 | +The list of changes is cleared twice during the release process: |
| 54 | +1. With the release of the first alpha |
| 55 | +2. For the first release candidate |
| 56 | +
|
| 57 | +No new `change_name`s will be added during release candidates or bugfix releases |
| 58 | +(so in particular on any released version, the list of changes will be empty and |
| 59 | +`__has_internal_change` will always be equivalent to a version comparison. |
| 60 | +
|
| 61 | +# Example |
| 62 | +
|
| 63 | +Julia version `v"1.12.0-DEV.173"` changed the internal representation of line number debug info. |
| 64 | +Several debugging packages have custom code to display this information and need to be changed |
| 65 | +accordingly. In previous practice, this would often be accomplished with something like the following |
| 66 | +``` |
| 67 | +@static if VERSION > v"1.12.0-DEV.173" |
| 68 | + # Code to handle new format |
| 69 | +else |
| 70 | + # Code to handle old format |
| 71 | +end |
| 72 | +``` |
| 73 | +
|
| 74 | +However, because such checks cannot be introduced until a VERSION number is assigned |
| 75 | +(which also automatically pushes out the change to all nightly users), there was a builtin period |
| 76 | +of breakage. With `__has_internal_change`, this can instead be written as: |
| 77 | +
|
| 78 | +``` |
| 79 | +@static if __has_internal_change(v"1.12-alpha", :invertedlinenames) |
| 80 | + # Code to handle new format |
| 81 | +else |
| 82 | + # Code to handle old format |
| 83 | +end |
| 84 | +``` |
| 85 | +
|
| 86 | +To find out the correct verrsion to use as the first argument, you may use |
| 87 | +`Base.__next_removal_version`, which is set to the next version number in which |
| 88 | +the list of changes will be cleared. |
| 89 | +
|
| 90 | +The primary advantage of this approach is that it allows a new version of the |
| 91 | +package to be tagged and released *in advance* of the break on the nightly |
| 92 | +build, thus ensuring continuity of package operation for nightly users. |
| 93 | +
|
| 94 | +!!! warning |
| 95 | +
|
| 96 | + This functionality is intended to help package developers which make use of |
| 97 | + internal julia functionality. Doing so is explicitly discouraged unless absolutely |
| 98 | + required and comes with the explicit understanding that the package will break. |
| 99 | + In particular, this is not a generic feature-testing mechanism, but only a |
| 100 | + simple, courtesy coordination mechanism for changes that are known (or found) to |
| 101 | + be breaking a package depending on julia internals. |
| 102 | +""" |
| 103 | +function __has_internal_change(version_or::VersionNumber, change_name::Symbol) |
| 104 | + VERSION > version_or && return true |
| 105 | + change_name in __internal_changes_list |
| 106 | +end |
| 107 | +export __has_internal_change |
| 108 | + |
3 | 109 | # Deprecated functions and objects
|
4 | 110 | #
|
5 | 111 | # Please add new deprecations at the bottom of the file.
|
|
0 commit comments