1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 from StringIO
import StringIO
12 from io
import StringIO
14 old_bytecode
= sys
.dont_write_bytecode
15 sys
.dont_write_bytecode
= True
17 path
= os
.path
.join(os
.path
.dirname(__file__
), 'mach')
19 if not os
.path
.exists(path
):
20 path
= os
.path
.join(os
.path
.dirname(__file__
), 'config.status')
21 config
= imp
.load_module('_buildconfig', open(path
), path
, ('', 'r', imp
.PY_SOURCE
))
22 path
= os
.path
.join(config
.topsrcdir
, 'mach')
23 mach_module
= imp
.load_module('_mach', open(path
), path
, ('', 'r', imp
.PY_SOURCE
))
25 sys
.dont_write_bytecode
= old_bytecode
27 def FlagsForFile(filename
):
28 mach
= mach_module
.get_mach()
31 # Mach calls sys.stdout.fileno(), so we need to fake it when capturing it.
32 # Returning an invalid file descriptor does the trick.
33 out
.fileno
= lambda: -1
35 mach
.run(['compileflags', filename
], stdout
=out
, stderr
=out
)
37 flag_list
= shlex
.split(out
.getvalue())
39 # This flag is added by Fennec for android build and causes ycmd to fail to parse the file.
40 # Removing this flag is a workaround until ycmd starts to handle this flag properly.
41 # https://github.com/Valloric/YouCompleteMe/issues/1490
42 final_flags
= [x
for x
in flag_list
if not x
.startswith('-march=armv')]