From 366b9d4e35eebbcc95b9eda09f1de8b15564e281 Mon Sep 17 00:00:00 2001 From: Bertrand Coconnier Date: Sun, 24 Jan 2021 20:24:23 +0100 Subject: [PATCH] Build a source package for JSBSim Python module compatible with all platforms (Windows, MacOSX, Linux) Until now, the CI workflow was building 2 different source packages (1 for Windows and 1 for MacOSX/Linux). Unfortunately, PyPI allows only one source package to be uploaded. This commit allows to produce just one source package that is compatible with all platforms. --- .github/workflows/cpp-python-build.yml | 26 ++++++-------------------- python/setup.py.in | 11 ++++++++--- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cpp-python-build.yml b/.github/workflows/cpp-python-build.yml index bb05d3cd51..37ab157519 100644 --- a/.github/workflows/cpp-python-build.yml +++ b/.github/workflows/cpp-python-build.yml @@ -203,10 +203,6 @@ jobs: - name: Test JSBSim working-directory: build run: ctest -j2 -E TestInputSocket --build-config RelWithDebInfo --output-on-failure - - name: Build source package for Python - if: env.release == 'true' - working-directory: build - run: python python/setup.py sdist --format=zip # On failure, upload logs - name: On failure - Upload logs @@ -263,7 +259,6 @@ jobs: build\src\RelWithDebInfo\JSBSim.lib build\python\jsbsim.cxx build\python\setup.py - build\python\dist\*.zip MacOSX: strategy: @@ -347,26 +342,18 @@ jobs: python-version: '3.7' - name: Install Python packages run: pip install -U cython numpy - - name: Download binary files (Linux & MacOSX) - id: UnixFiles - if: runner.os != 'Windows' + - name: Download binary files uses: actions/download-artifact@v2 with: name: macos-10.15.binaries - name: Build Python module from sources (Linux & MacOSX) - if: steps.UnixFiles.outcome == 'success' - run: pip install python/dist/*.tar.gz - - name: Download binary files (Windows) - id: WindowsFiles - if: runner.os == 'Windows' - uses: actions/download-artifact@v2 - with: - name: ${{ matrix.os }}.binaries + if: runner.os != 'Windows' + run: pip install python/dist/*.tar.gz -vv - name: Build Python module from sources (Windows) - if: steps.WindowsFiles.outcome == 'success' + if: runner.os == 'Windows' run: | - $PyPackage = Get-ChildItem -Path python\dist -Filter *.zip | Select-Object -First 1 - pip install $PyPackage.FullName + $PyPackage = Get-ChildItem -Path python\dist -Filter *.tar.gz | Select-Object -First 1 + pip install $PyPackage.FullName -vv - name: Test Python module shell: python run: | @@ -483,7 +470,6 @@ jobs: pip install -U twine twine upload dist/*.whl twine upload dist/*.tar.gz - twine upload dist/*.zip # Deploy stable release to GitHub - name: Get JSBSim version diff --git a/python/setup.py.in b/python/setup.py.in index 20fae50fb2..340691769c 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -153,6 +153,11 @@ if compiler.compiler_type == 'unix': else: cpp_compile_flag = [] +if compiler.compiler_type == 'msvc': + link_libraries = ['wsock32', 'ws2_32'] +else: + link_libraries = [${JSBSIM_LINK_LIBRARIES}] + # Update the JSBSim library path according to the --config option if args.config: if compiler.compiler_type == 'msvc': @@ -167,7 +172,7 @@ if 'sdist' not in dist.commands and compiler.find_library_file([library_path], # the Python module. ext_kwargs = { 'sources': ['${JSBSIM_CXX}'], 'include_dirs': ['src'], - 'libraries': ['JSBSim', ${JSBSIM_LINK_LIBRARIES}], + 'libraries': ['JSBSim'] + link_libraries, 'library_dirs': [library_path], 'extra_compile_args': cpp_compile_flag } setup_kwargs = { 'cmdclass' : {'build_ext': QuietBuild, @@ -176,13 +181,13 @@ else: # We cannot find the JSBSim library so the Python module must be built from # the sources. if compiler.compiler_type == 'msvc': - compile_flags = [('/D'+flag).replace('"', '\\"') for flag in [${JSBSIM_FLAGS}]] + compile_flags = [('/D'+flag).replace('"', '\\"') for flag in ['_USE_MATH_DEFINES', 'NOMINMAX', ${JSBSIM_FLAGS}]] else: compile_flags = ['-D'+flag for flag in [${JSBSIM_FLAGS}]] ext_kwargs = { 'sources': ['jsbsim.pyx', ${JSBSIM_SOURCE_FILES}], - 'libraries': [${JSBSIM_LINK_LIBRARIES}], + 'libraries': link_libraries, 'include_dirs': ['src', 'src/simgear/xml'], 'extra_compile_args': compile_flags } # List of required modules to build the JSBSim module from the sources.