Skip to content

Commit

Permalink
contrib: cleanup/factorize scripts fot checking windows/android versions
Browse files Browse the repository at this point in the history
contrib/git-hooks/check-versions.sh tested both android and windows.
contrib/windows/test-windows-version.sh.in only tested windows but
it had verbose messages, and it was only called in ci.inria.fr/job-0-tarball.sh.

Have a single windows check script under contrib/windows
and an Android one under contrib/android.
Both are called by the git hooks with --quiet,
and by ci.inria.fr/job-0-tarball.sh without --quiet.

No need to make them "make check" compatible.
No need to generate anything from configure.
They have a parameter to run outside of the git root directory
but it's actually not required here.

contrib/android/check-versions.sh isn't distributed since contrib/android isn't.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Sep 13, 2021
1 parent 8bb90de commit 3919415
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 204 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -219,7 +219,6 @@ test-suite.log

/contrib/systemd/hwloc-dump-hwdata.service
/contrib/misc/hwloc-tweak-osindex
/contrib/windows/test-windows-version.sh

/contrib/android/AndroidApp/.gradle
/contrib/android/AndroidApp/.idea
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
@@ -1,4 +1,4 @@
# Copyright © 2009-2020 Inria. All rights reserved.
# Copyright © 2009-2021 Inria. All rights reserved.
# Copyright © 2009 Université Bordeaux
# Copyright © 2009-2014 Cisco Systems, Inc. All rights reserved.
# See COPYING in top-level directory.
Expand Down
2 changes: 0 additions & 2 deletions config/hwloc_internal.m4
Expand Up @@ -510,7 +510,6 @@ int foo(void) {
hwloc_config_prefix[contrib/completion/Makefile]
hwloc_config_prefix[contrib/misc/Makefile]
hwloc_config_prefix[contrib/windows/Makefile]
hwloc_config_prefix[contrib/windows/test-windows-version.sh]
hwloc_config_prefix[tests/netloc/Makefile]
hwloc_config_prefix[tests/netloc/tests.sh]
)
Expand All @@ -537,7 +536,6 @@ int foo(void) {
hwloc_config_prefix[utils/lstopo/test-lstopo.sh] \
hwloc_config_prefix[utils/lstopo/test-lstopo-shmem.sh] \
hwloc_config_prefix[utils/netloc/infiniband/netloc_ib_gather_raw] \
hwloc_config_prefix[contrib/windows/test-windows-version.sh] \
hwloc_config_prefix[tests/netloc/tests.sh])
# These links are only needed in standalone mode. It would
Expand Down
84 changes: 84 additions & 0 deletions contrib/android/check-versions.sh
@@ -0,0 +1,84 @@
#!/bin/bash
#
# Copyright © 2018-2021 Inria. All rights reserved.
# $COPYRIGHT$
#

function die() {
echo "$@"
exit 1
}

if test "x$1" = "x-h" -o "x$1" = "x--help"; then
echo "$0 [--quiet] [git root directory]"
exit 0
fi

echo=echo
if test "x$1" = "x--quiet"; then
echo=true
shift
fi

rootdir=.
if test "x$1" != x; then
rootdir="$1"
fi

android_gradle="$rootdir/contrib/android/AndroidApp/lstopo/build.gradle"
android_config_h="$rootdir/contrib/android/include/hwloc/autogen/config.h"
version_file="$rootdir/VERSION"

if ! test -f "$version_file"; then
die "Couldn't find $version_file"
fi

### EXTRACT MAIN VERSION ###
$echo "Looking for official version $version_file ..."
official_major=$(grep ^major= $version_file | cut -d= -f2)
official_minor=$(grep ^minor= $version_file | cut -d= -f2)
official_release=$(grep ^release= $version_file | cut -d= -f2)
official_greek=$(grep ^greek= $version_file | cut -d= -f2)
if [ -z "$official_major" -o -z "$official_minor" -o -z "$official_release" ]; then
die "ERROR in $version_file: Failed to get official HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK"
fi
$echo " Found major=$official_major minor=$official_minor release=$official_release greek=$official_greek"
official_version_nogreek="$official_major.$official_minor.$official_release"

$echo

