Merge "perfetto: disable integration tests on travis"
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index c10e285..222d364 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -20,7 +20,6 @@
     # lines in them.
     long_line_sources = lambda x: input.FilterSourceFile(
             x, white_list=".*", black_list=['Android[.]bp'])
-
     results = []
     results += input.canned_checks.CheckDoNotSubmit(input, output)
     results += input.canned_checks.CheckChangeHasNoTabs(input, output)
@@ -28,6 +27,7 @@
             input, output, 80, source_file_filter=long_line_sources)
     results += input.canned_checks.CheckPatchFormatted(input, output)
     results += input.canned_checks.CheckGNFormatted(input, output)
+    results += CheckIncludeGuards(input, output)
     results += CheckAndroidBlueprint(input, output)
     results += CheckMergedTraceConfigProto(input, output)
     return results
@@ -51,6 +51,7 @@
 
     with open('Android.bp') as f:
         current_blueprint = f.read()
+
     new_blueprint = subprocess.check_output(
         ['tools/gen_android_bp', '--output', '/dev/stdout'])
 
@@ -63,6 +64,21 @@
     return []
 
 
+def CheckIncludeGuards(input_api, output_api):
+    tool = 'tools/fix_include_guards'
+    file_filter = lambda x: input_api.FilterSourceFile(
+          x,
+          white_list=('.*[.]cc$', '.*[.]h$', tool))
+    if not input_api.AffectedSourceFiles(file_filter):
+        return []
+    if subprocess.call([tool, '--check-only']):
+        return [
+            output_api.PresubmitError(
+                'Please run ' + tool + ' to fix include guards.')
+        ]
+    return []
+
+
 def CheckMergedTraceConfigProto(input_api, output_api):
     tool = 'tools/gen_merged_trace_config'
     build_file_filter = lambda x: input_api.FilterSourceFile(
diff --git a/include/perfetto/base/watchdog.h b/include/perfetto/base/watchdog.h
index 969059b..1a6fd39 100644
--- a/include/perfetto/base/watchdog.h
+++ b/include/perfetto/base/watchdog.h
@@ -40,4 +40,4 @@
 
 }  // namespace base
 }  // namespace perfetto
-#endif
+#endif  // INCLUDE_PERFETTO_BASE_WATCHDOG_H_
diff --git a/include/perfetto/ftrace_reader/ftrace_config.h b/include/perfetto/ftrace_reader/ftrace_config.h
index 7f6b264..a0b78f6 100644
--- a/include/perfetto/ftrace_reader/ftrace_config.h
+++ b/include/perfetto/ftrace_reader/ftrace_config.h
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#ifndef INCLUDE_PERFETTO_FTRACE_READER_FTRACE_CONFIG_H_
+#define INCLUDE_PERFETTO_FTRACE_READER_FTRACE_CONFIG_H_
+
 #include <set>
 #include <string>
 
@@ -39,3 +42,5 @@
 bool ValidConfig(const FtraceConfig& config);
 
 }  // namespace perfetto
+
+#endif  // INCLUDE_PERFETTO_FTRACE_READER_FTRACE_CONFIG_H_
diff --git a/src/tracing/core/data_source_config.cc b/src/tracing/core/data_source_config.cc
index a95d60e..61aec24 100644
--- a/src/tracing/core/data_source_config.cc
+++ b/src/tracing/core/data_source_config.cc
@@ -25,7 +25,7 @@
  * ./tools/gen_tracing_cpp_headers_from_protos.py
  */
 
-#include "include/perfetto/tracing/core/data_source_config.h"
+#include "perfetto/tracing/core/data_source_config.h"
 
 #include "perfetto/config/data_source_config.pb.h"
 
diff --git a/src/tracing/core/data_source_descriptor.cc b/src/tracing/core/data_source_descriptor.cc
index 1f61618..80f5741 100644
--- a/src/tracing/core/data_source_descriptor.cc
+++ b/src/tracing/core/data_source_descriptor.cc
@@ -25,7 +25,7 @@
  * ./tools/gen_tracing_cpp_headers_from_protos.py
  */
 
