Skip to content

Commit

Permalink
Fix ycm_core_tests build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
micbou committed Sep 21, 2015
1 parent 621e861 commit 38cd95d
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 27 deletions.
7 changes: 6 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ def RunYcmdTests( build_dir ):
tests_dir = p.join( build_dir, 'ycm', 'tests' )
os.chdir( tests_dir )
new_env = os.environ.copy()
new_env[ 'LD_LIBRARY_PATH' ] = DIR_OF_THIS_SCRIPT

if OnWindows():
new_env[ 'PATH' ] = DIR_OF_THIS_SCRIPT
else:
new_env[ 'LD_LIBRARY_PATH' ] = DIR_OF_THIS_SCRIPT

subprocess.check_call( p.join( tests_dir, 'ycm_core_tests' ), env = new_env )


Expand Down
11 changes: 6 additions & 5 deletions cpp/ycm/Candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef CANDIDATE_H_R5LZH6AC
#define CANDIDATE_H_R5LZH6AC

#include "DLLDefines.h"
#include "LetterNode.h"

#include <boost/scoped_ptr.hpp>
Expand All @@ -32,15 +33,15 @@ class Result;

typedef std::bitset< NUM_LETTERS > Bitset;

Bitset LetterBitsetFromString( const std::string &text );
YCM_DLL_EXPORT Bitset LetterBitsetFromString( const std::string &text );

// Public for tests
std::string GetWordBoundaryChars( const std::string &text );
YCM_DLL_EXPORT std::string GetWordBoundaryChars( const std::string &text );

