Skip to content

Commit

Permalink
Extract repository version and print in SoapySDRServer
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofquality committed Mar 25, 2018
1 parent 70b1909 commit 17e8e72
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 5 deletions.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
cmake_minimum_required(VERSION 2.8.7)
project(SoapyRemote CXX C)

#extract changelog version
file(READ "${PROJECT_SOURCE_DIR}/Changelog.txt" changelog_txt)
string(REGEX MATCH "Release ([0-9]+\\.[0-9]+\\.[0-9]+) \\(" CHANGELOG_MATCH "${changelog_txt}")
if(NOT CHANGELOG_MATCH)
message(FATAL_ERROR "Failed to extract version number from Changelog.txt")
endif(NOT CHANGELOG_MATCH)
set(SOAPY_REMOTE_VERSION "${CMAKE_MATCH_1}")

if (NOT SOAPY_REMOTE_EXTVER)
include(${PROJECT_SOURCE_DIR}/cmake/Modules/GetGitRevisionDescription.cmake)
get_git_head_revision(GITREFSPEC GITHASH)
if (GITHASH)
string(SUBSTRING "${GITHASH}" 0 8 GITHASH)
set(SOAPY_REMOTE_EXTVER "g${GITHASH}")
else (GITHASH)
set(SOAPY_REMOTE_EXTVER "unknown")
endif (GITHASH)
endif()

set(SOAPY_REMOTE_VERSION "${SOAPY_REMOTE_VERSION}-${SOAPY_REMOTE_EXTVER}")

# select build type to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
Expand Down Expand Up @@ -46,3 +67,9 @@ add_subdirectory(server)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_subdirectory(system)
endif()

#########################################################################
# summary
#########################################################################
message(STATUS "SoapyRemote version: v${SOAPY_REMOTE_VERSION}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Release 0.5.0 (pending)
==========================

- Extract repository version and print in SoapySDRServer
- Support stream hardware acceleration with protocol none
- Support for DNS-SD publishing and discovery with avahi

Expand Down
130 changes: 130 additions & 0 deletions cmake/Modules/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()

if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()

#message(STATUS "Arguments to execute_process: ${ARGN}")

execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()

set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
38 changes: 38 additions & 0 deletions cmake/Modules/GetGitRevisionDescription.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(HEAD_HASH)

file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
set(HEAD_HASH "${HEAD_REF}")
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()

if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
7 changes: 6 additions & 1 deletion common/SoapyInfoUtils.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2015 Josh Blum
// Copyright (c) 2015-2018 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#pragma once
Expand All @@ -19,4 +19,9 @@ namespace SoapyInfo
* Get the user agent string for this build.
*/
SOAPY_REMOTE_API std::string getUserAgent(void);

/*!
* Get the server version string for this build.
*/
SOAPY_REMOTE_API std::string getServerVersion(void);
};
7 changes: 6 additions & 1 deletion common/SoapyInfoUtils.in.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2015 Josh Blum
// Copyright (c) 2015-2018 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#include "SoapySocketDefs.hpp"
Expand Down Expand Up @@ -85,3 +85,8 @@ SOAPY_REMOTE_API std::string SoapyInfo::getUserAgent(void)
{
return "@CMAKE_SYSTEM_NAME@ UPnP/1.1 SoapyRemote/@SoapySDR_VERSION@";
}

SOAPY_REMOTE_API std::string SoapyInfo::getServerVersion(void)
{
return "@SOAPY_REMOTE_VERSION@";
}
9 changes: 7 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/make -f
# -*- makefile -*-

# extract the architecture for setting the library path suffix
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DEB_HOST_MULTIARCH

# extract the last section of the changelog version for extra info
DEB_VERSION ?= $(shell dpkg-parsechangelog -S Version)
DEB_VERSION_EXTRA := $(lastword $(subst -, ,$(DEB_VERSION)))

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
Expand All @@ -11,7 +15,8 @@ export DEB_HOST_MULTIARCH
dh $@ --buildsystem=cmake --parallel

override_dh_auto_configure:
dh_auto_configure -- -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)"
dh_auto_configure -- -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" \
-DSOAPY_REMOTE_EXTVER="$(DEB_VERSION_EXTRA)"

override_dh_installchangelogs:
dh_installchangelogs Changelog.txt
3 changes: 2 additions & 1 deletion server/SoapyServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ static int runServer(void)

//this UUID identifies the server process
const auto serverUUID = SoapyInfo::generateUUID1();
std::cout << serverUUID << std::endl;
std::cout << "Server version: " << SoapyInfo::getServerVersion() << std::endl;
std::cout << "Server UUID: " << serverUUID << std::endl;

std::cout << "Launching the server... " << url.toString() << std::endl;
SoapyRPCSocket s;
Expand Down

0 comments on commit 17e8e72

Please sign in to comment.