From b542c821d1c84d9844e897527d41f55aa60fbe42 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:46:15 -0700 Subject: [PATCH 01/12] new .props that has c++ dependencies --- vsprojects/cpptest.props | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 vsprojects/cpptest.props diff --git a/vsprojects/cpptest.props b/vsprojects/cpptest.props new file mode 100644 index 00000000000..c5ffd54f990 --- /dev/null +++ b/vsprojects/cpptest.props @@ -0,0 +1,18 @@ + + + + + + + + $(ProjectDir)\..\..;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\third_party\protobuf\src;$(ProjectDir)\..\..\third_party\gtest\include;%(AdditionalIncludeDirectories) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions) + EnableAllWarnings + + + grpc++_test_util.lib;grpc_test_util.lib;gpr_test_util.lib;gtestd.lib;gflags.lib;shlwapi.lib;gpr.lib;grpc.lib;grpc++.lib;%(AdditionalDependencies) + $(ProjectDir)\..\..\third_party\gtest\msvc\gtest\Debug;$(ProjectDir)\..\..\third_party\gflags\lib\Debug;$(ProjectDir)\..\Debug;$(ProjectDir)\..\packages\grpc.dependencies.openssl.1.0.2.2\build\native\lib\$(PlatformToolset)\$(Platform)\$(Configuration)\static;%(AdditionalLibraryDirectories) + + + + From b19d4ebba01b5a90b69230bcfdd7426bc791aacf Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:47:54 -0700 Subject: [PATCH 02/12] changed vsproject generation to make c++ tests; put a hint in the .sln about lib vs. target; expand .proto includes --- templates/vsprojects/vcxproj_defs.include | 27 ++++++++++++++++--- tools/buildgen/plugins/generate_vsprojects.py | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/templates/vsprojects/vcxproj_defs.include b/templates/vsprojects/vcxproj_defs.include index 55ec37393fa..39c73860629 100644 --- a/templates/vsprojects/vcxproj_defs.include +++ b/templates/vsprojects/vcxproj_defs.include @@ -12,19 +12,21 @@ if t.name == name: target = t if not configuration_type and target: + print target.name if target.build == 'test' or target.build == 'tool': configuration_type = 'Application' if not configuration_type: configuration_type = 'StaticLibrary' if not project_guid: project_guid = project.vs_project_guid + if target.build == 'test' and target.language == 'c++': + props.extend(['cpptest']) if configuration_type == 'Application': + print target.build if target.build == 'protoc': props.extend(['protoc']) else: props.extend(['winsock', 'protobuf', 'zlib', 'openssl']) - if target.language == 'c++': - props.extend(['protobuf']) props.extend(['global']) %>\ @@ -113,6 +115,13 @@ ${gen_package_props(packages)}\ ${name} + % if "zlib" in packages: + static + Debug + % endif + % if "openssl" in packages: + Debug + % endif ${name} @@ -200,8 +209,20 @@ ${gen_package_props(packages)}\ % if project.get('src',[]): % for src_name in project.src: + % if src_name.endswith(".proto"): +<% src_name_parts = src_name.split(".") %>\ + + + + + + + + + % else: + % endif % endfor % elif configuration_type != 'StaticLibrary': @@ -230,4 +251,4 @@ ${gen_package_targets(packages)}\ ${gen_package_ensure(packages)}\ -\ \ No newline at end of file +\ diff --git a/tools/buildgen/plugins/generate_vsprojects.py b/tools/buildgen/plugins/generate_vsprojects.py index 150e72e0b26..413056fe89f 100755 --- a/tools/buildgen/plugins/generate_vsprojects.py +++ b/tools/buildgen/plugins/generate_vsprojects.py @@ -70,7 +70,7 @@ def mako_plugin(dictionary): if project.get('vs_project_guid', None)] projects = [project for project in projects - if project['language'] != 'c++' or project['build'] == 'all' or project['build'] == 'protoc'] + if project['language'] != 'c++' or project['build'] == 'all' or project['build'] == 'protoc' or (project['language'] == 'c++' and (project['build'] == 'test' or project['build'] == 'private'))] project_dict = dict([(p['name'], p) for p in projects]) From 6e081e0453b8194bb389ebd811bdc253551045d2 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:48:35 -0700 Subject: [PATCH 03/12] changed .sln to include hint about lib vs. target --- templates/vsprojects/sln_defs.include | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/templates/vsprojects/sln_defs.include b/templates/vsprojects/sln_defs.include index ee05d0fbde2..4ba0fbff075 100644 --- a/templates/vsprojects/sln_defs.include +++ b/templates/vsprojects/sln_defs.include @@ -15,6 +15,13 @@ cpp_proj_type = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" %>\ % for project in solution_projects: Project("${cpp_proj_type}") = "${project.name}", "${project.name}\${project.name}.vcxproj", "${project.vs_project_guid}" + ProjectSection(myProperties) = preProject + % if project.is_library: + lib = "True" + % else: + lib = "False" + % endif + EndProjectSection % if project.get('deps', None): ProjectSection(ProjectDependencies) = postProject % for dep in project.get('deps', []): @@ -47,4 +54,4 @@ Global HideSolutionNode = FALSE EndGlobalSection EndGlobal -\ \ No newline at end of file +\ From 1ee691d92291cfb4553f19d17329963b11feee85 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:49:59 -0700 Subject: [PATCH 04/12] changed generate_debug_projects.sh to use the .sln hint when making vcxproj templates --- .../vsprojects/generate_debug_projects.sh | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/templates/vsprojects/generate_debug_projects.sh b/templates/vsprojects/generate_debug_projects.sh index 1bbe40b6c8b..f103ebe01a9 100755 --- a/templates/vsprojects/generate_debug_projects.sh +++ b/templates/vsprojects/generate_debug_projects.sh @@ -37,26 +37,40 @@ cd `dirname $0`/../.. -./tools/buildgen/generate_projects.sh +git add . #because we're using "git diff" to find changes to grpc.sln and then make files based on those changes, this prevents this file or other files from possibly being found in the diff -git diff | -grep \\+Project | -cut -d\" -f 4 | -sort -u | -grep _test$ | -while read p ; do - mkdir -p templates/vsprojects/$p - echo '<%namespace file="../vcxproj_defs.include" import="gen_project"/>${gen_project("'$p'", targets)}' > templates/vsprojects/$p/$p.vcxproj.template -done +./tools/buildgen/generate_projects-old.sh + +line_number=0 git diff | -grep \\+Project | -cut -d\" -f 4 | -sort -u | -grep -v _test$ | +grep -A2 \\+Project | #find "Project" immediately after a backslash (escaped), plus 2 additional lines to capture the "libs = ", plus 1 line of "--". matches will come from the generated grpc.sln while read p ; do - mkdir -p templates/vsprojects/$p - echo '<%namespace file="../vcxproj_defs.include" import="gen_project"/>${gen_project("'$p'", libs)}' > templates/vsprojects/$p/$p.vcxproj.template + line_number=$((line_number + 1)) + if [ "$line_number" -gt "4" ]; then + line_number=1; + fi + echo $line_number + echo $p + if [ "$line_number" -eq "1" ]; then + project_name=$(echo "$p" | cut -d\" -f 4) #sed: extract line N only; cut with delimiter: ". select only field 4 + fi + if [ "$line_number" -eq "3" ]; then + lib_setting=$(echo "$p" | cut -d\" -f 2) # + echo "project_name" + echo $project_name + echo "lib_setting" + echo $lib_setting + mkdir -p templates/vsprojects/$project_name + if [ "$lib_setting" = "True" ]; then + echo "lib: true" + echo '<%namespace file="../vcxproj_defs.include" import="gen_project"/>${gen_project("'$project_name'", libs)}' > templates/vsprojects/$project_name/$project_name.vcxproj.template + else + echo "lib: not true" + echo '<%namespace file="../vcxproj_defs.include" import="gen_project"/>${gen_project("'$project_name'", targets)}' > templates/vsprojects/$project_name/$project_name.vcxproj.template + fi + fi + # sleep .5 #for testing done -./tools/buildgen/generate_projects.sh +./tools/buildgen/generate_projects-old.sh From c27b25f78982f06a789c0fe19e9e2dfc1537e064 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:50:37 -0700 Subject: [PATCH 05/12] new includes / one less warning --- vsprojects/global.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vsprojects/global.props b/vsprojects/global.props index 14acf4668b3..6858bd7b9d4 100644 --- a/vsprojects/global.props +++ b/vsprojects/global.props @@ -5,10 +5,10 @@ - $(ProjectDir)\..\..;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\third_party\protobuf\src;$(AdditionalIncludeDirectories) - _CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions) + $(ProjectDir)\..\..;$(ProjectDir)\..\..\include;$(ProjectDir)\..\..\third_party\protobuf\src;$(ProjectDir)\..\packages\grpc.dependencies.openssl.1.0.2.2\build\native\include;$(ProjectDir)\..\..\third_party\gflags\include;%(AdditionalIncludeDirectories) + _SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions) EnableAllWarnings - \ No newline at end of file + From 845019c1d1afcb628312913cab87f769e3bf7c39 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:51:03 -0700 Subject: [PATCH 06/12] helper script to build all .proto files in /test/ in-place --- templates/vsprojects/build_test_protos.sh | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 templates/vsprojects/build_test_protos.sh diff --git a/templates/vsprojects/build_test_protos.sh b/templates/vsprojects/build_test_protos.sh new file mode 100644 index 00000000000..54edd3699af --- /dev/null +++ b/templates/vsprojects/build_test_protos.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +GRPC_CPP_PLUGIN_PATH=`which grpc_cpp_plugin` + +cd `dirname $0`/../.. + +find ./test -type f -name "*.proto" | +while read p ; do + echo "processing $p" + DIR=$(dirname "$p") + protoc $p --grpc_out=./ --plugin=protoc-gen-grpc=$GRPC_CPP_PLUGIN_PATH + protoc $p --cpp_out=./ +done From 878b63e1eba6a5ccc99ffde67c216f081e9cda0f Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:51:31 -0700 Subject: [PATCH 07/12] old not parallel version of generate_projects.sh, for debuggin --- tools/buildgen/generate_projects-old.sh | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tools/buildgen/generate_projects-old.sh diff --git a/tools/buildgen/generate_projects-old.sh b/tools/buildgen/generate_projects-old.sh new file mode 100644 index 00000000000..53998677465 --- /dev/null +++ b/tools/buildgen/generate_projects-old.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +set -e + +if [ "x$TEST" = "x" ] ; then + TEST=false +fi + + +cd `dirname $0`/../.. +mako_renderer=tools/buildgen/mako_renderer.py + +if [ "x$TEST" != "x" ] ; then + tools/buildgen/build-cleaner.py build.json +fi + +. tools/buildgen/generate_build_additions.sh + +global_plugins=`find ./tools/buildgen/plugins -name '*.py' | + sort | grep -v __init__ | awk ' { printf "-p %s ", $0 } '` + +for dir in . ; do + local_plugins=`find $dir/templates -name '*.py' | + sort | grep -v __init__ | awk ' { printf "-p %s ", $0 } '` + + plugins="$global_plugins $local_plugins" + + find -L $dir/templates -type f -and -name *.template | while read file ; do + out=${dir}/${file#$dir/templates/} # strip templates dir prefix + out=${out%.*} # strip template extension + echo "generating file: $out" + json_files="build.json $gen_build_files" + data=`for i in $json_files ; do echo $i ; done | awk ' { printf "-d %s ", $0 } '` + if [ "x$TEST" = "xtrue" ] ; then + actual_out=$out + out=`mktemp /tmp/gentXXXXXX` + fi + mkdir -p `dirname $out` # make sure dest directory exist + $mako_renderer $plugins $data -o $out $file + if [ "x$TEST" = "xtrue" ] ; then + diff -q $out $actual_out + rm $out + fi + done +done + +rm $gen_build_files From d6fafad06761b46ada8c6b64a7fae2032ef34377 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:51:52 -0700 Subject: [PATCH 08/12] documentation of new vcxproj/.sln debug buildgen --- vsprojects/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/vsprojects/README.md b/vsprojects/README.md index dade9e500e2..06e87b3aed2 100644 --- a/vsprojects/README.md +++ b/vsprojects/README.md @@ -19,8 +19,38 @@ After that, you can build the solution using one of these options: 1. open `grpc.sln` with Visual Studio and hit "Build". 2. build from commandline using `msbuild grpc.sln /p:Configuration=Debug` +#C/C++ Test Dependencies + * gtest isn't available as a git repo like the other dependencies. download it and add it to `/third_party/gtest/` (the folder will end up with `/build-aux/`, `/cmake/`, `/codegear/`, etc. folders in it). + * if using vs2013: open/import the gtest solution in `/msvc/`, and save over the first solution (you will have to change it from read-only). change all projects to use `/MDd` (Property Pages - C/C++ - Code Generation - Runtime Library) and build. This is a "multithreaded debug" setting and it needs to match grpc. + * build all + * open protobuf solution in `/third_party/protobuf/vsprojects` + * if using vs2013: on import the gtest stuff will probably fail, I think the paths are interpreted wrong. it's ok. + * tests and test_plugin will fail when built. also ok + * build all + * gflags is automatically imported as a git submodule but it needs to have CMake run on it to be ready for a specific platform + * download [CMake](http://www.cmake.org/) windows installer; install + * open visual studio developer command prompt (not sure if dev command prompt is necessary) + * run `cmake ` + * this will build a `.sln` and fill up the `/third_party/gflags/include/gflags/` directory with headers + * build all + * install [NuGet](http://www.nuget.org) + * nuget should automatically bring in built versions of zlib and openssl when building grpc.sln (the versions in `/third_party/` are not used). If it doesn't work use `tools->nuget...->manage...`. The packages are put in `/vsprojects/packages/` + +#C/C++ Test Build Steps + * set up dependencies (above) + * add `"debug": true,` to the top of build.json. This is the base file for all build tracking, see [templates](https://github.com/grpc/grpc/tree/master/templates) for more information + * `"debug": true,` gets picked up by `/tools/buildgen/plugins/generate_vsprojects.py`. It tells the script to add visual studio GUIDs to all projects. Otherwise only the projects that already have GUIDs in build.json will be built + * A basic git version of grpc only has templates for non-test items. run `/templates/vsprojects/generate_debug_projects.sh` to make debug templates/projects. This runs a regular visual studio buildgen process, which creates the `.sln` file with all of the new debug projects, then uses git diff to find the new project names from the `.sln` that need templates added. It builds the new templates based on the diff, then re-runs the visual studio buildgen, which builds the vs projects for each of the new debug targets + * copy over the `/vsprojects/` folder to your windows build setup (assuming this was built on linux in order to have easy access to python/mako and shell scripts) + * run `/templates/vsprojects/build_test_protos.sh` + * this builds all `.proto` files in `/test/` in-place. there might be a better place to put them that mirrors what happens in the linux build process (todo) + * each `.proto` file gets built into a `.grpc.pb.cc`, .`grpc.pb.h`, `.pb.cc`, and `.pb.h`. These are included in each test project in lieu of the `.proto` includes specified in `build.json`. This substitution is done by `/templates/vsprojects/vcxproj_defs.include` + * copy over the `/test/` folder in order to get the new files (assuming this was built on linux in order to have an easy protobuf+grpc plugin installation) + #Testing +This is incomplete (only runs some tests for now), todo. The above .sln-based buildgen makes more tets but isn't tied in to automatic test running yet. + Use `run_tests.py`, that also supports Windows (with a bit limited experience). ``` > REM Run from repository root. From 2c960065e20bba00df6f590eb090d70a705e8cf2 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:52:08 -0700 Subject: [PATCH 09/12] nmake: continue on error --- vsprojects/make.bat | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vsprojects/make.bat b/vsprojects/make.bat index 04737aeefc4..08c97bcd21f 100644 --- a/vsprojects/make.bat +++ b/vsprojects/make.bat @@ -5,6 +5,7 @@ setlocal @rem Set VS variables (uses Visual Studio 2013) @call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" x86 -nmake /f Grpc.mak %* +@rem /K: continue on error +nmake /K /f Grpc.mak %* exit /b %ERRORLEVEL% -endlocal \ No newline at end of file +endlocal From c58e50137327760a5b046a357cec9b1462844690 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Sun, 19 Jul 2015 10:52:32 -0700 Subject: [PATCH 10/12] changes to grpc.mak.template to support c++ test building --- templates/vsprojects/Grpc.mak.template | 73 ++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/templates/vsprojects/Grpc.mak.template b/templates/vsprojects/Grpc.mak.template index 9d85376648b..9d2f676d380 100644 --- a/templates/vsprojects/Grpc.mak.template +++ b/templates/vsprojects/Grpc.mak.template @@ -33,16 +33,18 @@ <%def name="to_windows_path(path)">${path.replace('/','\\')}\ <% build_from_project_file = set(['gpr', - 'grpc', - 'grpc_unsecure', 'gpr_test_util', + 'grpc', 'grpc_test_util', 'grpc_test_util_unsecure', + 'grpc_unsecure', + 'grpc++', + 'grpc++_unsecure' ]) buildable_targets = [ target for target in targets + libs if target.build in ['all', 'test', 'private', 'tool', 'benchmark'] and target.language in ['c', 'c++'] and - all([src.endswith('.c') for src in target.src]) and + all([(src.endswith('.c') or src.endswith('.cc') or src.endswith('.proto')) for src in target.src]) and 'windows' in target.get('platforms', ['windows']) ] c_test_targets = [ target for target in buildable_targets if target.build == 'test' and not target.language == 'c++' ] cxx_test_targets = [ target for target in buildable_targets if target.build == 'test' and target.language == 'c++' ] @@ -60,8 +62,19 @@ REPO_ROOT=.. OPENSSL_INCLUDES = .\packages\${get_openssl()}\build\native\include ZLIB_INCLUDES = .\packages\${get_zlib()}\build\native\include INCLUDES=/I$(REPO_ROOT) /I$(REPO_ROOT)\include /I$(OPENSSL_INCLUDES) /I$(ZLIB_INCLUDES) -DEFINES=/D WIN32 /D _LIB /D _USE_32BIT_TIME_T /D _UNICODE /D UNICODE /D _CRT_SECURE_NO_WARNINGS + +GFLAGS_INCLUDES = .\..\third_party\gflags\include +GTEST_INCLUDES = .\..\third_party\gtest\include +PROTOBUF_INCLUDES = .\..\third_party\protobuf\src +CXX_INCLUDES=/I$(GFLAGS_INCLUDES) /I$(GTEST_INCLUDES) /I$(PROTOBUF_INCLUDES) + +#_SCL_SECURE_NO_WARNINGS supresses a ton of "potentially unsafe use of std lib" warnings +DEFINES=/D WIN32 /D _LIB /D _USE_32BIT_TIME_T /D _UNICODE /D UNICODE /D _CRT_SECURE_NO_WARNINGS /D _SCL_SECURE_NO_WARNINGS + +#important options: /TC vs. /TP: compile as C vs. compile as C++ CFLAGS=/c $(INCLUDES) /Z7 /W3 /WX- /sdl $(DEFINES) /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TC /analyze- +CXXFLAGS=/c $(INCLUDES) $(CXX_INCLUDES) /Z7 /W3 /WX- /sdl $(DEFINES) /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Gd /TP /analyze- + LFLAGS=/DEBUG /INCREMENTAL /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 OPENSSL_LIBS=.\packages\${get_openssl()}\build\native\lib\v120\Win32\Debug\static\ssleay32.lib .\packages\${get_openssl()}\build\native\lib\v120\Win32\Debug\static\libeay32.lib @@ -70,6 +83,12 @@ GENERAL_LIBS=advapi32.lib comdlg32.lib gdi32.lib kernel32.lib odbc32.lib odbccp3 ZLIB_LIBS=.\packages\${get_zlib()}\build\native\lib\v120\Win32\Debug\static\cdecl\zlib.lib LIBS=$(OPENSSL_LIBS) $(ZLIB_LIBS) $(GENERAL_LIBS) $(WINSOCK_LIBS) +#shlwapi.lib provides PathMatchSpec() for gflags in windows +GFLAGS_LIBS=.\..\third_party\gflags\lib\Debug\gflags.lib shlwapi.lib +GTEST_LIBS=.\..\third_party\gtest\msvc\gtest\Debug\gtestd.lib +PROTOBUF_LIBS=.\..\third_party\protobuf\vsprojects\Debug\libprotobuf.lib +CXX_LIBS=$(GFLAGS_LIBS) $(GTEST_LIBS) $(PROTOBUF_LIBS) + all: buildtests tools: @@ -99,16 +118,33 @@ buildtests_c: \ ${target.name}.exe \ % endfor - echo All tests built. + echo All C tests built. buildtests_cxx: \ % for target in cxx_test_targets: ${target.name}.exe \ % endfor - echo All tests built. + echo All C++ tests built. % for target in buildable_targets: + +## replace all .proto includes with .pb.cc / .grpc.pb.cc +%if target.src: +%for source in target.src: +%if source.endswith(".proto"): +<% + src_name_parts = source.split(".") + target.src.append(src_name_parts[0] + ".pb.cc") + target.src.append(src_name_parts[0] + ".grpc.pb.cc") +%>\ +%endif +%endfor +%endif +## remove all .proto includes +<% + target.src = [item for item in target.src if not re.search('([^/]+)\.proto$', item)] +%>\ %if target.name in build_from_project_file: build_${target.name}: msbuild grpc.sln /t:${target.name} /p:Configuration=Debug /p:Linkage-grpc_dependencies_zlib=static @@ -116,11 +152,22 @@ build_${target.name}: %if target.build == 'private': Debug\${target.name}.lib: \ %else: -${target.name}.exe: build_libs \ +${target.name}.exe: \ +%for dep in target.get('deps', []): +%if dep in build_from_project_file: +build_${dep} \ +%else: +Debug\${dep}.lib \ +%endif +%endfor %endif $(OUT_DIR) echo Building ${target.name} +%if target.language == 'c++': + $(CC) $(CXXFLAGS) /Fo:$(OUT_DIR)\ \ +%else: $(CC) $(CFLAGS) /Fo:$(OUT_DIR)\ \ +%endif %for source in target.src: $(REPO_ROOT)\${to_windows_path(source)} \ %endfor @@ -135,13 +182,19 @@ $(REPO_ROOT)\${to_windows_path('vsprojects/dummy.c')} \ %for dep in target.get('deps', []): Debug\${dep}.lib \ %endfor +%if target.language == 'c++': +$(CXX_LIBS) \ +%endif $(LIBS) \ %endif -%for source in target.src: -$(OUT_DIR)\${re.search('([^/]+)\.c$', source).group(1)}.obj \ -%endfor %if not target.src: $(OUT_DIR)\dummy.obj \ +%else: +%for source in target.src: +%if re.search('([^/]+)\.c{1,2}$', source): +$(OUT_DIR)\${re.search('([^/]+)\.c{1,2}$', source).group(1)}.obj \ +%endif +%endfor %endif %if target.build != 'private': From 882ef3ff9ee0f5f5a82e26cfe2cfd2ba1536a339 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Mon, 20 Jul 2015 14:14:41 -0700 Subject: [PATCH 11/12] mark not building windows tests as platforms = posix in build.json --- build.json | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/build.json b/build.json index af8bd54460e..84c292cd7f3 100644 --- a/build.json +++ b/build.json @@ -1890,6 +1890,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -1907,6 +1910,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -1965,6 +1971,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -2188,6 +2197,9 @@ "gpr_test_util", "gpr", "grpc++_test_config" + ], + "platforms": [ + "posix" ] }, { @@ -2206,6 +2218,9 @@ "gpr_test_util", "gpr", "grpc++_test_config" + ], + "platforms": [ + "posix" ] }, { @@ -2220,6 +2235,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -2324,6 +2342,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -2342,6 +2363,9 @@ "gpr_test_util", "gpr", "grpc++_test_config" + ], + "platforms": [ + "posix" ] }, { @@ -2360,6 +2384,9 @@ "gpr_test_util", "gpr", "grpc++_test_config" + ], + "platforms": [ + "posix" ] }, { @@ -2411,6 +2438,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -2460,6 +2490,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { @@ -2477,6 +2510,9 @@ "grpc", "gpr_test_util", "gpr" + ], + "platforms": [ + "posix" ] }, { From 639ae0ff5f1deacf185ed38e8be86e4ca5fb7e43 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Tue, 21 Jul 2015 12:05:42 -0700 Subject: [PATCH 12/12] documentation for windows testing using grpc.mak --- vsprojects/README.md | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/vsprojects/README.md b/vsprojects/README.md index 06e87b3aed2..e6cbf833590 100644 --- a/vsprojects/README.md +++ b/vsprojects/README.md @@ -36,32 +36,45 @@ After that, you can build the solution using one of these options: * install [NuGet](http://www.nuget.org) * nuget should automatically bring in built versions of zlib and openssl when building grpc.sln (the versions in `/third_party/` are not used). If it doesn't work use `tools->nuget...->manage...`. The packages are put in `/vsprojects/packages/` -#C/C++ Test Build Steps +#C/C++ Test Solution/Project Build Steps + * A basic git version of grpc only has templates for non-test items. This checklist adds test items to grpc.sln and makes individual vs projects for them * set up dependencies (above) * add `"debug": true,` to the top of build.json. This is the base file for all build tracking, see [templates](https://github.com/grpc/grpc/tree/master/templates) for more information * `"debug": true,` gets picked up by `/tools/buildgen/plugins/generate_vsprojects.py`. It tells the script to add visual studio GUIDs to all projects. Otherwise only the projects that already have GUIDs in build.json will be built - * A basic git version of grpc only has templates for non-test items. run `/templates/vsprojects/generate_debug_projects.sh` to make debug templates/projects. This runs a regular visual studio buildgen process, which creates the `.sln` file with all of the new debug projects, then uses git diff to find the new project names from the `.sln` that need templates added. It builds the new templates based on the diff, then re-runs the visual studio buildgen, which builds the vs projects for each of the new debug targets + * run `/templates/vsprojects/generate_debug_projects.sh` to make debug templates/projects. This runs a regular visual studio buildgen process, which creates the `.sln` file with all of the new debug projects, then uses git diff to find the new project names from the `.sln` that need templates added. It builds the new templates based on the diff, then re-runs the visual studio buildgen, which builds the vs projects for each of the new debug targets * copy over the `/vsprojects/` folder to your windows build setup (assuming this was built on linux in order to have easy access to python/mako and shell scripts) * run `/templates/vsprojects/build_test_protos.sh` * this builds all `.proto` files in `/test/` in-place. there might be a better place to put them that mirrors what happens in the linux build process (todo) * each `.proto` file gets built into a `.grpc.pb.cc`, .`grpc.pb.h`, `.pb.cc`, and `.pb.h`. These are included in each test project in lieu of the `.proto` includes specified in `build.json`. This substitution is done by `/templates/vsprojects/vcxproj_defs.include` * copy over the `/test/` folder in order to get the new files (assuming this was built on linux in order to have an easy protobuf+grpc plugin installation) -#Testing +#Making and running tests with `/tools/run_tests/run_tests.py` or `/vsprojects/make.bat` +`run_tests.py` and `make.bat` both rely on `/vsprojects/grpc.mak`, an NMAKE script that includes C/C++ tests in addition to the base grpc projects. It builds the base projects by calling grpc.sln, but most things are built with a command line similar to a makefile workflow. -This is incomplete (only runs some tests for now), todo. The above .sln-based buildgen makes more tets but isn't tied in to automatic test running yet. + arguments for `/vsprojects/make.bat`: -Use `run_tests.py`, that also supports Windows (with a bit limited experience). -``` -> REM Run from repository root. -> python tools\run_tests\run_tests.py -l c -``` + * no options or `all` or `buildtests`: builds all tests + * `buildtests_c`: just c tests + * `buildtests_cxx`: just c++ tests + * names of individual tests: just those tests (example: `make.bat gpr_string_test`) -Also, you can `make.bat` directly to build and run gRPC tests. -``` -> REM Run from this directory. -> make.bat alarm_test -``` +using `run_tests.py` on windows: + + * when `run_tests.py` detects that it's running on windows it calls `make.bat` to build the tests and expects to find tests in `/vsprojects/test_bins/` + +`run_tests.py` options: + + * `run_tests.py --help` + * `run_tests.py -l c`: run c language tests + * `run_tests.py -l c++`: run c++ language tests + * note: `run_tests.py` doesn't normally show build steps, so if a build fails it is best to fall back to `make.bat` + * if `make.bat` fails, it might be easier to open up the `.sln` file in the visual studio gui (see above for how to build the test projects) and build the offending test from its project file. The `.mak` and project file templates are slightly different, so it's possible that a project will build one way and not another. Please report this if it happens. + +It can be helpful to disable the firewall when running tests so that 400 connection warnings don't pop up. + +Individual tests can be run by directly running the executable in `/vsprojects/run_tests/` (this is `/bins/opt/` on linux). Many C tests have no output; they either pass or fail internally and communicate this with their exit code (`0=pass`, `nonzero=fail`) + +`run_tests.py` will fail if it can't build something, so not-building tests are disabled with a "platforms = posix" note in build.json. The buildgen tools will not add a test to a windows build unless it is marked "windows" or has no platforms identified. As tests are ported they will get this mark removed. # Building protoc plugins For generating service stub code, gRPC relies on plugins for `protoc` (the protocol buffer compiler). The solution `grpc_protoc_plugins.sln` allows you to build