Skip to content

Commit 1f59d2b

Browse files
committed
Adding a .ycm_extra_conf file for webkitGtk
https://bugs.webkit.org/show_bug.cgi?id=119618 Patch by Martin Robinson <mrobinson@igalia.com> and Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> on 2013-12-11 Reviewed by Gustavo Noronha Silva. Added a YouCompleteMe flag discovery script for Vim and the GTK+ port. The script read the GTK+ build files to determine dynamically what flags to compile a source file with. This allows Vim to provide auto-complete for C++/C language. See https://github.com/Valloric/YouCompleteMe for how to use this file. .: * .gitignore: Ignore the YCM symlinks in the tree. Tools: * gtk/common.py: (get_build_path): Added a fatal argument to build_path to avoid crashing YCM on failure. * gtk/ycm_extra_conf.py: Added. Canonical link: https://commits.webkit.org/143701@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160531 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9bab464 commit 1f59d2b

5 files changed

Lines changed: 187 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,6 @@ tags
117117
.project
118118
.cproject
119119
.settings
120+
121+
# Ignore YouCompleteMe symlinks
122+
.ycm_extra_conf.py

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2013-12-11 Martin Robinson <mrobinson@igalia.com> and Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>
2+
3+
Adding a .ycm_extra_conf file for webkitGtk
4+
https://bugs.webkit.org/show_bug.cgi?id=119618
5+
6+
Reviewed by Gustavo Noronha Silva.
7+
8+
Added a YouCompleteMe flag discovery script for Vim and the GTK+ port. The script
9+
read the GTK+ build files to determine dynamically what flags to compile a source
10+
file with. This allows Vim to provide auto-complete for C++/C language. See
11+
https://github.com/Valloric/YouCompleteMe for how to use this file.
12+
13+
* .gitignore: Ignore the YCM symlinks in the tree.
14+
115
2013-12-12 Zan Dobersek <zdobersek@igalia.com>
216

317
Use of ar T option not supported by older binutils

Tools/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2013-12-11 Martin Robinson <mrobinson@igalia.com> and Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>
2+
3+
Adding a .ycm_extra_conf file for webkitGtk
4+
https://bugs.webkit.org/show_bug.cgi?id=119618
5+
6+
Reviewed by Gustavo Noronha Silva.
7+
8+
Added a YouCompleteMe flag discovery script for Vim and the GTK+ port. The script
9+
read the GTK+ build files to determine dynamically what flags to compile a source
10+
file with. This allows Vim to provide auto-complete for C++/C language. See
11+
https://github.com/Valloric/YouCompleteMe for how to use this file.
12+
13+
* gtk/common.py:
14+
(get_build_path): Added a fatal argument to build_path to avoid crashing YCM on failure.
15+
* gtk/ycm_extra_conf.py: Added.
16+
117
2013-12-12 Tim Horton <timothy_horton@apple.com>
218

319
[wk2] Handle pinch-to-zoom gesture

Tools/gtk/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def top_level_path(*args):
3636
return os.path.join(*((os.path.join(os.path.dirname(__file__), '..', '..'),) + args))
3737

3838

39-
def get_build_path(build_types=('Release', 'Debug')):
39+
def get_build_path(build_types=('Release', 'Debug'), fatal=True):
4040
global build_dir
4141
if build_dir:
4242
return build_dir
@@ -76,7 +76,8 @@ def is_valid_build_directory(path):
7676
return build_dir
7777

7878
print('Could not determine build directory.')
79-
sys.exit(1)
79+
if fatal:
80+
sys.exit(1)
8081

8182

8283
def build_path_for_build_types(build_types, *args):

