Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 6148cb5

Browse files
committed
Merge branch 'master' of https://github.com/cmu-db/peloton
2 parents 229fb4a + 83b95e2 commit 6148cb5

File tree

7 files changed

+106
-53
lines changed

7 files changed

+106
-53
lines changed

cmake/ConfigGen.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function(peloton_generate_export_configs)
5555
configure_file("cmake/Templates/PelotonConfig.cmake.in" "${PROJECT_BINARY_DIR}/PelotonConfig.cmake" @ONLY)
5656

5757
# Add targets to the build-tree export set
58-
export(TARGETS peloton peloton-proto FILE "${PROJECT_BINARY_DIR}/PelotonTargets.cmake")
58+
export(TARGETS peloton peloton-proto pg_query FILE "${PROJECT_BINARY_DIR}/PelotonTargets.cmake")
5959
if (TARGET peloton-capnp)
6060
export(TARGETS peloton-capnp APPEND FILE "${PROJECT_BINARY_DIR}/PelotonTargets.cmake")
6161
endif()

cmake/Modules/CoverallsGenerateGcov.cmake

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,27 @@ foreach (GCOV_FILE ${ALL_GCOV_FILES})
252252
# ->
253253
# /path/to/project/root/subdir/the_file.c
254254
get_source_path_from_gcov_filename(GCOV_SRC_PATH ${GCOV_FILE})
255-
file(RELATIVE_PATH GCOV_SRC_REL_PATH "${PROJECT_ROOT}" "${GCOV_SRC_PATH}")
256255

257-
# Is this in the list of source files?
258-
# TODO: We want to match against relative path filenames from the source file root...
259-
list(FIND COVERAGE_SRCS ${GCOV_SRC_PATH} WAS_FOUND)
256+
# skip if full path is not present
257+
# can happen if files are generated for external libraries
258+
if(IS_ABSOLUTE ${GCOV_SRC_PATH})
259+
file(RELATIVE_PATH GCOV_SRC_REL_PATH "${PROJECT_ROOT}" "${GCOV_SRC_PATH}")
260+
261+
# Is this in the list of source files?
262+
# TODO: We want to match against relative path filenames from the source file root...
263+
list(FIND COVERAGE_SRCS ${GCOV_SRC_PATH} WAS_FOUND)
260264

261-
if (NOT WAS_FOUND EQUAL -1)
262-
message("YES: ${GCOV_FILE}")
263-
list(APPEND GCOV_FILES ${GCOV_FILE})
265+
if (NOT WAS_FOUND EQUAL -1)
266+
message("YES: ${GCOV_FILE}")
267+
list(APPEND GCOV_FILES ${GCOV_FILE})
264268

265-
# We remove it from the list, so we don't bother searching for it again.
266-
# Also files left in COVERAGE_SRCS_REMAINING after this loop ends should
267-
# have coverage data generated from them (no lines are covered).
268-
list(REMOVE_ITEM COVERAGE_SRCS_REMAINING ${GCOV_SRC_PATH})
269-
else()
270-
message("NO: ${GCOV_FILE}")
269+
# We remove it from the list, so we don't bother searching for it again.
270+
# Also files left in COVERAGE_SRCS_REMAINING after this loop ends should
271+
# have coverage data generated from them (no lines are covered).
272+
list(REMOVE_ITEM COVERAGE_SRCS_REMAINING ${GCOV_SRC_PATH})
273+
else()
274+
message("NO: ${GCOV_FILE}")
275+
endif()
271276
endif()
272277
endforeach()
273278

script/formatting/formatter.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import sys
1313
import datetime
1414
import subprocess
15+
import distutils.spawn
16+
1517

1618
## ==============================================
1719
## CONFIGURATION
@@ -32,7 +34,7 @@
3234
DEFAULT_DIRS.append(PELOTON_SRC_DIR)
3335
DEFAULT_DIRS.append(PELOTON_TESTS_DIR)
3436

35-
CLANG_FORMAT = "clang-format-3.6"
37+
CLANG_FORMAT = None
3638
CLANG_FORMAT_FILE = os.path.join(PELOTON_DIR, ".clang-format")
3739

3840
## ==============================================
@@ -112,13 +114,13 @@ def format_file(file_path, update_header, clang_format_code):
112114
fd.write(file_data)
113115

