2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NSFramework
23 ///////////////////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////
28 #include <native_service/ns_buildversioncheck.hpp>
34 namespace frameworkunified_ns_bvc {
36 const UI_32 kMaxBuildVersionLength = 32;
37 PCSTR g_build_version_env_var_name = "BUILD_VERSION";
38 PCSTR g_build_version = _BUILD_VERSION; // Should be defined when library is built
40 bool isEmptyString(PCSTR str) { // NOLINT (readability/nolint)
41 return 0 == std::strncmp("", str, 1);
44 } // namespace frameworkunified_ns_bvc
48 namespace frameworkunified {
54 BOOL buildVersionsMatch(PCSTR build_version) { // NOLINT (readability/nolint)
55 PCSTR env_build_version = getEnvironmentBuildVersion();
56 PCSTR lib_build_version = getLibraryBuildVersion();
57 return 0 == std::strncmp(env_build_version, build_version, frameworkunified_ns_bvc::kMaxBuildVersionLength) &&
58 0 == std::strncmp(lib_build_version, build_version, frameworkunified_ns_bvc::kMaxBuildVersionLength) &&
59 !frameworkunified_ns_bvc::isEmptyString(build_version) &&
60 !frameworkunified_ns_bvc::isEmptyString(env_build_version) &&
61 !frameworkunified_ns_bvc::isEmptyString(lib_build_version);
64 PCSTR getEnvironmentBuildVersion() { // NOLINT (readability/nolint)
65 static PCSTR env_version = std::getenv(frameworkunified_ns_bvc::g_build_version_env_var_name);
66 return env_version != NULL ? env_version : "";
69 PCSTR getLibraryBuildVersion() { // NOLINT (readability/nolint)
70 return frameworkunified_ns_bvc::g_build_version;
73 namespace utility_private {
75 PCSTR niceBuildVersion(PCSTR build_version) { // NOLINT (readability/nolint)
76 return frameworkunified_ns_bvc::isEmptyString(build_version) ? "<Not defined>" : build_version;
79 } // namespace utility_private
81 } // namespace utility
85 } // namespace frameworkunified