contrib/packaging/packagelib.sh
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 45983 97205cf0ee4d
child 49418 ccccd5064c6c
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26833
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     1
# Extract version number into 4 parts, some of which may be empty:
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     2
#
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     3
# version: the numeric part of the most recent tag. Will always look like 1.3.
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     4
#
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     5
# type: if an rc build, "rc", otherwise empty
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     6
#
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     7
# distance: the distance from the nearest tag, or empty if built from a tag
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     8
#
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
     9
# node: the node|short hg was built from, or empty if built from a tag
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
gethgversion() {
45983
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    11
    if [ -z "${1+x}" ]; then
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    12
        python="python"
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    13
    else
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    14
        python="$1"
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    15
    fi
34903
16d9f0b3e134 build: build deb/rpm independently on config/extensions in the host system
muxator <a.mux@inwind.it>
parents: 34686
diff changeset
    16
    export HGRCPATH=
16d9f0b3e134 build: build deb/rpm independently on config/extensions in the host system
muxator <a.mux@inwind.it>
parents: 34686
diff changeset
    17
    export HGPLAIN=
16d9f0b3e134 build: build deb/rpm independently on config/extensions in the host system
muxator <a.mux@inwind.it>
parents: 34686
diff changeset
    18
45983
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    19
    make cleanbutpackages PYTHON=$python
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    20
    make local PURE=--pure PYTHON=$python
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
    HG="$PWD/hg"
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
45983
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    23
    $python "$HG" version > /dev/null || { echo 'abort: hg version failed!'; exit 1 ; }
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
45983
97205cf0ee4d packaging: don't use plain 'python' if another python has been specified
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 41613
diff changeset
    25
    hgversion=`LANGUAGE=C $python "$HG" version | sed -ne 's/.*(version \(.*\))$/\1/p'`
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
26833
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    27
    if echo $hgversion | grep + > /dev/null 2>&1 ; then
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    28
        tmp=`echo $hgversion | cut -d+ -f 2`
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    29
        hgversion=`echo $hgversion | cut -d+ -f 1`
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    30
        distance=`echo $tmp | cut -d- -f 1`
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    31
        node=`echo $tmp | cut -d- -f 2`
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    32
    else
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    33
        distance=''
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    34
        node=''
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    35
    fi
41613
8f0e8b179842 packaging: modify rc detection to work with X.Yrc instead of X.Y-rc
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 38005
diff changeset
    36
    if echo $hgversion | grep -E -- '[0-9]\.[0-9](\.[0-9])?rc' > /dev/null 2>&1; then
8f0e8b179842 packaging: modify rc detection to work with X.Yrc instead of X.Y-rc
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 38005
diff changeset
    37
        version=`echo $hgversion | cut -d'r' -f1`
8f0e8b179842 packaging: modify rc detection to work with X.Yrc instead of X.Y-rc
Mathias De Mare <mathias.de_mare@nokia.com>
parents: 38005
diff changeset
    38
        type="rc`echo $hgversion | cut -d'c' -f2-`"
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
    else
26833
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    40
        version=$hgversion
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 24972
diff changeset
    41
        type=''
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
    fi
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
}