python / python/mypy

cppflags in test_c_unit_test is not supporting gcc compiler?

オープン
#11,252 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

I newly forked the repo and ran the tests with runtests.py in the project root. Then, I am getting an error while running test_c_unit_test in test_external.py as following:

running build_ext
building 'test_capi' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -mmacosx-version-min=10.10 -stdlib=libc++ -I../external/googletest -I../external/googletest/include -I/Users/terunobuinaba/OSS/mypy/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c exc_ops.c -o build/temp.macosx-10.9-x86_64-3.9/exc_ops.o -Wno-unused-function -Wno-sign-compare
gcc: error: unrecognized command-line option '-stdlib=libc++'
error: command '/usr/local/bin/gcc' failed with exit code 1

mypyc/test/test_external.py:16 (TestExternal.test_c_unit_test)
self = <mypyc.test.test_external.TestExternal testMethod=test_c_unit_test>

    @unittest.skipIf(sys.platform.startswith("win"), "rt tests don't work on windows")
    def test_c_unit_test(self) -> None:
        """Run C unit tests in a subprocess."""
        # Build Google Test, the C++ framework we use for testing C code.
        # The source code for Google Test is copied to this repository.
        cppflags: List[str] = []
        env = os.environ.copy()
        if sys.platform == 'darwin':
            cppflags += ['-mmacosx-version-min=10.10', '-stdlib=libc++']
        env['CPPFLAGS'] = ' '.join(cppflags)
        subprocess.check_call(
            ['make', 'libgtest.a'],
            env=env,
            cwd=os.path.join(base_dir, 'mypyc', 'external', 'googletest', 'make'))
        # Build Python wrapper for C unit tests.
        env = os.environ.copy()
        env['CPPFLAGS'] = ' '.join(cppflags)
>       status = subprocess.check_call(
            [sys.executable, 'setup.py', 'build_ext', '--inplace'],
            env=env,
            cwd=os.path.join(base_dir, 'mypyc', 'lib-rt'))

mypyc/test/test_external.py:34: 

To Reproduce
After cloning and install mypy using pip install, I followed the instruction here

 pip3 install -r test-requirements.txt
 python2 -m pip install -U typing
 ./runtests.py

Also, I am not using clang but using gcc instead in my mac PC.

Expected Behavior

No error raised.

Actual Behavior

As the fourth line in the error above suggests: gcc: error: unrecognized command-line option '-stdlib=libc++', gcc supports only libstdc++. No option should be passed for gcc environments?

class TestExternal(unittest.TestCase):
    # TODO: Get this to work on Windows.
    # (Or don't. It is probably not a good use of time.)
    @unittest.skipIf(sys.platform.startswith("win"), "rt tests don't work on windows")
    def test_c_unit_test(self) -> None:
        """Run C unit tests in a subprocess."""
        # Build Google Test, the C++ framework we use for testing C code.
        # The source code for Google Test is copied to this repository.
        cppflags: List[str] = []
        env = os.environ.copy()
        if sys.platform == 'darwin':
            cppflags += ['-mmacosx-version-min=10.10', '-stdlib=libc++']    # passing cppflags parameter
        env['CPPFLAGS'] = ' '.join(cppflags)

I guess simply branching in cppflags += ['-mmacosx-version-min=10.10', '-stdlib=libc++'] between clang/gcc would work.

Your Environment

  • Mypy version used: mypy 0.920+dev.492739692206f05347c6706cb982115446ba552a
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: Python 3.9.6
  • Operating system and version: macOS Big Sur 11.6
  • gcc version used: gcc version 10.2.0

P.S.
I am very new to open source contribution and this is actually the first issue I have made ever. I appreciate any comments, suggestions not only for the issue but also the manner of reporting the issue. Thank you for your guidance.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

mypyc/test/test_external.py の TestExternal.test_c_unit_test から始め、runtests.py がこのテストに到達する方法を確認します。報告されたコンパイラを使って macOS 上でビルドを再現し、サポートされていないフラグを渡さずに C ユニットテストのビルドが完了することを確認します。報告されたコンパイラでテストが動作し、既存の macOS テスト動作が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, python
領域
build-system, testing-qa
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。