class Candidate : boost::noncopyable {
public:

explicit Candidate( const std::string &text );
YCM_DLL_EXPORT explicit Candidate( const std::string &text );

inline const std::string &Text() const {
return text_;
Expand All @@ -52,8 +53,8 @@ class Candidate : boost::noncopyable {
return ( letters_present_ & query_bitset ) == query_bitset;
}

Result QueryMatchResult( const std::string &query,
bool case_sensitive ) const;
YCM_DLL_EXPORT Result QueryMatchResult( const std::string &query,
bool case_sensitive ) const;

private:
std::string text_;
Expand Down
6 changes: 4 additions & 2 deletions cpp/ycm/CandidateRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef CANDIDATEREPOSITORY_H_K9OVCMHG
#define CANDIDATEREPOSITORY_H_K9OVCMHG

#include "DLLDefines.h"

#include <boost/utility.hpp>
#include <boost/unordered_map.hpp>
#include <boost/thread/mutex.hpp>
Expand All @@ -44,11 +46,11 @@ CandidateHolder;
// This class is thread-safe.
class CandidateRepository : boost::noncopyable {
public:
static CandidateRepository &Instance();
YCM_DLL_EXPORT static CandidateRepository &Instance();

int NumStoredCandidates();

std::vector< const Candidate * > GetCandidatesForStrings(
YCM_DLL_EXPORT std::vector< const Candidate * > GetCandidatesForStrings(
const std::vector< std::string > &strings );

#ifdef USE_CLANG_COMPLETER
Expand Down
9 changes: 5 additions & 4 deletions cpp/ycm/ClangCompleter/ClangCompleter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef CLANGCOMPLETE_H_WLKDU0ZV
#define CLANGCOMPLETE_H_WLKDU0ZV

#include "../DLLDefines.h"
#include "UnsavedFile.h"
#include "Diagnostic.h"
#include "TranslationUnitStore.h"
Expand All @@ -41,8 +42,8 @@ typedef std::vector< CompletionData > CompletionDatas;
// All filename parameters must be absolute paths.
class ClangCompleter : boost::noncopyable {
public:
ClangCompleter();
~ClangCompleter();
YCM_DLL_EXPORT ClangCompleter();
YCM_DLL_EXPORT ~ClangCompleter();

bool UpdatingTranslationUnit( const std::string &filename );

Expand All @@ -51,7 +52,7 @@ class ClangCompleter : boost::noncopyable {
const std::vector< UnsavedFile > &unsaved_files,
const std::vector< std::string > &flags );

std::vector< CompletionData > CandidatesForLocationInFile(
YCM_DLL_EXPORT std::vector< CompletionData > CandidatesForLocationInFile(
const std::string &filename,
int line,
int column,
Expand All @@ -66,7 +67,7 @@ class ClangCompleter : boost::noncopyable {
const std::vector< std::string > &flags,
bool reparse = true );

Location GetDefinitionLocation(
YCM_DLL_EXPORT Location GetDefinitionLocation(
const std::string &filename,
int line,
int column,
Expand Down
9 changes: 5 additions & 4 deletions cpp/ycm/ClangCompleter/TranslationUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef TRANSLATIONUNIT_H_XQ7I6SVA
#define TRANSLATIONUNIT_H_XQ7I6SVA

#include "../DLLDefines.h"
#include "UnsavedFile.h"
#include "Diagnostic.h"
#include "Location.h"
Expand All @@ -43,13 +44,13 @@ class TranslationUnit : boost::noncopyable {
// no callers try to rely on the invalid TU.
TranslationUnit();

TranslationUnit(
YCM_DLL_EXPORT TranslationUnit(
const std::string &filename,
const std::vector< UnsavedFile > &unsaved_files,
const std::vector< std::string > &flags,
CXIndex clang_index );

~TranslationUnit();
YCM_DLL_EXPORT ~TranslationUnit();

void Destroy();

Expand All @@ -67,13 +68,13 @@ class TranslationUnit : boost::noncopyable {
int column,
const std::vector< UnsavedFile > &unsaved_files );

Location GetDeclarationLocation(
YCM_DLL_EXPORT Location GetDeclarationLocation(
int line,
int column,
const std::vector< UnsavedFile > &unsaved_files,
bool reparse = true );

Location GetDefinitionLocation(
YCM_DLL_EXPORT Location GetDefinitionLocation(
int line,
int column,
const std::vector< UnsavedFile > &unsaved_files,
Expand Down
29 changes: 29 additions & 0 deletions cpp/ycm/DLLDefines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2015 ycmd contributors
//
// This file is part of ycmd.
//
// ycmd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ycmd is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ycmd. If not, see <http://www.gnu.org/licenses/>.

#ifndef DLLDEFINES_H_0IYA3AQ3
#define DLLDEFINES_H_0IYA3AQ3

// We need to export symbols for gmock tests on Windows. The preprocessor
// symbol ycm_core_EXPORTS is defined by CMake when building a shared library.
#if defined( _WIN32 ) && defined( ycm_core_EXPORTS )
#define YCM_DLL_EXPORT __declspec( dllexport )
#else
#define YCM_DLL_EXPORT
#endif

#endif /* end of include guard: DLLDEFINES_H_0IYA3AQ3 */
12 changes: 7 additions & 5 deletions cpp/ycm/IdentifierCompleter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef COMPLETER_H_7AR4UGXE
#define COMPLETER_H_7AR4UGXE

#include "DLLDefines.h"
#include "IdentifierDatabase.h"

#include <boost/utility.hpp>
Expand All @@ -36,8 +37,9 @@ class Candidate;

class IdentifierCompleter : boost::noncopyable {
public:
IdentifierCompleter();
IdentifierCompleter( const std::vector< std::string > &candidates );
YCM_DLL_EXPORT IdentifierCompleter();
YCM_DLL_EXPORT IdentifierCompleter(
const std::vector< std::string > &candidates );
IdentifierCompleter( const std::vector< std::string > &candidates,
const std::string &filetype,
const std::string &filepath );
Expand All @@ -54,7 +56,7 @@ class IdentifierCompleter : boost::noncopyable {
const std::string &filetype,
const std::string &filepath );

void AddIdentifiersToDatabaseFromTagFiles(
YCM_DLL_EXPORT void AddIdentifiersToDatabaseFromTagFiles(
const std::vector< std::string > &absolute_paths_to_tag_files );

void AddIdentifiersToDatabaseFromBuffer(
Expand All @@ -64,10 +66,10 @@ class IdentifierCompleter : boost::noncopyable {
bool collect_from_comments_and_strings );

// Only provided for tests!
std::vector< std::string > CandidatesForQuery(
YCM_DLL_EXPORT std::vector< std::string > CandidatesForQuery(
const std::string &query ) const;

std::vector< std::string > CandidatesForQueryAndType(
YCM_DLL_EXPORT std::vector< std::string > CandidatesForQueryAndType(
const std::string &query,
const std::string &filetype ) const;

Expand Down
3 changes: 2 additions & 1 deletion cpp/ycm/IdentifierUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef IDENTIFIERUTILS_CPP_WFFUZNET
#define IDENTIFIERUTILS_CPP_WFFUZNET

#include "DLLDefines.h"
#include "IdentifierDatabase.h"

#include <vector>
Expand All @@ -27,7 +28,7 @@

namespace YouCompleteMe {

FiletypeIdentifierMap ExtractIdentifiersFromTagsFile(
YCM_DLL_EXPORT FiletypeIdentifierMap ExtractIdentifiersFromTagsFile(
const boost::filesystem::path &path_to_tag_file );

} // namespace YouCompleteMe
Expand Down
8 changes: 5 additions & 3 deletions cpp/ycm/LetterNodeListMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef LETTERNODELISTMAP_H_BRK2UMC1
#define LETTERNODELISTMAP_H_BRK2UMC1

#include "DLLDefines.h"

#include <list>
#include <boost/utility.hpp>
#include <boost/array.hpp>
Expand All @@ -28,13 +30,13 @@ namespace YouCompleteMe {

class LetterNode;

int IndexForChar( char letter );
bool IsUppercase( char letter );
YCM_DLL_EXPORT int IndexForChar( char letter );
YCM_DLL_EXPORT bool IsUppercase( char letter );

class LetterNodeListMap : boost::noncopyable {
public:
LetterNodeListMap();
~LetterNodeListMap();
YCM_DLL_EXPORT ~LetterNodeListMap();

bool HasLetter( char letter );

Expand Down
5 changes: 4 additions & 1 deletion cpp/ycm/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef UTILS_H_KEPMRPBH
#define UTILS_H_KEPMRPBH

#include "DLLDefines.h"

#include <string>
#include <vector>
#include <boost/filesystem.hpp>
Expand All @@ -33,7 +35,8 @@ std::string ReadUtf8File( const fs::path &filepath );

// Writes the entire contents of the specified file. If the file does not exist,
// an exception is thrown.
void WriteUtf8File( const fs::path &filepath, const std::string &contents );
YCM_DLL_EXPORT void WriteUtf8File( const fs::path &filepath,
const std::string &contents );

template <class Container, class Key>
typename Container::mapped_type &
Expand Down
29 changes: 28 additions & 1 deletion cpp/ycm/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ if ( USE_SYSTEM_GMOCK )
find_package( GTest REQUIRED )
find_package( GMock REQUIRED )
else()
if ( WIN32 )
# Override BUILD_SHARED_LIBS option in gmock and gtest CMakeLists
set( BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries (DLLs)." )
endif()

add_subdirectory( gmock )
set( GTEST_INCLUDE_DIRS ${gtest_SOURCE_DIR} ${gtest_SOURCE_DIR}/include )
set( GMOCK_INCLUDE_DIRS ${gmock_SOURCE_DIR} ${gmock_SOURCE_DIR}/include )
Expand Down Expand Up @@ -77,13 +82,35 @@ add_executable( ${PROJECT_NAME}
${SOURCES}
)

if ( MSVC )
# This is needed to compile tests with the gtest shared library
set_target_properties( ${PROJECT_NAME}
PROPERTIES
COMPILE_DEFINITIONS
"GTEST_LINKED_AS_SHARED_LIBRARY=1" )

# Fix gtest build on MSVC 11. See: http://stackoverflow.com/a/8274747
if ( MSVC_VERSION EQUAL 1700 )
add_definitions( /D _VARIADIC_MAX=10 )
endif()

# Build gmock and ycm_core_tests targets in cmake ycm/tests folder
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set_target_properties( ${GMOCK_LIBRARIES} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} )
set_target_properties( ${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_BINARY_DIR} )
endforeach()
endif()

target_link_libraries( ${PROJECT_NAME}
${Boost_LIBRARIES}
${SERVER_LIB}
${CLIENT_LIB}
${GTEST_LIBRARIES}
${GMOCK_LIBRARIES} )


if ( NOT CMAKE_GENERATOR_IS_XCODE )
# The test executable expects a "testdata" dir in its working directory. Why?
# Because there's NO reliable, cross-platform way of getting the directory in
Expand Down

0 comments on commit 38cd95d

Please sign in to comment.