Tools/gtk/ycm_extra_conf.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env python
2+
# Copyright (C) 2013 Danilo Cesar Lemes de Paula <danilo.eu@gmail.com>
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
18+
import os
19+
import re
20+
import subprocess
21+
import sys
22+
23+
# It's very likely that this script is a symlink somewhere in the WebKit directory,
24+
# so we try to find the actual script location so that we can locate the tools
25+
# directory.
26+
if os.path.islink(__file__):
27+
__tools_directory = os.path.dirname(os.readlink(__file__))
28+
else:
29+
__tools_directory = os.path.dirname(__file__)
30+
sys.path.insert(0, os.path.abspath(__tools_directory))
31+
import common
32+
33+
MAKE_TRACE_FILE_NAME = "ycm-make-trace"
34+
FLAGS_PRECEDING_PATHS = ['-isystem', '-I', '-iquote', '--sysroot=']
35+
36+
37+
def transform_relative_paths_to_absolute_paths(arguments, build_path):
38+
result = []
39+
40+
make_next_absolute = False
41+
for argument in arguments:
42+
if make_next_absolute:
43+
make_next_absolute = False
44+
if not argument.startswith('/'):
45+
argument = os.path.join(build_path, argument)
46+
elif flag in FLAGS_PRECEDING_PATHS:
47+
# Some flags precede the path in the list. For those we make the
48+
# next argument absolute.
49+
if argument == flag:
50+
make_next_absolute = True
51+
else:
52+
# Some argument contain the flag and the path together. For these
53+
# we parse the argument out of the path.
54+
for flag in FLAGS_PRECEDING_PATHS:
55+
if argument.startswith(flag):
56+
argument = flag + os.path.join(build_path, argument[len(flag):])
57+
break
58+
59+
result.append(argument)
60+
return result
61+
62+
63+
def create_make_trace_file(build_path):
64+
print "Creating make trace file for YouCompleteMe, might take a few seconds"
65+
os.chdir(build_path)
66+
subprocess.call("make -n -s > %s" % MAKE_TRACE_FILE_NAME, shell=True)
67+
68+
69+
def make_trace_file_up_to_date(build_path):
70+
trace_file = os.path.join(build_path, MAKE_TRACE_FILE_NAME)
71+
if not os.path.isfile(trace_file):
72+
return False
73+
74+
makefile = os.path.join(build_path, 'GNUmakefile')
75+
if os.path.getmtime(trace_file) < os.path.getctime(makefile):
76+
return False
77+
78+
return True
79+
80+
81+
def ensure_make_trace_file(build_path):
82+
if make_trace_file_up_to_date(build_path):
83+
return True
84+
create_make_trace_file(build_path)
85+
return make_trace_file_up_to_date(build_path)
86+
87+
88+
def get_compilation_flags_from_build_commandline(command_line, build_path):
89+
flags = re.findall("-[I,D,p,O][\w,\.,/,-]*(?:=\"?\w*\"?)?", command_line)
90+
return transform_relative_paths_to_absolute_paths(flags, build_path)
91+
92+
93+
def get_compilation_flags_for_file(build_path, filename):
94+
trace_file_path = os.path.join(build_path, MAKE_TRACE_FILE_NAME)
95+
96+
try:
97+
trace_file = open(trace_file_path)
98+
lines = trace_file.readlines()
99+
trace_file.close()
100+
except:
101+
print "==== Error reading %s file", trace_file_path
102+
return []
103+
104+
basename = os.path.basename(filename)
105+
for line in lines:
106+
if line.find(basename) != -1 and line.find("CC") != -1 or line.find("CXX") != -1:
107+
return get_compilation_flags_from_build_commandline(line, build_path)
108+
109+
print "Could not find flags for %s" % filename
110+
return []
111+
112+
113+
def FlagsForFile(filename, **kwargs):
114+
"""This is the main entry point for YCM. Its interface is fixed.
115+
116+
Args:
117+
filename: (String) Path to source file being edited.
118+
119+
Returns:
120+
(Dictionary)
121+
'flags': (List of Strings) Command line flags.
122+
'do_cache': (Boolean) True if the result should be cached.
123+
"""
124+
125+
result = {'flags': ['-std=c++11', '-x', 'c++'], 'do_cache': True}
126+
127+
# Headers can't be built, so we get the source file flags instead.
128+
if filename.endswith('.h'):
129+
filename = filename[:-2] + ".cpp"
130+
if not os.path.exists(filename):
131+
return result
132+
133+
# Force config.h file inclusion, for GLib macros.
134+
result['flags'].append("-includeconfig.h")
135+
136+
build_path = common.get_build_path(fatal=False)
137+
if not build_path:
138+
print "Could not find WebKit build path."
139+
return result
140+
141+
if not ensure_make_trace_file(build_path):
142+
print "Could not create make trace file"
143+
return result
144+
145+
result['flags'].extend(get_compilation_flags_for_file(build_path, filename))
146+
return result
147+
148+
if __name__ == "__main__":
149+
import sys
150+
if len(sys.argv) >= 2:
151+
print FlagsForFile(sys.argv[1])

0 commit comments

Comments
 (0)