### ANDROID CHECKS ###
$echo "Looking for Android-specific version in $android_config_h ..."
android_version=$(grep -w HWLOC_VERSION $android_config_h | grep -oP '".+"' | tr -d \")
android_major=$(grep -w HWLOC_VERSION_MAJOR $android_config_h | grep -oP '[0-9]+')
android_minor=$(grep -w HWLOC_VERSION_MINOR $android_config_h | grep -oP '[0-9]+')
android_release=$(grep -w HWLOC_VERSION_RELEASE $android_config_h | grep -oP '[0-9]+')
android_greek=$(grep -w HWLOC_VERSION_GREEK $android_config_h | grep -oP '".*"' | tr -d \")
if [ -z "$android_major" -o -z "$android_minor" -o -z "$android_release" ]; then
# greek is likely empty on purpose, ignore it
die "ERROR in $android_config_h: Failed to get Android-specific HWLOC_VERSION_MAJOR/MINOR/RELEASE"
fi
$echo " Found Android-specific version=$android_version major=$android_major minor=$android_minor release=$android_release greek=$android_greek"

# check that the version string matches
expected_android_version="$android_major.$android_minor.$android_release$android_greek"
if [ "$android_version" != "$expected_android_version" ]; then
die "ERROR in $android_config_h: Android-specific HWLOC_VERSION \"$android_version\" doesn't match HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK components \"$expected_android_version\""
fi
$echo " Android-specific HWLOC_VERSION \"$android_version\" matches HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK components"

# check android config.h version
if [ "$official_version_nogreek" != "$android_version" ]; then
die "ERROR in $android_config_h: Android-specific HWLOC_VERSION \"$android_version\" doesn't match \"$official_version_nogreek\" without GREEK"
fi
$echo " Android-specific version \"$android_version\" matches official version without GREEK"

$echo

# check android gradle version
$echo "Looking for Android-specific version in $android_gradle ..."
android_gradle_version=$(grep -w versionName $android_gradle | grep -oP '".*"' | tr -d \" | grep -oP '.+?(?=[-~])')
if [ "$official_version_nogreek" != "$android_gradle_version" ]; then
die "ERROR in $android_gradle: Android gradle HWLOC_VERSION \"$android_gradle_version\" doesn't match \"$official_version_nogreek\" without GREEK"
fi
$echo " Android-specific gradle version \"$android_gradle_version\" matches official version without GREEK"
7 changes: 4 additions & 3 deletions contrib/ci.inria.fr/job-0-tarball.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright © 2012-2020 Inria. All rights reserved.
# Copyright © 2012-2021 Inria. All rights reserved.
# See COPYING in top-level directory.
#

Expand Down Expand Up @@ -69,7 +69,8 @@ if ! make $distcheck; then
false
fi

# this test requires bash and grep -P, only run it in the main job
make check -C contrib/windows
# these tests require bash and grep -P, only run it in the main job
contrib/windows/check-versions.sh
contrib/android/check-versions.sh

exit 0
100 changes: 3 additions & 97 deletions contrib/git-hooks/check-versions.sh
@@ -1,102 +1,8 @@
#!/bin/bash
#
# Copyright © 2018-2020 Inria. All rights reserved.
# Copyright © 2018-2021 Inria. All rights reserved.
# $COPYRIGHT$
#

function die() {
echo "$@"
exit 1
}

android_gradle="./contrib/android/AndroidApp/lstopo/build.gradle"
android_config_h="./contrib/android/include/hwloc/autogen/config.h"
windows_config_h="./contrib/windows/hwloc_config.h"
vcxproj_file="./contrib/windows/libhwloc.vcxproj"
version_file="./VERSION"

# get all individual version components
android_version=$(grep -w HWLOC_VERSION $android_config_h | grep -oP '".+"' | tr -d \")
android_major=$(grep -w HWLOC_VERSION_MAJOR $android_config_h | grep -oP '[0-9]+')
android_minor=$(grep -w HWLOC_VERSION_MINOR $android_config_h | grep -oP '[0-9]+')
android_release=$(grep -w HWLOC_VERSION_RELEASE $android_config_h | grep -oP '[0-9]+')
android_greek=$(grep -w HWLOC_VERSION_GREEK $android_config_h | grep -oP '".*"' | tr -d \")
android_gradle_version=$(grep -w versionName $android_gradle | grep -oP '".*"' | tr -d \" | grep -oP '.+?(?=[-~])')
windows_major=$(grep -w HWLOC_VERSION_MAJOR $windows_config_h | grep -oP '[0-9]+')
windows_minor=$(grep -w HWLOC_VERSION_MINOR $windows_config_h | grep -oP '[0-9]+')
windows_release=$(grep -w HWLOC_VERSION_RELEASE $windows_config_h | grep -oP '[0-9]+')
windows_greek=$(grep -w HWLOC_VERSION_GREEK $windows_config_h | grep -oP '".*"' | tr -d \")
official_major=$(grep ^major= $version_file | cut -d= -f2)
official_minor=$(grep ^minor= $version_file | cut -d= -f2)
official_release=$(grep ^release= $version_file | cut -d= -f2)


### WINDOWS CHECK ###
if [ -z "$windows_major" -o -z "$windows_minor" -o -z "$windows_release" ]; then
# greek is likely empty on purpose, ignore it
die "ERROR in $windows_config_h: Failed to get Windows-specific HWLOC_VERSION_MAJOR/MINOR/RELEASE"
fi

# check that the version string matches
windows_version=$(grep -w HWLOC_VERSION $windows_config_h | grep -oP '".+"' | tr -d \")
expected_windows_version="$windows_major.$windows_minor.$windows_release$windows_greek"
if [ "$windows_version" != "$expected_windows_version" ]; then
die "ERROR in $windows_config_h: Windows-specific HWLOC_VERSION \"$windows_version\" doesn't match HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK components \"$expected_windows_version\""
fi

# check that it matchs the official version, without a GREEK
if [ -z "$official_major" -o -z "$official_minor" -o -z "$official_release" ]; then
die "ERROR in $windows_config_h: Failed to get official HWLOC_VERSION_MAJOR/MINOR/RELEASE"
fi
official_version_nogreek="$official_major.$official_minor.$official_release"
if [ "$official_version_nogreek" != "$windows_version" ]; then
die "ERROR in $windows_config_h: Windows-specific HWLOC_VERSION \"$windows_version\" doesn't match the official \"$official_version_nogreek\" without GREEK"
fi

# get the windows soname
if [ `grep '<TargetName>' $vcxproj_file | uniq -c | wc -l` != 1 ]; then
die "ERROR in $vcxproj_file: Couldn't find a single value for <TargetName> lines"
fi
windows_lib_soname=$(grep -m1 '<TargetName>' $vcxproj_file | grep -oP '\d+')
if [ -z "$windows_lib_soname" ]; then
die "ERROR in $vcxproj_file: Failed to get the Windows-specific soname"
fi

# get the official soname
official_lib_version=$(grep -w "libhwloc_so_version" $version_file | grep -oP '\d+:\d+:\d+')
if [ -z "$official_lib_version" ]; then
die "ERROR in $version_file: Failed to get the official lib version"
fi

# bashisms to extract the soname from the version
IFS=':' arr=(${official_lib_version})
declare -i official_lib_soname=${arr[0]}-${arr[2]}

# check that sonames match only if on a release branch
if [ "$official_lib_version" != "0:0:0" ] ; then
if [ "$windows_lib_soname" != "$official_lib_soname" ]; then
die "ERROR in $vcxproj_file: Windows-specific lib soname $windows_lib_soname differs from official $official_lib_soname (from \"$official_lib_version\")"
fi
fi

### ANDROID CHECK ###
if [ -z "$android_major" -o -z "$android_minor" -o -z "$android_release" ]; then
# greek is likely empty on purpose, ignore it
die "ERROR in $android_config_h: Failed to get Android-specific HWLOC_VERSION_MAJOR/MINOR/RELEASE"
fi

# check that the version string matches
expected_android_version="$android_major.$android_minor.$android_release$android_greek"
if [ "$android_version" != "$expected_android_version" ]; then
die "ERROR in $android_config_h: Android-specific HWLOC_VERSION \"$android_version\" doesn't match HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK components \"$expected_android_version\""
fi

# check android config.h version
if [ "$official_version_nogreek" != "$android_version" ]; then
die "ERROR in $android_config_h: Android-specific HWLOC_VERSION \"$android_version\" doesn't match \"$official_version_nogreek\" without GREEK"
fi

# check android gradle version
if [ "$official_version_nogreek" != "$android_gradle_version" ]; then
die "ERROR in $android_gradle: Android gradle HWLOC_VERSION \"$android_gradle_version\" doesn't match \"$official_version_nogreek\" without GREEK"
fi
./contrib/windows/check-versions.sh --quiet
./contrib/android/check-versions.sh --quiet
9 changes: 2 additions & 7 deletions contrib/windows/Makefile.am
@@ -1,12 +1,6 @@
# Copyright © 2009-2020 Inria. All rights reserved.
# See COPYING in top-level directory.

# This Makefile isn't used outside of make dist by default
# because test-windows-version.sh requires
# bash, and grep built with support for -P

TESTS = test-windows-version.sh

EXTRA_DIST = \
README \
hwloc.sln \
Expand Down Expand Up @@ -37,4 +31,5 @@ EXTRA_DIST = \
lstopo-win.vcxproj.filters \
lstopo.vcxproj \
lstopo.vcxproj.filters \
app.manifest
app.manifest \
check-versions.sh
111 changes: 111 additions & 0 deletions contrib/windows/check-versions.sh
@@ -0,0 +1,111 @@
#!/bin/bash
#
# Copyright © 2018-2021 Inria. All rights reserved.
# $COPYRIGHT$
#

function die() {
echo "$@"
exit 1
}

if test "x$1" = "x-h" -o "x$1" = "x--help"; then
echo "$0 [--quiet] [git root directory]"
exit 0
fi

echo=echo
if test "x$1" = "x--quiet"; then
echo=true
shift
fi

rootdir=.
if test "x$1" != x; then
rootdir="$1"
fi

windows_config_h="$rootdir/contrib/windows/hwloc_config.h"
vcxproj_file="$rootdir/contrib/windows/libhwloc.vcxproj"
version_file="$rootdir/VERSION"

if ! test -f "$version_file"; then
die "Couldn't find $version_file"
fi

### EXTRACT MAIN VERSION ###
$echo "Looking for official version $version_file ..."
official_major=$(grep ^major= $version_file | cut -d= -f2)
official_minor=$(grep ^minor= $version_file | cut -d= -f2)
official_release=$(grep ^release= $version_file | cut -d= -f2)
official_greek=$(grep ^greek= $version_file | cut -d= -f2)
if [ -z "$official_major" -o -z "$official_minor" -o -z "$official_release" ]; then
die "ERROR in $version_file: Failed to get official HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK"
fi
$echo " Found major=$official_major minor=$official_minor release=$official_release greek=$official_greek"
official_version_nogreek="$official_major.$official_minor.$official_release"

$echo

### WINDOWS CHECKS ###
$echo "Looking for Windows-specific version in $windows_config_h ..."
windows_major=$(grep -w HWLOC_VERSION_MAJOR $windows_config_h | grep -oP '[0-9]+')
windows_minor=$(grep -w HWLOC_VERSION_MINOR $windows_config_h | grep -oP '[0-9]+')
windows_release=$(grep -w HWLOC_VERSION_RELEASE $windows_config_h | grep -oP '[0-9]+')
windows_greek=$(grep -w HWLOC_VERSION_GREEK $windows_config_h | grep -oP '".*"' | tr -d \")
if [ -z "$windows_major" -o -z "$windows_minor" -o -z "$windows_release" ]; then
# greek is likely empty on purpose, ignore it
die "ERROR in $windows_config_h: Failed to get Windows-specific HWLOC_VERSION_MAJOR/MINOR/RELEASE"
fi
$echo " Found Windows-specific major=$windows_major minor=$windows_minor release=$windows_release greek=$windows_greek"

# check that the version string matches
windows_version=$(grep -w HWLOC_VERSION $windows_config_h | grep -oP '".+"' | tr -d \")
$echo " Found windows-specific HWLOC_VERSION \"$windows_version\""
expected_windows_version="$windows_major.$windows_minor.$windows_release$windows_greek"
if [ "$windows_version" != "$expected_windows_version" ]; then
die "ERROR in $windows_config_h: Windows-specific HWLOC_VERSION \"$windows_version\" doesn't match HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK components \"$expected_windows_version\""
fi
$echo " Windows-specific HWLOC_VERSION \"$windows_version\" matches HWLOC_VERSION_MAJOR/MINOR/RELEASE/GREEK components"

# check that it matches the official version, without a GREEK
if [ "$official_version_nogreek" != "$windows_version" ]; then
die "ERROR in $windows_config_h: Windows-specific HWLOC_VERSION \"$windows_version\" doesn't match the official \"$official_version_nogreek\" without GREEK"
fi
$echo " Windows-specific HWLOC_VERSION \"$windows_version\" matches official version without GREEK"

$echo

# get the windows soname
$echo "Looking in $vcxproj_file ..."
if [ `grep '<TargetName>' $vcxproj_file | uniq -c | wc -l` != 1 ]; then
die "ERROR in $vcxproj_file: Couldn't find a single value for <TargetName> lines"
fi
windows_lib_soname=$(grep -m1 '<TargetName>' $vcxproj_file | grep -oP '\d+')
if [ -z "$windows_lib_soname" ]; then
die "ERROR in $vcxproj_file: Failed to get the Windows-specific soname"
fi
$echo " Found Windows-specific soname $windows_lib_soname"

# get the official soname
$echo "Looking in $version_file ..."
official_lib_version=$(grep -w "libhwloc_so_version" $version_file | grep -oP '\d+:\d+:\d+')
if [ -z "$official_lib_version" ]; then
die "ERROR in $version_file: Failed to get the official lib version"
fi
$echo " Found official lib version \"$official_lib_version\""

# bashisms to extract the soname from the version
IFS=':' arr=(${official_lib_version})
declare -i official_lib_soname=${arr[0]}-${arr[2]}
$echo " Extracted official lib soname $official_lib_soname"

# check that sonames match only if on a release branch
if [ "$official_lib_version" != "0:0:0" ] ; then
if [ "$windows_lib_soname" != "$official_lib_soname" ]; then
die "ERROR in $vcxproj_file: Windows-specific lib soname $windows_lib_soname differs from official $official_lib_soname (from \"$official_lib_version\")"
fi
$echo " Windows-specific lib soname $windows_lib_soname matches official lib soname"
else
$echo " Ignoring unset lib soname"
fi

0 comments on commit 3919415

Please sign in to comment.