Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Add bazel build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Jun 27, 2017
1 parent 71bf740 commit 777ee72
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 24 deletions.
78 changes: 78 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
licenses(["notice"])

exports_files(["LICENSE.md"])

cc_library(
name = "served",
copts = [
"-Iexternal/com_googlesource_code_re2",
],
srcs = glob(
[
"src/served/*.cpp",
"src/served/mux/*.cpp",
"src/served/net/*.cpp",
],
exclude = [
"src/served/*.test.cpp",
"src/served/mux/*.test.cpp",
"src/served/net/*.test.cpp",
],
),
hdrs = glob(
[
"src/served/*.hpp",
"src/served/mux/*.hpp",
"src/served/net/*.hpp",
],
exclude = [
"src/served/version.hpp"
],
) + [":servedversion"],
strip_include_prefix = "src/",
visibility = ["//visibility:public"],
deps = [
"@boost//:system",
"@boost//:asio",
"@com_googlesource_code_re2//:re2",
],
)

cc_test(
name = "served-test",
copts = [
"-Iexternal/com_googlesource_code_re2",
"-Isrc",
],
srcs = glob(
[
"src/served/*.test.cpp",
"src/served/mux/*.test.cpp",
"src/served/net/*.test.cpp",
"src/test/catch.cpp",
"src/test/catch.hpp",
],
),
tags = [ "large" ],
timeout = "short",
deps = [ "//:served" ],
)

genrule(
name = "servedversion",
srcs = [],
outs = ["src/served/version.hpp"],
cmd = """
echo '#ifndef SERVED_VERSION_HPP_INCLUDED' > $@
echo '#define SERVED_VERSION_HPP_INCLUDED' >> $@
echo '#define APPLICATION_NAME \"Served HTTP REST Library\"' >> $@
echo '#define APPLICATION_CODENAME \"served\"' >> $@
echo '#define APPLICATION_COPYRIGHT_YEARS \"2014\"' >> $@
echo '#define APPLICATION_VERSION_STRING \"1.4.3-DS1\"' >> $@
echo '#define APPLICATION_VENDOR_ID \"com.datasift\"' >> $@
echo '#define APPLICATION_VENDOR_NAME \"DataSift\"' >> $@
echo '#define APPLICATION_VENDOR_URL \"datasift.com\"' >> $@
echo '#define APPLICATION_ID = \"com.datasift.served\"' >> $@
echo '#endif' >> $@
""",
)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ $ mkdir served.build && cd served.build
$ cmake ../served && make
```

Or, using [bazel](https://bazel.build/):

```bash
$ git clone git@github.com:datasift/served.git
$ cd served
$ bazel build :served
$ bazel test :served-test
```

### Getting Started

The most basic example of creating a server and handling a `HTTP GET` for the path `/hello`:
Expand Down
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
workspace(name = "com_github_datasift_served")

git_repository(
name = "com_github_nelhage_boost",
remote = "https://github.com/nelhage/rules_boost.git",
commit = "ead0110ff90d5d90d2eb67e7e78f34f42d8486a1",
)

load("@com_github_nelhage_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

git_repository(
name = "com_googlesource_code_re2",
remote = "https://github.com/google/re2.git",
commit = "22fc950c75d238f8b2dcbc43d8a60573cad2b8d7",
)
1 change: 1 addition & 0 deletions src/served/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ ENDIF (SERVED_BUILD_SHARED)
# Configure common test settings
#
SET (test_LIBS ${Boost_LIBRARIES} ${PROJECT_NAME})
SET (test_HDRS "../test/catch.cpp")

#
# Test build rules
Expand Down
17 changes: 8 additions & 9 deletions src/served/methods_handler.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/methods_handler.hpp>

bool search(std::vector<std::string> & vec, std::string s)
bool search_method(std::vector<std::string> & vec, std::string s)
{
for ( auto & v : vec )
{
Expand Down Expand Up @@ -74,10 +73,10 @@ TEST_CASE("test methods handling", "[methods_handler]")
CHECK(std::get<1>(methods).size() == 4);
CHECK(std::get<0>(methods).empty());

CHECK(search(std::get<1>(methods), "POST"));
CHECK(search(std::get<1>(methods), "GET"));
CHECK(search(std::get<1>(methods), "CONNECT"));
CHECK(search(std::get<1>(methods), "PUT"));
CHECK(search_method(std::get<1>(methods), "POST"));
CHECK(search_method(std::get<1>(methods), "GET"));
CHECK(search_method(std::get<1>(methods), "CONNECT"));
CHECK(search_method(std::get<1>(methods), "PUT"));
}

SECTION("check endpoint propagation with description")
Expand All @@ -98,8 +97,8 @@ TEST_CASE("test methods handling", "[methods_handler]")
CHECK(3 == std::get<1>(methods).size());
CHECK("This is an endpoint for great stuff" == std::get<0>(methods));

CHECK(search(std::get<1>(methods), "GET"));
CHECK(search(std::get<1>(methods), "PUT"));
CHECK(search(std::get<1>(methods), "DELETE"));
CHECK(search_method(std::get<1>(methods), "GET"));
CHECK(search_method(std::get<1>(methods), "PUT"));
CHECK(search_method(std::get<1>(methods), "DELETE"));
}
}
3 changes: 1 addition & 2 deletions src/served/multiplexer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <vector>
Expand Down Expand Up @@ -181,7 +180,7 @@ TEST_CASE("multiplexer path routing", "[mux]")

INFO( "comparing size of received for pattern: " << story.pattern );
CHECK( story.expected_200s.size() == story.received.size() );
for ( int i = 0; i < story.expected_200s.size(); i++ )
for ( unsigned int i = 0; i < story.expected_200s.size(); i++ )
{
CHECK( story.expected_200s[i] == story.received[i] );
}
Expand Down
1 change: 0 additions & 1 deletion src/served/mux/matchers.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/mux/matchers.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/served/net/connection.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>
1 change: 0 additions & 1 deletion src/served/net/connection_manager.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>
1 change: 0 additions & 1 deletion src/served/net/server.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>
4 changes: 2 additions & 2 deletions src/served/parameters.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include "served/parameters.hpp"
#include <map>
#include <served/parameters.hpp>

TEST_CASE("Test param const, ref and copy handling", "[parameters]")
{
Expand Down
1 change: 0 additions & 1 deletion src/served/request.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/request.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/served/request_error.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/status.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/served/request_parser.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/request_parser.hpp>
Expand Down
3 changes: 2 additions & 1 deletion src/served/request_parser_impl.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <cstring>

#include <served/methods.hpp>
#include <served/request_parser_impl.hpp>

Expand Down
1 change: 0 additions & 1 deletion src/served/response.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/response.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/served/status.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/status.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/served/uri.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* SOFTWARE.
*/

#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

#include <served/uri.hpp>
Expand Down
2 changes: 2 additions & 0 deletions src/test/catch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include <test/catch.hpp>

0 comments on commit 777ee72

Please sign in to comment.