Split targets mixing .c and .cc sources.

The Bazel build format doesn't support having separate
lists of compilation flags for C and C++; it just has a single
copts list for cc_library:
https://bazel.build/versions/master/docs/be/c-cpp.html#cc_binary.copts

This makes it hard to convert our GN targets to Bazel when there are
compiler warnings that aren't supported for C (like -Woverloaded-virtual
being added in bugs.webrtc.org/6653).

The solution for this is to move all .c files to their own targets
and remove C++-only compiler flags during conversion.

New targets:
//webrtc/common_audio:common_audio_c
//webrtc/common_audio:common_audio_neon_c
//webrtc/modules/audio_coding:g711_c
//webrtc/modules/audio_coding:g722_c
//webrtc/modules/audio_coding:ilbc_c
//webrtc/modules/audio_coding:isac_c
//webrtc/modules/audio_coding:isac_fix_c
//webrtc/modules/audio_coding:isac_test_util
//webrtc/modules/audio_coding:pcm16b_c
//webrtc/modules/audio_coding:webrtc_opusj_c
//webrtc/modules/audio_device:mac_portaudio
//webrtc/modules/audio_procssing:audio_processing_c
//webrtc/modules/audio_procssing:audio_processing_neon_c

This CL also adds a PRESUBMIT.py check that will throw an error
if targets are mixing .c and .cc files, to preven this from regressing.

BUG=webrtc:6653
NOTRY=True

Review-Url: https://codereview.webrtc.org/2550563003
Cr-Commit-Position: refs/heads/master@{#15433}
This commit is contained in:
kjellander
2016-12-05 22:47:46 -08:00
committed by Commit bot
parent 5f7a9dc1c8
commit 7439f973f7
5 changed files with 341 additions and 116 deletions

View File

@ -6,6 +6,7 @@
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
import json
import os
import re
import sys
@ -291,6 +292,35 @@ def _CheckNoSourcesAbove(input_api, gn_files, output_api):
items=violating_gn_files)]
return []
def _CheckNoMixingCAndCCSources(input_api, gn_files, output_api):
# Disallow mixing .c and .cc source files in the same target.
source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
re.MULTILINE | re.DOTALL)
file_pattern = input_api.re.compile(r'"(.*)"')
violating_gn_files = dict()
for gn_file in gn_files:
contents = input_api.ReadFile(gn_file)
for source_block_match in source_pattern.finditer(contents):
c_files = []
cc_files = []
for file_list_match in file_pattern.finditer(source_block_match.group(1)):
source_file = file_list_match.group(1)
if source_file.endswith('.c'):
c_files.append(source_file)
if source_file.endswith('.cc'):
cc_files.append(source_file)
if c_files and cc_files:
violating_gn_files[gn_file.LocalPath()] = sorted(c_files + cc_files)
if violating_gn_files:
return [output_api.PresubmitError(
'GN targets cannot mix .cc and .c source files. Please create a '
'separate target for each collection of sources.\n'
'Mixed sources: \n'
'%s\n'
'Violating GN files:' % json.dumps(violating_gn_files, indent=2),
items=violating_gn_files.keys())]
return []
def _CheckGnChanges(input_api, output_api):
source_file_filter = lambda x: input_api.FilterSourceFile(
x, white_list=(r'.+\.(gn|gni)$',))
@ -304,6 +334,7 @@ def _CheckGnChanges(input_api, output_api):
if gn_files:
result.extend(_CheckNoRtcBaseDeps(input_api, gn_files, output_api))
result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api))
result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api))
return result
def _CheckUnwantedDependencies(input_api, output_api):