114116
elif clang_format_code:
115-
try:
116-
formatting_command = CLANG_FORMAT + " -style=file -i " + file_path
117-
LOG.info(formatting_command)
118-
subprocess.call([CLANG_FORMAT, "-style=file", "-i", file_path])
119-
except OSError as e:
117+
if CLANG_FORMAT is None:
120118
LOG.error("clang-format seems not installed")
121119
exit("clang-format seems not installed")
120+
121+
formatting_command = CLANG_FORMAT + " -style=file -i " + file_path
122+
LOG.info(formatting_command)
123+
subprocess.call([CLANG_FORMAT, "-style=file", "-i", file_path])
122124

123125
#END WITH
124126

@@ -140,6 +142,17 @@ def format_dir(dir_path, update_header, clang_format_code):
140142
#END FOR [os.walk]
141143
#END ADD_HEADERS_DIR(DIR_PATH)
142144

145+
#find clang-format executable
146+
def find_clangformat():
147+
global CLANG_FORMAT
148+
#check for possible clang-format versions
149+
for exe in ["clang-format", "clang-format-3.6", "clang-format-3.7", "clang-format-3.8"]:
150+
path = distutils.spawn.find_executable(exe)
151+
if not path is None:
152+
CLANG_FORMAT = path
153+
return
154+
155+
143156
## ==============================================
144157
## Main Function
145158
## ==============================================
@@ -155,6 +168,8 @@ def format_dir(dir_path, update_header, clang_format_code):
155168
help='Files or directories to (recursively) apply the actions to')
156169

157170
args = parser.parse_args()
171+
172+
find_clangformat()
158173

159174
if args.staged_files:
160175
targets = [os.path.abspath(os.path.join(PELOTON_DIR, f)) for f in subprocess.check_output(["git", "diff", "--name-only", "HEAD", "--cached", "--diff-filter=d"]).split()]

script/validators/source_validator.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import mmap
1717
import glob
1818
import functools
19+
import distutils.spawn
1920

2021
## ==============================================
2122
## LOGGING CONFIGURATION
@@ -44,7 +45,7 @@
4445
functools.reduce(os.path.join, [CODE_SOURCE_DIR, os.path.pardir, os.path.pardir])
4546
)
4647

47-
CLANG_FORMAT = "clang-format-3.6"
48+
CLANG_FORMAT = None
4849
CLANG_FORMAT_FILE = os.path.join(PELOTON_DIR, ".clang-format")
4950

5051
# Other directory paths used are relative to PELOTON_DIR
@@ -132,31 +133,32 @@ def check_format(file_path):
132133
status = True
133134

134135
# Run clang-format on the file
135-
try:
136-
clang_format_cmd = [CLANG_FORMAT, "-style=file", file_path]
137-
formatted_src = subprocess.check_output(clang_format_cmd).splitlines(True)
138-
# Load source file
139-
with open(file_path, "r") as file:
140-
src = file.readlines()
141-
142-
# Do the diff
143-
d = difflib.Differ()
144-
diff = d.compare(src, formatted_src)
145-
line_num = 0
146-
for line in diff:
147-
code = line[:2]
148-
if code in (" ", "- "):
149-
line_num += 1
150-
if code == '- ':
151-
if status:
152-
LOG.info("Invalid formatting in file : " + file_path)
153-
LOG.info(" Line %d: %s" % (line_num, line[2:].strip()))
154-
status = False
155-
156-
return status
157-
except OSError as e:
136+
if CLANG_FORMAT is None:
158137
LOG.error("clang-format seems not installed")
159138
exit()
139+
140+
clang_format_cmd = [CLANG_FORMAT, "-style=file", file_path]
141+
formatted_src = subprocess.check_output(clang_format_cmd).splitlines(True)
142+
# Load source file
143+
with open(file_path, "r") as file:
144+
src = file.readlines()
145+
146+
# Do the diff
147+
d = difflib.Differ()
148+
diff = d.compare(src, formatted_src)
149+
line_num = 0
150+
for line in diff:
151+
code = line[:2]
152+
if code in (" ", "- "):
153+
line_num += 1
154+
if code == '- ':
155+
if status:
156+
LOG.info("Invalid formatting in file : " + file_path)
157+
LOG.info(" Line %d: %s" % (line_num, line[2:].strip()))
158+
status = False
159+
160+
return status
161+
160162

