Skip to content

Commit

Permalink
Merged PR 3372: Release 4.2.0
Browse files Browse the repository at this point in the history
- BUG: Build script now correctly build 32bit and Debug version for Linux platform.
- BUILD: Build script now build Debug and Release version for MacOS platform.
- BUG: ResultsHashGetValues* APIs now use the single result if uniqueHttpHeaderIndex is not set.
- BUG: Removed constant specifier for writable variable in MatchForDeviceId example.
- OPTIM: Macros for printing deviceId are now replaced with static functions to properly handle the returned value of snprintf.
  • Loading branch information
Tung Pham authored and fatima51Degrees committed Dec 23, 2020
2 parents 3ce211e + 613829e commit cf2ad7c
Show file tree
Hide file tree
Showing 20 changed files with 674 additions and 110 deletions.
50 changes: 46 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ project(51DegreesDeviceDetection VERSION 4.0.1 LANGUAGES CXX C)

set(DD ${CMAKE_CURRENT_LIST_DIR}/src)
set(HASH ${CMAKE_CURRENT_LIST_DIR}/src/hash)
if (NoThreading)
set(DMALLOC_LIB dmalloc)
else()
set(DMALLOC_LIB dmallocth)
endif()

# Device Detection libraries

Expand Down Expand Up @@ -41,6 +46,8 @@ add_library(fiftyone-hash-c ${HASHC_SRC} ${HASHC_H})
target_link_libraries(fiftyone-hash-c fiftyone-device-detection-c)
if (MSVC)
target_compile_options(fiftyone-hash-c PRIVATE "/D_CRT_SECURE_NO_WARNINGS")
else()
target_compile_options(fiftyone-hash-c PRIVATE ${COMPILE_OPTION_DEBUG})
endif()

