summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2022-08-16libcamera: base: Make message.h and mutex.h privateLaurent Pinchart
2022-08-16meson: Use dependency() instead of find_library() where possibleLaurent Pinchart
2022-08-10libcamera: Allow concurrent use of cameras from same pipeline handlerLaurent Pinchart
2022-08-10libcamera: formats: Fix warning for unknown V4L2 pixfmtJacopo Mondi
2022-08-09ipa: ipu3: Add YAML tuning file supportLaurent Pinchart
2022-08-09ipa: ipu3: Register algorithmsLaurent Pinchart
2022-08-09ipa: ipu3: Add an uncalibrated.yaml tuning data fileLaurent Pinchart
2022-08-09pipeline: ipu3: Support IPA tuning fileLaurent Pinchart
2022-08-09libcamera: yaml_parser: Return nullopt on error from YamlObject::get()Laurent Pinchart
2022-08-09cam: sdl_texture: Rename 'pitch' to 'stride'Laurent Pinchart
2022-08-09ipa: rkisp1: Remove unused algorithms includes from rkisp1.cppDaniel Semkowicz
2022-08-09libcamera: Make IPA module signing recommended instead of mandatoryLaurent Pinchart
2022-08-09libcamera: pub_key: Support openssl as an alternative to gnutlsLaurent Pinchart
2022-08-09libcamera: pub_key: Gracefully handle failures to load public keyLaurent Pinchart
2022-08-09libcamera: meson: Use dependency() to find gnutlsLaurent Pinchart
2022-08-09libcamera: controls: Generate and use fixed-sized Span typesChristian Rauch
2022-08-09cam: kms_sink: Scale the frame buffer to full screen if supportedLaurent Pinchart
2022-08-09cam: kms_sink: Make lifetime management of DRM request saferLaurent Pinchart
2022-08-09cam: drm: Add support for test-only commitsLaurent Pinchart
2022-08-08cam: sdl_sink: Fix compilation with SDL2 <2.0.16Laurent Pinchart
2022-08-08cam: sdl_sink: Add NV12 texture supportLaurent Pinchart
2022-08-08cam: sdl_sink: Support multi-planar formatsLaurent Pinchart
2022-08-08cam: Rename sdl_texture_yuyv.{cpp,h} to sdl_texture_yuv.{cpp,h}Laurent Pinchart
2022-08-08cam: sdl_texture_yuyv: Make line stride configurableLaurent Pinchart
2022-08-04libcamera: Correct typos and omissions for packed 10-bit raw monochrome formatDavid Plowman
2022-08-04libcamera: Switch internal YAML files to YAML 1.1Laurent Pinchart
2022-08-04ipa: rkisp1: Use YAML 1.1 for tuning data filesLaurent Pinchart
2022-08-04pipeline: rkisp1: Move ControlInfoMap to IPA moduleLaurent Pinchart
2022-08-03libcamera: pipeline: simple: Add support for NXP ISILaurent Pinchart
2022-08-03libcamera: pipeline: simple: Don't disable links carrying other streamsLaurent Pinchart
2022-08-03libcamera: pipeline: simple: Walk pipeline using subdev internal routingPhi-Bang Nguyen
2022-08-03libcamera: pipeline: simple: Setup links in the context of sink entitiesLaurent Pinchart
2022-08-03libcamera: pipeline: simple: Reset routing table of subdevsJacopo Mondi
2022-08-03libcamera: v4l2_subdevice: Add support for the V4L2 subdev routing APIJacopo Mondi
2022-08-03libcamera: v4l2_subdevice: Collect subdev capabilitiesJacopo Mondi
2022-08-03libcamera: v4l2_subdevice: Change V4L2Subdevice::WhenceJacopo Mondi
2022-08-03include: linux: Add V4L2 subdev internal routing APILaurent Pinchart
2022-08-03libcamera: formats: Add AVUY8888 and XVUY8888 formatsLaurent Pinchart
2022-08-03include: linux: Add V4L2 YUVA32 and YUVX32 pixel formatsLaurent Pinchart
2022-08-03include: drm_fourcc: Add AVUY and XVUY 4:4:4 packet formatsLaurent Pinchart
2022-08-03include: linux: Update kernel headers to version v5.19Laurent Pinchart
2022-08-03libcamera: yaml_parser: Return nullopt on errorJacopo Mondi
2022-08-03libcamera: formats: Map V4L2_PIX_FMT_JPEG to formats::MJPEGJacopo Mondi
2022-08-03libcamera: v4l2_videodevice: Match formats supported by the deviceJacopo Mondi
2022-08-03libcamera: v4l2_pixelformat: Implement std::hash specializationLaurent Pinchart
2022-08-03libcamera: v4l2_pixelformat: Return the list of V4L2 formatsJacopo Mondi
2022-08-03libcamera: v4l2_videodevice: Reintroduce toV4L2PixelFormat()Jacopo Mondi
2022-08-03guides: pipeline handler: Remove rogue spacesJacopo Mondi
2022-08-03libcamera: formats: Merge V4L2 single and multi formatsJacopo Mondi
2022-08-03libcamera: formats: Reimplement V4L2 PixelFormatInfo::info()Jacopo Mondi
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0