-#include "include/perfetto/tracing/core/data_source_descriptor.h"
+#include "perfetto/tracing/core/data_source_descriptor.h"
 
 #include "perfetto/config/data_source_descriptor.pb.h"
 
diff --git a/src/tracing/core/trace_config.cc b/src/tracing/core/trace_config.cc
index aa9b8fb..8b9a28e 100644
--- a/src/tracing/core/trace_config.cc
+++ b/src/tracing/core/trace_config.cc
@@ -25,7 +25,7 @@
  * ./tools/gen_tracing_cpp_headers_from_protos.py
  */
 
-#include "include/perfetto/tracing/core/trace_config.h"
+#include "perfetto/tracing/core/trace_config.h"
 
 #include "perfetto/config/data_source_config.pb.h"
 #include "perfetto/config/trace_config.pb.h"
diff --git a/tools/fix_include_guards.py b/tools/fix_include_guards
similarity index 76%
rename from tools/fix_include_guards.py
rename to tools/fix_include_guards
index 80b59a6..ff062d0 100755
--- a/tools/fix_include_guards.py
+++ b/tools/fix_include_guards
@@ -17,8 +17,8 @@
 import re
 import sys
 
-def fix_guards(fpath):
-  with open(fpath) as f:
+def fix_guards(fpath, checkonly):
+  with open(fpath, 'rb') as f:
     lines = [l.strip('\n') for l in f.readlines()]
   res = []
   guard = re.sub(r'[^a-zA-Z0-9_-]', '_', fpath.upper()) + '_'
@@ -29,7 +29,7 @@
     if lines[line_idx].startswith('#endif'):
       endif_line_idx = line_idx
       break
-  assert(endif_line_idx > 0)
+  assert endif_line_idx > 0, fpath
 
   line_idx = 0
   for line in lines:
@@ -41,29 +41,32 @@
       replacements = 2
     elif line_idx == endif_line_idx and replacements == 2:
       assert(line.startswith('#endif'))
-      line = '#endif  // ' + guard + '\n'
+      line = '#endif  // ' + guard
     res.append(line)
     line_idx += 1
   if res == lines:
     return 0
+  if checkonly:
+    print >>sys.stderr, 'Wrong #include guards in %s' % fpath
+    return 1
   with open(fpath, 'w') as f:
-    f.write('\n'.join(res))
+    f.write('\n'.join(res) + '\n')
   return 1
 
 def main():
-  if len(sys.argv) < 2:
-    print('Usage: %s src include' % sys.argv[0])
-    return 1
-
+  checkonly = '--check-only' in sys.argv
   num_files_changed = 0
-  for topdir in sys.argv[1:]:
+  for topdir in ('src', 'include'):
     for root, dirs, files in os.walk(topdir):
       for name in files:
         if not name.endswith('.h'):
           continue
         fpath = os.path.join(root, name)
-        num_files_changed += fix_guards(fpath)
-  print '%d files changed' % num_files_changed
+        num_files_changed += fix_guards(fpath, checkonly)
+  if checkonly:
+    return 0 if num_files_changed == 0 else 1
+  else:
+    print '%d files changed' % num_files_changed
 
 if __name__ == '__main__':
   sys.exit(main())
diff --git a/tools/proto_to_cpp/proto_to_cpp.cc b/tools/proto_to_cpp/proto_to_cpp.cc
index bdabd53..86d505b 100644
--- a/tools/proto_to_cpp/proto_to_cpp.cc
+++ b/tools/proto_to_cpp/proto_to_cpp.cc
@@ -230,7 +230,9 @@
   header_printer.Print("#include <type_traits>\n\n");
 
   cpp_printer.Print(kHeader, "f", __FILE__, "p", src_proto);
-  cpp_printer.Print("#include \"$f$\"\n", "f", dst_header);
+  PERFETTO_CHECK(dst_header.find("include/") == 0);
+  cpp_printer.Print("#include \"$f$\"\n", "f",
+                    dst_header.substr(strlen("include/")));
 
   // Generate includes for translated types of dependencies.
   for (int i = 0; i < proto_file->dependency_count(); i++) {