FILE(GLOB HASHCPP_SRC ${HASH}/*.cpp)
Expand All @@ -49,6 +56,11 @@ add_library(fiftyone-hash-cxx ${HASHCPP_SRC} ${HASHCPP_H})
target_link_libraries(fiftyone-hash-cxx
fiftyone-hash-c
fiftyone-device-detection-cxx)
if (MSVC)
target_compile_options(fiftyone-hash-cxx PRIVATE "/D_CRT_SECURE_NO_WARNINGS")
else()
target_compile_options(fiftyone-hash-cxx PRIVATE ${COMPILE_OPTION_DEBUG})
endif()

set_target_properties(fiftyone-hash-c fiftyone-hash-cxx
PROPERTIES FOLDER "Device Detection/Hash")
Expand All @@ -58,6 +70,11 @@ set_target_properties(fiftyone-hash-c fiftyone-hash-cxx
file(WRITE null.cpp "")
add_library(fiftyone-device-detection-complete SHARED null.cpp)
target_link_libraries(fiftyone-device-detection-complete fiftyone-hash-cxx)
if (MSVC)
target_compile_options(fiftyone-device-detection-complete PRIVATE "/D_CRT_SECURE_NO_WARNINGS")
else()
target_compile_options(fiftyone-device-detection-complete PRIVATE ${COMPILE_OPTION_DEBUG})
endif()

set_target_properties(fiftyone-device-detection-complete PROPERTIES PUBLIC_HEADER "${HASH}/hash.h")

Expand Down Expand Up @@ -85,17 +102,35 @@ foreach (api "Hash")
add_executable(${name} ${file}
${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/ExampleBase.cpp
${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/ExampleBase.hpp)
target_link_libraries(${name} fiftyone-${lowerapi}-cxx)
if (MSVC)
target_link_libraries(${name} fiftyone-${lowerapi}-cxx)
else()
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_include_directories(${name} PRIVATE "/usr/local/include")
target_link_directories(${name} PRIVATE "/usr/local/lib")
endif()
target_link_libraries(${name} fiftyone-${lowerapi}-cxx ${DMALLOC_LIB})
endif()
elseif("${langext}" STREQUAL "c")
MESSAGE("-- Found C example '${name}'")
add_executable(${name} ${file})
target_link_libraries(${name} fiftyone-${lowerapi}-c)
if (MSVC)
target_link_libraries(${name} fiftyone-${lowerapi}-c)
else()
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_include_directories(${name} PRIVATE "/usr/local/include")
target_link_directories(${name} PRIVATE "/usr/local/lib")
endif()
target_link_libraries(${name} fiftyone-${lowerapi}-c ${DMALLOC_LIB})
endif()
endif()
set_target_properties(${name}
PROPERTIES FOLDER
"Examples/Device Detection/${api}/${upperlangext}")
"Examples/Device Detection/${api}/${upperlangext}")
if (MSVC)
target_compile_options(${name} PRIVATE "/D_CRT_SECURE_NO_WARNINGS")
else()
target_compile_options(${name} PRIVATE ${COMPILE_OPTION_DEBUG})
endif()
endif()
endforeach()
Expand All @@ -119,17 +154,24 @@ add_library(fiftyone-device-detection-test-base
${COMMON_TEST}/EngineTests.cpp
${COMMON_TEST}/ExampleTests.cpp)
target_link_libraries(fiftyone-device-detection-test-base gtest_main)
if (NOT MSVC)
target_compile_options(fiftyone-device-detection-test-base PRIVATE ${COMPILE_OPTION_DEBUG})
endif()

set_target_properties(fiftyone-device-detection-test-base PROPERTIES FOLDER "Tests")

add_executable(HashTests ${HASH_TEST_SRC} ${HASH_TEST_H})
target_link_libraries(HashTests
fiftyone-device-detection-test-base
fiftyone-hash-cxx)
fiftyone-hash-cxx)
gtest_discover_tests(HashTests)

set_target_properties(HashTests PROPERTIES FOLDER "Tests")

# Don't enable _DEBUG here for Linux, because that will trigger
# dmalloc usage in Example tests which are not required for testing.
# Non-example code which require _DEBUG is dealed separately when
# building the specific libraries.
if (MSVC)
target_compile_options(HashTests PRIVATE "/D_CRT_SECURE_NO_WARNINGS")
endif()
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ If you have Visual Studio Code, you'll still need to install the build tools fro

### Linux

You will need [CMake 3.10](https://cmake.org/) or greater installed to build the project. In addition, you will need a C++ compiler which supports C++11. The compiler will and other build tools will be selected by CMake automatically based on your environment.
You will need:
- [CMake 3.10](https://cmake.org/) or greater installed to build the project.
- A C++ compiler which supports C++11. The compiler will and other build tools will be selected by CMake automatically based on your environment.
- dmalloc and dmallocth libraries installed when compiling the examples in Debug mode.


# Installing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="..\..\test\hash\ExampleHashReloadFromMemoryTests.cpp" />
<ClCompile Include="..\..\test\hash\ExampleHashStronglyTypedTests.cpp" />
<ClCompile Include="..\..\test\hash\ExampleHashTests.hpp" />
<ClCompile Include="..\..\test\hash\HashCTests.cpp" />
<ClCompile Include="..\..\test\hash\HashMemLeakReloadFromFileTests.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<ClCompile Include="..\..\test\hash\HashMemLeakReloadFromFileTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\hash\HashCTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\hash\hash.h">
Expand Down
149 changes: 143 additions & 6 deletions build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ stages:
testRunTitle: 'Windows CTest $(BuildPlatform) $(BuildConfiguration) $(BuildArguments)'
testResultsFiles: '**/Test.xml'


- stage: Linux
dependsOn: [Data]
jobs:
Expand All @@ -255,27 +256,35 @@ stages:
matrix:
debug x86 multi threads:
BuildConfiguration: Debug
BuildArguments: -DWin32=ON -DNoThreading=OFF
BuildPlatform: x86
BuildArguments: -D32bit=ON -DNoThreading=OFF
release x86 multi threads:
BuildConfiguration: Release
BuildArguments: -DWin32=ON -DNoThreading=OFF
BuildPlatform: x86
BuildArguments: -D32bit=ON -DNoThreading=OFF
debug x64 multi threads:
BuildConfiguration: Debug
BuildPlatform: x64
BuildArguments: -DNoThreading=OFF
release x64 multi threads:
BuildConfiguration: Release
BuildPlatform: x64
BuildArguments: -DNoThreading=OFF
debug x86 single thread:
BuildConfiguration: Debug
BuildArguments: -DWin32=ON -DNoThreading=ON
BuildPlatform: x86
BuildArguments: -D32bit=ON -DNoThreading=ON
release x86 single thread:
BuildConfiguration: Release
BuildArguments: -DWin32=ON -DNoThreading=ON
BuildPlatform: x86
BuildArguments: -D32bit=ON -DNoThreading=ON
debug x64 single thread:
BuildConfiguration: Debug
BuildPlatform: x64
BuildArguments: -DNoThreading=ON
release x64 single thread:
BuildConfiguration: Release
BuildPlatform: x64
BuildArguments: -DNoThreading=ON

steps:
Expand All @@ -284,6 +293,36 @@ stages:
submodules: recursive
lfs: true

- script: |
ulimit -c unlimited
echo "cat /proc/sys/kernel/core_pattern"
cat /proc/sys/kernel/core_pattern
echo "cat /proc/sys/kernel/core_uses_pid"
cat /proc/sys/kernel/core_uses_pid
echo "sudo systemctl enable apport.service"
sudo systemctl enable apport.service
echo "sysctl -w kernel.core_pattern=core.%p"
sudo sysctl -w kernel.core_pattern="core.%p"
cat /proc/sys/kernel/core_pattern
sudo apt-get -y install \
gcc-multilib \
g++-multilib
displayName: 'Install Required Packages'
- script: |
wget http://ftp.br.debian.org/debian/pool/main/d/dmalloc/libdmalloc-dev_5.5.2-6_i386.deb
sudo dpkg --add-architecture i386
sudo apt-get -y update
sudo dpkg -i libdmalloc-dev_5.5.2-6_i386.deb
sudo sudo apt-get -y install -f
displayName: 'Install Required 32bit Packages'
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'))
- script: |
sudo apt-get -y install libdmalloc-dev
displayName: 'Install Required 64bit Packages'
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x64'))
- task: DownloadBuildArtifacts@0
displayName: 'Download Enterprise Data File'
inputs:
Expand All @@ -306,13 +345,111 @@ stages:
displayName: 'CMake Configure'
inputs:
workingDirectory: build
cmakeArgs: '.. $(BuildArguments)'
cmakeArgs: '.. -DCMAKE_BUILD_TYPE=$(BuildConfiguration) $(BuildArguments)'

- task: CMake@1
displayName: 'CMake Build'
inputs:
workingDirectory: build
cmakeArgs: '--build . --config $(BuildConfiguration)'
cmakeArgs: '--build .'

- bash: 'ctest -E ".*TestOfflineProcessing.*" -T test --no-compress-output'
workingDirectory: build
failOnStderr: true
displayName: 'Run Tests'

- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
condition: failed()

- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
condition: failed()

- task: PublishTestResults@2
condition: true
inputs:
testResultsFormat: 'CTest'
testRunTitle: 'Linux CTest $(BuildConfiguration) $(BuildArguments)'
testResultsFiles: '**/Test.xml'


- stage: MacOS
dependsOn: [Data]
jobs:
- job: Build_And_Test

timeoutInMinutes: 240

pool:
vmImage: macOS-10.14

strategy:
matrix:
debug x64 multi threads:
BuildConfiguration: Debug
BuildPlatform: x64
BuildArguments: -DNoThreading=OFF
release x64 multi threads:
BuildConfiguration: Release
BuildPlatform: x64
BuildArguments: -DNoThreading=OFF
debug x64 single thread:
BuildConfiguration: Debug
BuildPlatform: x64
BuildArguments: -DNoThreading=ON
release x64 single thread:
BuildConfiguration: Release
BuildPlatform: x64
BuildArguments: -DNoThreading=ON

steps:

- checkout: self
submodules: recursive
lfs: true

- script: |
brew search dmalloc
brew install dmalloc
displayName: 'Install Required Packages'
- task: DownloadBuildArtifacts@0
displayName: 'Download Enterprise Data File'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'enterpriseFile'
downloadPath: '$(System.ArtifactsDirectory)'

- script: |
mv $(System.ArtifactsDirectory)/enterpriseFile/51Degrees-EnterpriseV4.1.hash $(Build.SourcesDirectory)/device-detection-data/51Degrees-EnterpriseV4.1.hash
displayName: 'Move Data File'
- task: Bash@3
displayName: 'Create Build Directory'
inputs:
targetType: 'inline'
script: 'mkdir build'

- task: CMake@1
displayName: 'CMake Configure'
inputs:
workingDirectory: build
cmakeArgs: '.. -DCMAKE_BUILD_TYPE=$(BuildConfiguration) $(BuildArguments)'

- task: CMake@1
displayName: 'CMake Build'
inputs:
workingDirectory: build
cmakeArgs: '--build .'

- bash: 'ctest -E ".*TestOfflineProcessing.*" -T test --no-compress-output'
workingDirectory: build
Expand Down
16 changes: 10 additions & 6 deletions examples/C/Hash/FindProfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,25 @@ fiftyoneDegreesHashIterateProfilesForPropertyAndValue(
fiftyoneDegreesResourceManagerFree(&manager);
```
*/
#include <stdio.h>

#ifdef _DEBUG
#ifdef _MSC_VER
// Windows 'crtdbg.h' needs to be included
// before 'malloc.h'
#if defined(_DEBUG) && defined(_MSC_VER)
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include "dmalloc.h"
#endif
#endif

#include <stdio.h>
#include "../../../src/hash/hash.h"
#include "../../../src/hash/fiftyone.h"

// 'dmalloc.h' needs to be included after
// 'string.h'
#if defined(_DEBUG) && !defined(_MSC_VER)
#include "dmalloc.h"
#endif

static const char *dataDir = "device-detection-data";

static const char *dataFileName = "51Degrees-LiteV4.1.hash";
Expand Down
Loading

0 comments on commit cf2ad7c

Please sign in to comment.