Skip to content

Commit

Permalink
server: Remove angle-bracket envoy includes, and make check_format pr…
Browse files Browse the repository at this point in the history
…event them from reappearing (envoyproxy#2921)

Signed-off-by: Joshua Marantz <[email protected]>
  • Loading branch information
jmarantz authored and mattklein123 committed Apr 3, 2018
1 parent a27f9d5 commit c69f959
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion source/server/http/config_tracker_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <envoy/server/config_tracker.h>
#include "envoy/server/config_tracker.h"

#include "common/common/assert.h"
#include "common/common/macros.h"
Expand Down
34 changes: 27 additions & 7 deletions tools/check_format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import argparse
import common
import fileinput
import os
import os.path
Expand All @@ -22,6 +23,9 @@
os.path.dirname(os.path.abspath(sys.argv[0])), "envoy_build_fixer.py")
HEADER_ORDER_PATH = os.path.join(
os.path.dirname(os.path.abspath(sys.argv[0])), "header_order.py")
SUBDIR_SET = set(common.includeDirOrder())
INCLUDE_ANGLE = "#include <"
INCLUDE_ANGLE_LEN = len(INCLUDE_ANGLE)

PROTOBUF_TYPE_ERRORS = {
# Well-known types should be referenced from the ProtobufWkt namespace.
Expand Down Expand Up @@ -69,7 +73,7 @@ def findSubstringAndPrintError(pattern, file_path, error_message):
with open(file_path) as f:
text = f.read()
if pattern in text:
printError(error_message)
printError(file_path + ': ' + error_message)
for i, line in enumerate(text.splitlines()):
if pattern in line:
printError(" %s:%s" % (file_path, i + 1))
Expand All @@ -79,8 +83,8 @@ def findSubstringAndPrintError(pattern, file_path, error_message):
def checkProtobufExternalDepsBuild(file_path):
if whitelistedForProtobufDeps(file_path):
return True
message = ("%s has unexpected direct external dependency on protobuf, use "
"//source/common/protobuf instead." % file_path)
message = ("unexpected direct external dependency on protobuf, use "
"//source/common/protobuf instead.")
return findSubstringAndPrintError('"protobuf"', file_path, message)


Expand All @@ -103,25 +107,41 @@ def isBuildFile(file_path):
return True
return False

def hasInvalidAngleBracketDirectory(line):
if not line.startswith(INCLUDE_ANGLE):
return False
path = line[INCLUDE_ANGLE_LEN:]
slash = path.find("/")
if slash == -1:
return False
subdir = path[0:slash]
return subdir in SUBDIR_SET

def checkFileContents(file_path):
message = "%s has over-enthusiastic spaces:" % file_path
findSubstringAndPrintError('. ', file_path, message)
def printLineError(path, zero_based_line_number, message):
printError("%s:%d: %s" % (path, zero_based_line_number + 1, message))

def checkFileContents(file_path):
for line_number, line in enumerate(fileinput.input(file_path)):
if line.find(". ") != -1:
printLineError(file_path, line_number, "over-enthusiastic spaces")
if hasInvalidAngleBracketDirectory(line):
printLineError(file_path, line_number, "envoy includes should not have angle brackets")

def fixFileContents(file_path):
for line in fileinput.input(file_path, inplace=True):
# Strip double space after '.' This may prove overenthusiastic and need to
# be restricted to comments and metadata files but works for now.
line = line.replace('. ', '. ')

if hasInvalidAngleBracketDirectory(line):
line = line.replace('<', '"').replace(">", '"')

# Fix incorrect protobuf namespace references.
for error, replacement in PROTOBUF_TYPE_ERRORS.items():
line = line.replace(error, replacement)

sys.stdout.write(str(line))


def checkFilePath(file_path):
if isBuildFile(file_path):
command = "%s %s | diff %s -" % (ENVOY_BUILD_FIXER_PATH, file_path, file_path)
Expand Down
10 changes: 10 additions & 0 deletions tools/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def includeDirOrder():
return (
"envoy",
"common",
"source",
"exe",
"server",
"extensions",
"test",
)
10 changes: 3 additions & 7 deletions tools/header_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# enough to handle block splitting and correctly detecting the main header subject to the Envoy
# canonical paths.

import common
import re
import sys

Expand Down Expand Up @@ -66,14 +67,9 @@ def regex_filter(regex):
file_header_filter(),
regex_filter('<.*\.h>'),
regex_filter('<.*>'),
regex_filter('"envoy/.*"'),
regex_filter('"common/.*"'),
regex_filter('"source/common/.*"'),
regex_filter('"exe/.*"'),
regex_filter('"server/.*"'),
regex_filter('"extensions/.*"'),
regex_filter('"test/.*"'),
]
for subdir in common.includeDirOrder():
block_filters.append(regex_filter('"' + subdir + '/.*"'))

blocks = []
already_included = set([])
Expand Down

0 comments on commit c69f959

Please sign in to comment.