2 Star 0 Fork 0

chromium_develop/chromium_tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
compile_test.py 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
李想 提交于 3年前 . chromium origin init
#!/usr/bin/env python
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Tries to compile given code, produces different output depending on success.
This is similar to checks done by ./configure scripts.
"""
from __future__ import print_function
import optparse
import os
import shutil
import subprocess
import sys
import tempfile
def DoMain(argv):
parser = optparse.OptionParser()
parser.add_option('--code')
parser.add_option('--run-linker', action='store_true')
parser.add_option('--on-success', default='')
parser.add_option('--on-failure', default='')
options, args = parser.parse_args(argv)
if not options.code:
parser.error('Missing required --code switch.')
# The environment variable might expand to a string with spaces,
# e.g. "ccache g++". Convert it to a list suitable for argv.
cxx = os.environ.get('CXX', 'g++').split()
tmpdir = tempfile.mkdtemp()
try:
cxx_path = os.path.join(tmpdir, 'test.cc')
with open(cxx_path, 'w') as f:
f.write(options.code.decode('string-escape'))
o_path = os.path.join(tmpdir, 'test.o')
cxx_cmdline = cxx + [cxx_path, '-o', o_path]
if not options.run_linker:
cxx_cmdline.append('-c')
# Pass remaining arguments to the compiler.
cxx_cmdline += args
cxx_popen = subprocess.Popen(cxx_cmdline,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
cxx_stdout, cxx_stderr = cxx_popen.communicate()
if cxx_popen.returncode == 0:
print(options.on_success)
else:
print(options.on_failure)
finally:
shutil.rmtree(tmpdir)
return 0
if __name__ == '__main__':
sys.exit(DoMain(sys.argv[1:]))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chromium_develop/chromium_tools.git
git@gitee.com:chromium_develop/chromium_tools.git
chromium_develop
chromium_tools
chromium_tools
master

搜索帮助