161163
def check_namespaces(file_path):
162164
# only check for src files
@@ -285,6 +287,16 @@ def validate_dir(dir_path):
285287
#END FOR [os.walk]
286288
#END VALIDATE_DIR(DIR_PATH)
287289

290+
#find clang-format executable
291+
def find_clangformat():
292+
global CLANG_FORMAT
293+
#check for possible clang-format versions
294+
for exe in ["clang-format", "clang-format-3.6", "clang-format-3.7", "clang-format-3.8"]:
295+
path = distutils.spawn.find_executable(exe)
296+
if not path is None:
297+
CLANG_FORMAT = path
298+
return
299+
288300
## ==============================================
289301
## Main Function
290302
## ==============================================
@@ -297,6 +309,8 @@ def validate_dir(dir_path):
297309

298310
LOG.info("Running source validator ...")
299311
LOG.info("Peloton root : " + PELOTON_DIR)
312+
313+
find_clangformat()
300314

301315
if args.files:
302316
# Validate just the provided files.

src/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ peloton_default_properties(peloton-proto)
3232

3333
# --[ Libpg_query library
3434

35-
add_custom_target(libpg_query ALL
36-
COMMAND ${CMAKE_MAKE_PROGRAM}
37-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/third_party/libpg_query/
38-
COMMENT "Original libpg makefile target")
35+
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/libpg_query/ libpg_query.a)
3936

4037

4138
##################################################################################
@@ -46,9 +43,8 @@ add_custom_target(libpg_query ALL
4643
peloton_pickup_peloton_sources(${PROJECT_SOURCE_DIR})
4744

4845
add_library(peloton SHARED ${srcs})
49-
add_dependencies(peloton libpg_query)
50-
target_link_libraries(peloton ${Peloton_LINKER_LIBS}
51-
${PROJECT_SOURCE_DIR}/third_party/libpg_query/libpg_query.a)
46+
47+
target_link_libraries(peloton PUBLIC ${Peloton_LINKER_LIBS} peloton-proto pg_query)
5248

5349
peloton_default_properties(peloton)
5450
set_target_properties(peloton PROPERTIES

test/common/statement_cache_manager_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ TEST_F(StatementCacheTests, InvalidateManyTest) {
6262
std::set<oid_t> ref_table = {0, 1};
6363

6464
for (auto oid : ref_table) {
65-
std::string string_name = "foo" + oid;
65+
std::string string_name = std::to_string(oid);
6666
std::string query = "SELECT * FROM TEST";
6767
auto statement = std::make_shared<Statement>(string_name, query);
6868
std::set<oid_t> cur_ref_table;
@@ -78,7 +78,7 @@ TEST_F(StatementCacheTests, InvalidateManyTest) {
7878

7979
// Both plans need to replan now
8080
for (auto oid : ref_table) {
81-
std::string string_name = "foo" + oid;
81+
std::string string_name = std::to_string(oid);
8282
auto statement = statement_cache.GetStatement(string_name);
8383

8484
EXPECT_TRUE(statement->GetNeedsReplan());
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 2.8.7)
2+
3+
# ---[ Peloton project
4+
project(pg_query CXX C)
5+
6+
# this code imitates the Makefile in /third_party/libpg_query/
7+
file(GLOB_RECURSE pg_query_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
8+
list(REMOVE_ITEM pg_query_srcs
9+
"${CMAKE_CURRENT_SOURCE_DIR}/src/pg_query_fingerprint_defs.c"
10+
"${CMAKE_CURRENT_SOURCE_DIR}/src/pg_query_fingerprint_conds.c"
11+
"${CMAKE_CURRENT_SOURCE_DIR}/src/pg_query_json_defs.c"
12+
"${CMAKE_CURRENT_SOURCE_DIR}/src/pg_query_json_conds.c"
13+
"${CMAKE_CURRENT_SOURCE_DIR}/src/postgres/guc-file.c"
14+
"${CMAKE_CURRENT_SOURCE_DIR}/src/postgres/scan.c"
15+
"${CMAKE_CURRENT_SOURCE_DIR}/src/pg_query_json_helper.c")
16+
17+
include_directories(.)
18+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/postgres/include)
19+
20+
add_library(pg_query STATIC ${pg_query_srcs})
21+
22+
set_target_properties(pg_query PROPERTIES LINKER_LANGUAGE C)
23+
set_target_properties(pg_query PROPERTIES POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)