set -o errexit -o nounset -o pipefail

NAT='0|[1-9][0-9]*'
ALPHANUM='[0-9]*[A-Za-z-][0-9A-Za-z-]*'
IDENT="$NAT|$ALPHANUM"
FIELD='[0-9A-Za-z-]+'

SEMVER_REGEX="\
^[vV]?\
($NAT)\\.($NAT)\\.($NAT)\
(\\-(${IDENT})(\\.(${IDENT}))*)?\
(\\+${FIELD}(\\.${FIELD})*)?$"

PROG=semver
PROG_VERSION="3.4.0"

USAGE="\
Usage:
  $PROG bump major <version>
  $PROG bump minor <version>
  $PROG bump patch <version>
  $PROG bump prerel|prerelease [<prerel>] <version>
  $PROG bump build <build> <version>
  $PROG bump release <version>
  $PROG get major <version>
  $PROG get minor <version>
  $PROG get patch <version>
  $PROG get prerel|prerelease <version>
  $PROG get build <version>
  $PROG get release <version>
  $PROG compare <version> <other_version>
  $PROG diff <version> <other_version>
  $PROG validate <version>
  $PROG --help
  $PROG --version

Arguments:
  <version>  A version must match the following regular expression:
             \"${SEMVER_REGEX}\"
             In English:
             -- The version must match X.Y.Z[-PRERELEASE][+BUILD]
                where X, Y and Z are non-negative integers.
             -- PRERELEASE is a dot separated sequence of non-negative integers and/or
                identifiers composed of alphanumeric characters and hyphens (with
                at least one non-digit). Numeric identifiers must not have leading
                zeros. A hyphen (\"-\") introduces this optional part.
             -- BUILD is a dot separated sequence of identifiers composed of alphanumeric
                characters and hyphens. A plus (\"+\") introduces this optional part.

  <other_version>  See <version> definition.

  <prerel>  A string as defined by PRERELEASE above. Or, it can be a PRERELEASE
            prototype string followed by a dot.

  <build>   A string as defined by BUILD above.

Options:
  -v, --version          Print the version of this tool.
  -h, --help             Print this help message.

Commands:
  bump      Bump by one of major, minor, patch; zeroing or removing
            subsequent parts. \"bump prerel\" (or its synonym \"bump prerelease\")
            sets the PRERELEASE part and removes any BUILD part. A trailing dot
            in the <prerel> argument introduces an incrementing numeric field
            which is added or bumped. If no <prerel> argument is provided, an
            incrementing numeric field is introduced/bumped. \"bump build\" sets
            the BUILD part.  \"bump release\" removes any PRERELEASE or BUILD parts.
            The bumped version is written to stdout.

  get       Extract given part of <version>, where part is one of major, minor,
            patch, prerel (alternatively: prerelease), build, or release.

  compare   Compare <version> with <other_version>, output to stdout the
            following values: -1 if <other_version> is newer, 0 if equal, 1 if
            older. The BUILD part is not used in comparisons.

  diff      Compare <version> with <other_version>, output to stdout the
            difference between two versions by the release type (MAJOR, MINOR,
            PATCH, PRERELEASE, BUILD).

  validate  Validate if <version> follows the SEMVER pattern (see <version>
            definition). Print 'valid' to stdout if the version is valid, otherwise
            print 'invalid'.

See also:
  https://semver.org -- Semantic Versioning 2.0.0"

function error {
  echo -e "$1" >&2
  exit 1
}

function usage_help {
  error "$USAGE"
}

function usage_version {
  echo -e "${PROG}: $PROG_VERSION"
  exit 0
}

# normalize the "part" keywords to a canonical string.  At present,
# only "prerelease" is normalized to "prerel".

function normalize_part {
    if [ "$1" == "prerelease" ]
    then
	echo "prerel"
    else
	echo "$1"
    fi
}

function validate_version {
  local version=$1
  if [[ "$version" =~ $SEMVER_REGEX ]]; then
    # if a second argument is passed, store the result in var named by $2
    if [ "$#" -eq "2" ]; then
      local major=${BASH_REMATCH[1]}
      local minor=${BASH_REMATCH[2]}
      local patch=${BASH_REMATCH[3]}
      local prere=${BASH_REMATCH[4]}
      local build=${BASH_REMATCH[8]}
      eval "$2=(\"$major\" \"$minor\" \"$patch\" \"$prere\" \"$build\")"
    else
      echo "$version"
    fi
  else
    error "version $version does not match the semver scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'. See help for more information."
  fi
}

function is_nat {
    [[ "$1" =~ ^($NAT)$ ]]
}

function is_null {
    [ -z "$1" ]
}

function order_nat {
    [ "$1" -lt "$2" ] && { echo -1 ; return ; }
    [ "$1" -gt "$2" ] && { echo 1 ; return ; }
    echo 0
}

function order_string {
    [[ $1 < $2 ]] && { echo -1 ; return ; }
    [[ $1 > $2 ]] && { echo 1 ; return ; }
    echo 0
}

# given two (named) arrays containing NAT and/or ALPHANUM fields, compare them
# one by one according to semver 2.0.0 spec. Return -1, 0, 1 if left array ($1)
# is less-than, equal, or greater-than the right array ($2).  The longer array
# is considered greater-than the shorter if the shorter is a prefix of the longer.
#
function compare_fields {
    local l="$1[@]"
    local r="$2[@]"
    local leftfield=( "${!l}" )
    local rightfield=( "${!r}" )
    local left
    local right

    local i=$(( -1 ))
    local order=$(( 0 ))

    while true
    do
        [ $order -ne 0 ] && { echo $order ; return ; }

        : $(( i++ ))
        left="${leftfield[$i]}"
        right="${rightfield[$i]}"

        is_null "$left" && is_null "$right" && { echo 0  ; return ; }
        is_null "$left"                     && { echo -1 ; return ; }
                           is_null "$right" && { echo 1  ; return ; }

        is_nat "$left" &&  is_nat "$right" && { order=$(order_nat "$left" "$right") ; continue ; }
        is_nat "$left"                     && { echo -1 ; return ; }
                           is_nat "$right" && { echo 1  ; return ; }
                                              { order=$(order_string "$left" "$right") ; continue ; }
    done
}

# shellcheck disable=SC2206     # checked by "validate"; ok to expand prerel id's into array
function compare_version {
  local order
  validate_version "$1" V
  validate_version "$2" V_

  # compare major, minor, patch

  local left=( "${V[0]}" "${V[1]}" "${V[2]}" )
  local right=( "${V_[0]}" "${V_[1]}" "${V_[2]}" )

  order=$(compare_fields left right)
  [ "$order" -ne 0 ] && { echo "$order" ; return ; }

  # compare pre-release ids when M.m.p are equal

  local prerel="${V[3]:1}"
  local prerel_="${V_[3]:1}"
  local left=( ${prerel//./ } )
  local right=( ${prerel_//./ } )

  # if left and right have no pre-release part, then left equals right
  # if only one of left/right has pre-release part, that one is less than simple M.m.p

  [ -z "$prerel" ] && [ -z "$prerel_" ] && { echo 0  ; return ; }
  [ -z "$prerel" ]                      && { echo 1  ; return ; }
                      [ -z "$prerel_" ] && { echo -1 ; return ; }

  # otherwise, compare the pre-release id's

  compare_fields left right
}