diff --git a/.github/actions/checkout/action.yaml b/.github/actions/checkout/action.yaml new file mode 100644 index 00000000..7da7fe73 --- /dev/null +++ b/.github/actions/checkout/action.yaml @@ -0,0 +1,21 @@ +# Copyright (C) 2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: 🧰 Checkout +description: "Checkout the git repository correctly" + +runs: + using: "includes" + + steps: + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + # Always clone the full depth so git-describe works. + fetch-depth: 0 + submodules: true diff --git a/.github/actions/download-and-run-tests/action.yaml b/.github/actions/download-and-run-tests/action.yaml new file mode 100644 index 00000000..b4eaceac --- /dev/null +++ b/.github/actions/download-and-run-tests/action.yaml @@ -0,0 +1,46 @@ +# Copyright (C) 2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: Download and run tests +description: "Download the tests from GitHub and run them." + +runs: + using: "includes" + + steps: + + - name: Smoke Test - Run fasm tool + run: | + fasm --help + + - name: Smoke Test - Import fasm module + shell: python + run: | + import fasm + + - name: Smoke Test - Print fasm version info + includes-script: fasm-version.py + + - name: Getting the tests + includes-script: get-tests.sh + + - name: List Tests + shell: bash + run: | + echo "::group::Top directory" + ls -l tests + echo "::endgroup::" + echo "::group::Files found" + find tests -type f | sort + echo "::endgroup::" + + - name: Run Tests + shell: bash + run: | + cd tests + python test_simple.py diff --git a/.github/actions/download-and-run-tests/fasm-version.py b/.github/actions/download-and-run-tests/fasm-version.py new file mode 100644 index 00000000..dc0abd3c --- /dev/null +++ b/.github/actions/download-and-run-tests/fasm-version.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +import fasm.version + +l = [] + +print() +print(' FASM library version info') +print('='*75) + +kl = max(len(k) for k in dir(fasm.version)) +for k in dir(fasm.version): + if '__' in k: + continue + v = getattr(fasm.version, k) + if isinstance(v, str) and '\n' in v: + l.append((k,v)) + else: + print(" {!s}: {!r}".format(k.rjust(kl), v)) + +for k, v in l: + print() + print(k) + print('-'*75) + print(v) + print('-'*75) diff --git a/.github/actions/download-and-run-tests/get-tests.sh b/.github/actions/download-and-run-tests/get-tests.sh new file mode 100644 index 00000000..683ee272 --- /dev/null +++ b/.github/actions/download-and-run-tests/get-tests.sh @@ -0,0 +1,54 @@ +if [ -d tests ]; then + echo "::group::Using existing tests" + ls -l tests + echo "::endgroup::" +else + echo "::group::Event info" + cat ${GITHUB_EVENT_PATH} + echo "::endgroup::" + echo "::group::GitHub info" + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" + echo " GITHUB_ACTOR: ${GITHUB_ACTOR}" + echo " GITHUB_REF: ${GITHUB_REF}" + echo " GITHUB_BASE_REF: ${GITHUB_BASE_REF}" + echo " GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" + echo " GITHUB_SHA: ${GITHUB_SHA}" + echo "::endgroup::" + echo "::group::Downloading tests from ${GITHUB_REPOSITORY}" + set -x + mkdir .checkout-tests + cd .checkout-tests + git init + git config core.sparseCheckout true + if [ -f .git/info/sparse-checkout ]; then + rm .git/info/sparse-checkout + fi + echo "tests/*" >> .git/info/sparse-checkout + echo "examples/*" >> .git/info/sparse-checkout + git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git + git fetch --all + git remote -v + if [ ! -z "${GITHUB_REF}" ]; then + git fetch --refmap='' origin ${GITHUB_REF}:refs/remotes/origin/merge || true + fi + if [ ! -z "${GITHUB_BASE_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_BASE_REF}:refs/remotes/origin/base || true + fi + if [ ! -z "${GITHUB_HEAD_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/head || true + fi + git remote show origin + git branch -v -a + + git show-ref ${GITHUB_SHA} || true + git rev-parse --verify "sha^${GITHUB_SHA}" || true + + git fetch -q https://github.com/SymbiFlow/fasm.git ${GITHUB_SHA} + git rev-parse FETCH_HEAD + git checkout ${GITHUB_SHA} + for i in *; do + cp -rvf $i .. + done + cd .. + echo "::endgroup::" +fi diff --git a/.github/actions/system-setup/action.yaml b/.github/actions/system-setup/action.yaml new file mode 100644 index 00000000..f832dff0 --- /dev/null +++ b/.github/actions/system-setup/action.yaml @@ -0,0 +1,93 @@ +# Copyright (C) 2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: "Setup system for package" +description: "Set up system with Python environment and dependencies ready for the package." +inputs: + python-version: + description: 'Python version to use.' + required: true + default: 3.x + os: + description: 'Operating system in use.' + required: true + default: ubuntu-latest + system-dependencies: + description: 'Install the system dependencies on the operating system.' + required: true + default: true + packaging-tools: + description: 'Install the tools required for packaging.' + required: false + default: false + git-checkout: + description: 'Download the repository from git.' + required: true + default: true + development-tools: + description: 'Install the tools required for development.' + required: true + default: false + +runs: + using: "includes" + + steps: + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ inputs.python-version }} + + - name: Install latest pip + run: | + pip install -U pip + + - name: Install package's system dependencies (Ubuntu) + if: inputs.system-dependencies && startsWith(inputs.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + + - name: Install package's system dependencies (Mac OS X) + if: inputs.system-dependencies && startsWith(inputs.os, 'macos') + run: | + true + + - name: Install package's system dependencies (Windows) + if: inputs.system-dependencies && startsWith(inputs.os, 'windows') + run: | + true + + - name: Install packaging tooling + if: inputs.packaging-tools + run: | + pip install twine auditwheel build + + - includes: /checkout + if: inputs.git-checkout + + - name: Install developer tooling's system dependencies (Ubuntu) + if: inputs.development-tools && startsWith(inputs.os, 'ubuntu') + run: | + sudo apt-get update + sudo apt-get install -y clang-format + + - name: Install developer tooling's system dependencies (Mac OS X) + if: inputs.development-tools && startsWith(inputs.os, 'macos') + run: | + true + + - name: Install developer tooling's system dependencies (Windows) + if: inputs.development-tools && startsWith(inputs.os, 'windows') + run: | + true + + - name: Install development tools + if: inputs.development-tools + run: | + pip install -r requirements.txt diff --git a/.github/actions/upload-to-pypi/action.yaml b/.github/actions/upload-to-pypi/action.yaml new file mode 100644 index 00000000..f4736267 --- /dev/null +++ b/.github/actions/upload-to-pypi/action.yaml @@ -0,0 +1,60 @@ +# Copyright (C) 2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: "Publish packages into PyPI" +description: "Check the packages and then publish packages onto Test and real versions." +inputs: + type: + description: 'Type of packages to publish to PyPi.' + required: true + root_repo: + description: 'Repository name that should be publishing packages to PyPi.' + required: true + root_branch: + description: 'Default branch to publish packages from.' + required: true + default: refs/heads/master + +runs: + using: "includes" + + steps: + - name: ✔︎ Check 📦 + run: | + for WHEEL in dist/*.whl; do + echo + echo "::group::Checking $WHEEL" + echo + python -m zipfile --list $WHEEL + echo + auditwheel show $WHEEL + echo + twine check $WHEEL + echo + echo "::endgroup::" + done + + - name: 📤 Publish ${{ inputs.type }} to Test PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }} + if: env.TWINE_PASSWORD != null + run: | + twine upload --skip-existing --verbose --repository testpypi dist/* + + - name: 📤 Publish source to PyPI + if: | + (github.ref == inputs.root_branch) && + (github.event_name != 'pull_request') && + (github.repository == inputs.root_repo) && + env.TWINE_PASSWORD != null + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + twine upload dist/* diff --git a/.github/workflows-src/Makefile b/.github/workflows-src/Makefile new file mode 100644 index 00000000..9e02ad59 --- /dev/null +++ b/.github/workflows-src/Makefile @@ -0,0 +1,46 @@ +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +# Set up a Python environment to run the actions_include tool on. +ENV_DIR = venv +PYTHON = $(ENV_DIR)/bin/python3 +ACTIVATE = source $(ENV_DIR)/bin/activate; + +env: requirements.txt + rm -rf $(ENV_DIR) + virtualenv --copies $(ENV_DIR) + $(ACTIVATE) pip install -r $< + touch --reference=$< $(PYTHON) + +.PHONY: env + +$(PYTHON): requirements.txt + make env + +# Generate the output files +SRC_YAML = $(wildcard *.yml) +OUT_YAML = $(addprefix ../workflows/,$(SRC_YAML)) + +../workflows/%.yml: %.yml | $(PYTHON) + @echo + @echo Updating $@ + @echo ------------------------------------------------ + $(ACTIVATE) python -m actions_includes $< $@ + @echo ------------------------------------------------ + +update: + @for F in $(SRC_YAML); do touch $$F; done + make build + +build: $(OUT_YAML) | $(PYTHON) + @true + +info: + @echo 'Output files: $(OUT_YAML)' + +.PHONY: info diff --git a/.github/workflows-src/check-functionality.yml b/.github/workflows-src/check-functionality.yml new file mode 100644 index 00000000..67e602b7 --- /dev/null +++ b/.github/workflows-src/check-functionality.yml @@ -0,0 +1,40 @@ +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +on: + push: + pull_request: + +name: Functionality +jobs: + + functionality: + runs-on: ubuntu-20.04 + + strategy: + matrix: + antlr_runtime_type: [static, shared] + include: + - { python-version: 3.5, TOXENV: py35 } + - { python-version: 3.6, TOXENV: py36 } + - { python-version: 3.7, TOXENV: py37 } + - { python-version: 3.8, TOXENV: py38 } + - { python-version: 3.9, TOXENV: py39 } + fail-fast: false + + name: Functionality on Python ${{ matrix.python-version }} (with ${{ matrix.antlr_runtime_type}} antlr) + + steps: + - includes: /system-setup + with: + development-tools: true + python-version: ${{ matrix.python-version }} + + - name: Run Tests + run: | + ANTLR4_RUNTIME_TYPE=${{ matrix.antlr_runtime_type }} tox -e ${{ matrix.TOXENV }} diff --git a/.github/workflows-src/check-install.yml b/.github/workflows-src/check-install.yml new file mode 100644 index 00000000..ff629970 --- /dev/null +++ b/.github/workflows-src/check-install.yml @@ -0,0 +1,199 @@ +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: Install from + +on: + push: + pull_request: + + +jobs: + + # Install directly using pip from GitHub + # ---------------------------------------------------------------------- + GitHub: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + fail-fast: false + + runs-on: ${{ matrix.os }} + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + git-checkout: false + + - name: Installing directly from GitHub + shell: bash + run: | + pip install --verbose git+https://github.com/${GITHUB_REPOSITORY}.git@${GITHUB_SHA}#egg=fasm + + - includes: /download-and-run-tests + # ---------------------------------------------------------------------- + + # Install using a local checkout + # ---------------------------------------------------------------------- + Checkout: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + cmd: + - python setup.py install + - pip install --verbose . + - pip install --verbose -e . # Editable install + fail-fast: false + + name: Checkout with '${{ matrix.cmd }}' (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + + - name: Installing using '${{ matrix.cmd }}' + run: | + ${{ matrix.cmd }} + + - includes: /download-and-run-tests + # ---------------------------------------------------------------------- + + # Install into self-contained `make-env` environment. + # ---------------------------------------------------------------------- + make-env: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + fail-fast: false + + name: make-env (Conda) + runs-on: ${{ matrix.os }} + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + + - name: Run tests + run: | + make test + # ---------------------------------------------------------------------- + + # Install from a sdist package + # ---------------------------------------------------------------------- + BuildSdist: + strategy: + matrix: + os: [ubuntu-20.04] + fail-fast: false + + runs-on: ${{ matrix.os }} + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + packaging-tools: true + + - name: Build wheel + run: | + python -m build --sdist + + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: fasm-sdist + path: dist + + sdist: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + fail-fast: false + + runs-on: ${{ matrix.os }} + needs: BuildSdist + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + git-checkout: false + + - name: Download sdist + uses: actions/download-artifact@v2 + with: + name: fasm-sdist + path: dist + + - name: Installing using the sdist + shell: bash + run: | + ls -l dist/* + pip install --verbose dist/* + + - includes: /download-and-run-tests + # ---------------------------------------------------------------------- + + # Install from a binary wheel package + # ---------------------------------------------------------------------- + BuildWheel: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + fail-fast: false + + runs-on: ${{ matrix.os }} + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + packaging-tools: true + + - name: Build wheel + run: | + python -m build --wheel + + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: fasm-wheel-${{ matrix.os }} + path: dist + + Wheel: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-20.04] + fail-fast: false + + runs-on: ${{ matrix.os }} + needs: BuildWheel + + steps: + - includes: /system-setup + with: + os: ${{ matrix.os }} + git-checkout: false + + - name: Download wheel + uses: actions/download-artifact@v2 + with: + name: fasm-wheel-${{ matrix.os }} + path: dist + + - name: Installing using the wheel + run: | + ls -l dist/* + pip install --verbose dist/*.whl + + - includes: /download-and-run-tests + # ---------------------------------------------------------------------- diff --git a/.github/workflows-src/check-style.yml b/.github/workflows-src/check-style.yml new file mode 100644 index 00000000..f9ab4f7e --- /dev/null +++ b/.github/workflows-src/check-style.yml @@ -0,0 +1,39 @@ +# Copyright (C) 2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: Style + +on: + push: + pull_request: + +jobs: + + Style: + runs-on: ubuntu-20.04 + + steps: + - includes: /system-setup + with: + development-tools: true + + - name: Check license headers + run: make check-license + + - name: Python style check + run: | + make format lint + test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; } + + - name: Python script checks + run: make check-python-scripts + + - name: C++ style check + run: | + make format-cpp + test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; } diff --git a/.github/workflows-src/publish-to-pypi.yml b/.github/workflows-src/publish-to-pypi.yml new file mode 100644 index 00000000..362ba14e --- /dev/null +++ b/.github/workflows-src/publish-to-pypi.yml @@ -0,0 +1,67 @@ +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +name: PyPI + +on: + push: + pull_request: + workflow_dispatch: + + +jobs: + + Source: + name: Source + runs-on: ubuntu-20.04 + + steps: + - includes: /checkout + + - includes: mithro/actions/includes/python/publish-to-pypi-src@main + with: + root_user: SymbiFlow + + Wheels-Linux: + strategy: + matrix: + python-version: [ '3.6', '3.7', '3.8', '3.9' ] + fail-fast: false + + name: '${{ matrix.python-version }} • manylinux' + runs-on: ubuntu-20.04 + + steps: + - includes: /checkout + + - includes: mithro/actions/includes/python/publish-to-pypi-wheels-bin-linux@main + with: + pre-build-command: bash .github/workflows/manylinux-install-cmake.sh + build-requirements: cython + system-packages: java-1.8.0-openjdk uuid uuid-devel libuuid libuuid-devel git + python-version: ${{ matrix.python-version }} + package-path: '' + root_user: SymbiFlow + + Wheels-Other: + strategy: + matrix: + os: [windows-latest, macos-latest] + python-version: [ '3.6', '3.7', '3.8', '3.9' ] + fail-fast: false + + name: '${{ matrix.python-version }} • ${{ matrix.os }}' + runs-on: ${{ matrix.os }} + + steps: + - includes: /checkout + + - includes: mithro/actions/includes/python/publish-to-pypi-wheels-bin-other@main + with: + python-version: ${{ matrix.python-version }} + root_user: SymbiFlow diff --git a/.github/workflows-src/requirements.txt b/.github/workflows-src/requirements.txt new file mode 100644 index 00000000..b64c895d --- /dev/null +++ b/.github/workflows-src/requirements.txt @@ -0,0 +1 @@ +git+https://github.com/mithro/actions-includes.git#egg=actions-includes diff --git a/.github/workflows/check-functionality.yml b/.github/workflows/check-functionality.yml new file mode 100644 index 00000000..67975918 --- /dev/null +++ b/.github/workflows/check-functionality.yml @@ -0,0 +1,71 @@ +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +# !! WARNING !! +# Do not modify this file directly! +# !! WARNING !! +# +# It is generated from: ../workflows-src/check-functionality.yml +# using the script from https://github.com/mithro/actions-includes@main + +on: + push: + pull_request: +name: Functionality +jobs: + functionality: + runs-on: ubuntu-20.04 + strategy: + matrix: + antlr_runtime_type: + - static + - shared + include: + - python-version: 3.5 + TOXENV: py35 + - python-version: 3.6 + TOXENV: py36 + - python-version: 3.7 + TOXENV: py37 + - python-version: 3.8 + TOXENV: py38 + - python-version: 3.9 + TOXENV: py39 + fail-fast: false + name: Functionality on Python ${{ matrix.python-version }} (with ${{ matrix.antlr_runtime_type}} antlr) + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-functionality.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + - name: Install developer tooling's system dependencies (Ubuntu) + run: | + sudo apt-get update + sudo apt-get install -y clang-format + - name: Install development tools + run: | + pip install -r requirements.txt + - name: Run Tests + run: ANTLR4_RUNTIME_TYPE=${{ matrix.antlr_runtime_type }} tox -e ${{ matrix.TOXENV }} diff --git a/.github/workflows/check-install.yml b/.github/workflows/check-install.yml index 8793a2b1..fcaf9e62 100644 --- a/.github/workflows/check-install.yml +++ b/.github/workflows/check-install.yml @@ -1,57 +1,770 @@ -name: Install from +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +# !! WARNING !! +# Do not modify this file directly! +# !! WARNING !! +# +# It is generated from: ../workflows-src/check-install.yml +# using the script from https://github.com/mithro/actions-includes@main on: push: pull_request: - - +name: Install from jobs: - GitHub: strategy: matrix: - os: [windows-latest, macos-latest, ubuntu-20.04] + os: + - windows-latest + - macos-latest + - ubuntu-20.04 fail-fast: false - - name: GitHub runs-on: ${{ matrix.os }} - steps: - - name: Install dependencies (Ubuntu) - if: startsWith(matrix.os, 'ubuntu') + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} run: | sudo apt-get update sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev - - - name: Install dependencies (Mac OS X) - if: startsWith(matrix.os, 'macos') + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} run: | true - - - name: Install dependencies (Windows) - if: startsWith(matrix.os, 'windows') + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} run: | true + - name: Installing directly from GitHub + shell: bash + run: | + pip install --verbose git+https://github.com/${GITHUB_REPOSITORY}.git@${GITHUB_SHA}#egg=fasm + - name: Smoke Test - Run fasm tool + run: | + fasm --help + - name: Smoke Test - Import fasm module + shell: python + run: | + import fasm + - name: Smoke Test - Print fasm version info + run: | + #!/usr/bin/env python + + import fasm.version + + l = [] + + print() + print(' FASM library version info') + print('='*75) - - name: 🐍 Set up Python + kl = max(len(k) for k in dir(fasm.version)) + for k in dir(fasm.version): + if '__' in k: + continue + v = getattr(fasm.version, k) + if isinstance(v, str) and '\n' in v: + l.append((k,v)) + else: + print(" {!s}: {!r}".format(k.rjust(kl), v)) + + for k, v in l: + print() + print(k) + print('-'*75) + print(v) + print('-'*75) + shell: python + - name: Getting the tests + run: | + if [ -d tests ]; then + echo "::group::Using existing tests" + ls -l tests + echo "::endgroup::" + else + echo "::group::Event info" + cat ${GITHUB_EVENT_PATH} + echo "::endgroup::" + echo "::group::GitHub info" + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" + echo " GITHUB_ACTOR: ${GITHUB_ACTOR}" + echo " GITHUB_REF: ${GITHUB_REF}" + echo " GITHUB_BASE_REF: ${GITHUB_BASE_REF}" + echo " GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" + echo " GITHUB_SHA: ${GITHUB_SHA}" + echo "::endgroup::" + echo "::group::Downloading tests from ${GITHUB_REPOSITORY}" + set -x + mkdir .checkout-tests + cd .checkout-tests + git init + git config core.sparseCheckout true + if [ -f .git/info/sparse-checkout ]; then + rm .git/info/sparse-checkout + fi + echo "tests/*" >> .git/info/sparse-checkout + echo "examples/*" >> .git/info/sparse-checkout + git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git + git fetch --all + git remote -v + if [ ! -z "${GITHUB_REF}" ]; then + git fetch --refmap='' origin ${GITHUB_REF}:refs/remotes/origin/merge || true + fi + if [ ! -z "${GITHUB_BASE_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_BASE_REF}:refs/remotes/origin/base || true + fi + if [ ! -z "${GITHUB_HEAD_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/head || true + fi + git remote show origin + git branch -v -a + + git show-ref ${GITHUB_SHA} || true + git rev-parse --verify "sha^${GITHUB_SHA}" || true + + git fetch -q https://github.com/SymbiFlow/fasm.git ${GITHUB_SHA} + git rev-parse FETCH_HEAD + git checkout ${GITHUB_SHA} + for i in *; do + cp -rvf $i .. + done + cd .. + echo "::endgroup::" + fi + shell: bash + - name: List Tests + shell: bash + run: | + echo "::group::Top directory" + ls -l tests + echo "::endgroup::" + echo "::group::Files found" + find tests -type f | sort + echo "::endgroup::" + - name: Run Tests + shell: bash + run: | + cd tests + python test_simple.py + Checkout: + strategy: + matrix: + os: + - windows-latest + - macos-latest + - ubuntu-20.04 + cmd: + - python setup.py install + - pip install --verbose . + - pip install --verbose -e . + fail-fast: false + name: Checkout with '${{ matrix.cmd }}' (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + true + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + true + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + - name: Installing using '${{ matrix.cmd }}' + run: | + ${{ matrix.cmd }} + - name: Smoke Test - Run fasm tool + run: | + fasm --help + - name: Smoke Test - Import fasm module + shell: python + run: | + import fasm + - name: Smoke Test - Print fasm version info + run: | + #!/usr/bin/env python + + import fasm.version - - name: Install pip+wheel + l = [] + + print() + print(' FASM library version info') + print('='*75) + + kl = max(len(k) for k in dir(fasm.version)) + for k in dir(fasm.version): + if '__' in k: + continue + v = getattr(fasm.version, k) + if isinstance(v, str) and '\n' in v: + l.append((k,v)) + else: + print(" {!s}: {!r}".format(k.rjust(kl), v)) + + for k, v in l: + print() + print(k) + print('-'*75) + print(v) + print('-'*75) + shell: python + - name: Getting the tests run: | - pip install --upgrade wheel - pip install --upgrade pip + if [ -d tests ]; then + echo "::group::Using existing tests" + ls -l tests + echo "::endgroup::" + else + echo "::group::Event info" + cat ${GITHUB_EVENT_PATH} + echo "::endgroup::" + echo "::group::GitHub info" + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" + echo " GITHUB_ACTOR: ${GITHUB_ACTOR}" + echo " GITHUB_REF: ${GITHUB_REF}" + echo " GITHUB_BASE_REF: ${GITHUB_BASE_REF}" + echo " GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" + echo " GITHUB_SHA: ${GITHUB_SHA}" + echo "::endgroup::" + echo "::group::Downloading tests from ${GITHUB_REPOSITORY}" + set -x + mkdir .checkout-tests + cd .checkout-tests + git init + git config core.sparseCheckout true + if [ -f .git/info/sparse-checkout ]; then + rm .git/info/sparse-checkout + fi + echo "tests/*" >> .git/info/sparse-checkout + echo "examples/*" >> .git/info/sparse-checkout + git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git + git fetch --all + git remote -v + if [ ! -z "${GITHUB_REF}" ]; then + git fetch --refmap='' origin ${GITHUB_REF}:refs/remotes/origin/merge || true + fi + if [ ! -z "${GITHUB_BASE_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_BASE_REF}:refs/remotes/origin/base || true + fi + if [ ! -z "${GITHUB_HEAD_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/head || true + fi + git remote show origin + git branch -v -a - - name: Test installation + git show-ref ${GITHUB_SHA} || true + git rev-parse --verify "sha^${GITHUB_SHA}" || true + + git fetch -q https://github.com/SymbiFlow/fasm.git ${GITHUB_SHA} + git rev-parse FETCH_HEAD + git checkout ${GITHUB_SHA} + for i in *; do + cp -rvf $i .. + done + cd .. + echo "::endgroup::" + fi + shell: bash + - name: List Tests + shell: bash + run: | + echo "::group::Top directory" + ls -l tests + echo "::endgroup::" + echo "::group::Files found" + find tests -type f | sort + echo "::endgroup::" + - name: Run Tests shell: bash run: | - pip install git+https://github.com/${GITHUB_REPOSITORY}.git@${GITHUB_SHA}#egg=fasm + cd tests + python test_simple.py + make-env: + strategy: + matrix: + os: + - windows-latest + - macos-latest + - ubuntu-20.04 + fail-fast: false + name: make-env (Conda) + runs-on: ${{ matrix.os }} + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + true + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + true + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + - name: Run tests + run: | + make test + BuildSdist: + strategy: + matrix: + os: + - ubuntu-20.04 + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + true + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + true + - name: Install packaging tooling + run: | + pip install twine auditwheel build + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + - name: Build wheel + run: | + python -m build --sdist + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: fasm-sdist + path: dist + sdist: + strategy: + matrix: + os: + - windows-latest + - macos-latest + - ubuntu-20.04 + fail-fast: false + runs-on: ${{ matrix.os }} + needs: BuildSdist + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + true + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + true + - name: Download sdist + uses: actions/download-artifact@v2 + with: + name: fasm-sdist + path: dist + - name: Installing using the sdist + shell: bash + run: | + ls -l dist/* + pip install --verbose dist/* + - name: Smoke Test - Run fasm tool + run: | + fasm --help + - name: Smoke Test - Import fasm module + shell: python + run: | + import fasm + - name: Smoke Test - Print fasm version info + run: | + #!/usr/bin/env python + + import fasm.version + + l = [] + + print() + print(' FASM library version info') + print('='*75) + + kl = max(len(k) for k in dir(fasm.version)) + for k in dir(fasm.version): + if '__' in k: + continue + v = getattr(fasm.version, k) + if isinstance(v, str) and '\n' in v: + l.append((k,v)) + else: + print(" {!s}: {!r}".format(k.rjust(kl), v)) + + for k, v in l: + print() + print(k) + print('-'*75) + print(v) + print('-'*75) + shell: python + - name: Getting the tests + run: | + if [ -d tests ]; then + echo "::group::Using existing tests" + ls -l tests + echo "::endgroup::" + else + echo "::group::Event info" + cat ${GITHUB_EVENT_PATH} + echo "::endgroup::" + echo "::group::GitHub info" + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" + echo " GITHUB_ACTOR: ${GITHUB_ACTOR}" + echo " GITHUB_REF: ${GITHUB_REF}" + echo " GITHUB_BASE_REF: ${GITHUB_BASE_REF}" + echo " GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" + echo " GITHUB_SHA: ${GITHUB_SHA}" + echo "::endgroup::" + echo "::group::Downloading tests from ${GITHUB_REPOSITORY}" + set -x + mkdir .checkout-tests + cd .checkout-tests + git init + git config core.sparseCheckout true + if [ -f .git/info/sparse-checkout ]; then + rm .git/info/sparse-checkout + fi + echo "tests/*" >> .git/info/sparse-checkout + echo "examples/*" >> .git/info/sparse-checkout + git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git + git fetch --all + git remote -v + if [ ! -z "${GITHUB_REF}" ]; then + git fetch --refmap='' origin ${GITHUB_REF}:refs/remotes/origin/merge || true + fi + if [ ! -z "${GITHUB_BASE_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_BASE_REF}:refs/remotes/origin/base || true + fi + if [ ! -z "${GITHUB_HEAD_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/head || true + fi + git remote show origin + git branch -v -a + + git show-ref ${GITHUB_SHA} || true + git rev-parse --verify "sha^${GITHUB_SHA}" || true - - name: Run Smoke Test + git fetch -q https://github.com/SymbiFlow/fasm.git ${GITHUB_SHA} + git rev-parse FETCH_HEAD + git checkout ${GITHUB_SHA} + for i in *; do + cp -rvf $i .. + done + cd .. + echo "::endgroup::" + fi + shell: bash + - name: List Tests + shell: bash + run: | + echo "::group::Top directory" + ls -l tests + echo "::endgroup::" + echo "::group::Files found" + find tests -type f | sort + echo "::endgroup::" + - name: Run Tests + shell: bash + run: | + cd tests + python test_simple.py + BuildWheel: + strategy: + matrix: + os: + - windows-latest + - macos-latest + - ubuntu-20.04 + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + true + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + true + - name: Install packaging tooling + run: | + pip install twine auditwheel build + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + - name: Build wheel + run: | + python -m build --wheel + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: fasm-wheel-${{ matrix.os }} + path: dist + Wheel: + strategy: + matrix: + os: + - windows-latest + - macos-latest + - ubuntu-20.04 + fail-fast: false + runs-on: ${{ matrix.os }} + needs: BuildWheel + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-install.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: Install package's system dependencies (Mac OS X) + if: ${{ startsWith(matrix.os, 'macos') }} + run: | + true + - name: Install package's system dependencies (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + run: | + true + - name: Download wheel + uses: actions/download-artifact@v2 + with: + name: fasm-wheel-${{ matrix.os }} + path: dist + - name: Installing using the wheel + run: | + ls -l dist/* + pip install --verbose dist/*.whl + - name: Smoke Test - Run fasm tool run: | fasm --help + - name: Smoke Test - Import fasm module + shell: python + run: | + import fasm + - name: Smoke Test - Print fasm version info + run: | + #!/usr/bin/env python + + import fasm.version -# PyPi: -# runs-on: ubuntu-20.04 -# name: PyPi + l = [] + + print() + print(' FASM library version info') + print('='*75) + + kl = max(len(k) for k in dir(fasm.version)) + for k in dir(fasm.version): + if '__' in k: + continue + v = getattr(fasm.version, k) + if isinstance(v, str) and '\n' in v: + l.append((k,v)) + else: + print(" {!s}: {!r}".format(k.rjust(kl), v)) + + for k, v in l: + print() + print(k) + print('-'*75) + print(v) + print('-'*75) + shell: python + - name: Getting the tests + run: | + if [ -d tests ]; then + echo "::group::Using existing tests" + ls -l tests + echo "::endgroup::" + else + echo "::group::Event info" + cat ${GITHUB_EVENT_PATH} + echo "::endgroup::" + echo "::group::GitHub info" + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}" + echo " GITHUB_ACTOR: ${GITHUB_ACTOR}" + echo " GITHUB_REF: ${GITHUB_REF}" + echo " GITHUB_BASE_REF: ${GITHUB_BASE_REF}" + echo " GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}" + echo " GITHUB_SHA: ${GITHUB_SHA}" + echo "::endgroup::" + echo "::group::Downloading tests from ${GITHUB_REPOSITORY}" + set -x + mkdir .checkout-tests + cd .checkout-tests + git init + git config core.sparseCheckout true + if [ -f .git/info/sparse-checkout ]; then + rm .git/info/sparse-checkout + fi + echo "tests/*" >> .git/info/sparse-checkout + echo "examples/*" >> .git/info/sparse-checkout + git remote add origin ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git + git fetch --all + git remote -v + if [ ! -z "${GITHUB_REF}" ]; then + git fetch --refmap='' origin ${GITHUB_REF}:refs/remotes/origin/merge || true + fi + if [ ! -z "${GITHUB_BASE_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_BASE_REF}:refs/remotes/origin/base || true + fi + if [ ! -z "${GITHUB_HEAD_REF}" ]; then + git fetch --refmap='' origin refs/heads/${GITHUB_HEAD_REF}:refs/remotes/origin/head || true + fi + git remote show origin + git branch -v -a + + git show-ref ${GITHUB_SHA} || true + git rev-parse --verify "sha^${GITHUB_SHA}" || true + + git fetch -q https://github.com/SymbiFlow/fasm.git ${GITHUB_SHA} + git rev-parse FETCH_HEAD + git checkout ${GITHUB_SHA} + for i in *; do + cp -rvf $i .. + done + cd .. + echo "::endgroup::" + fi + shell: bash + - name: List Tests + shell: bash + run: | + echo "::group::Top directory" + ls -l tests + echo "::endgroup::" + echo "::group::Files found" + find tests -type f | sort + echo "::endgroup::" + - name: Run Tests + shell: bash + run: | + cd tests + python test_simple.py diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml new file mode 100644 index 00000000..486fe42a --- /dev/null +++ b/.github/workflows/check-style.yml @@ -0,0 +1,63 @@ +# Copyright (C) 2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +# !! WARNING !! +# Do not modify this file directly! +# !! WARNING !! +# +# It is generated from: ../workflows-src/check-style.yml +# using the script from https://github.com/mithro/actions-includes@main + +on: + push: + pull_request: +name: Style +jobs: + Style: + runs-on: ubuntu-20.04 + steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/check-style.yml + - name: 🐍 Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: 3.x + - name: Install latest pip + run: | + pip install -U pip + - name: Install package's system dependencies (Ubuntu) + run: | + sudo apt-get update + sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev + - name: 🧰 Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: true + - name: Install developer tooling's system dependencies (Ubuntu) + run: | + sudo apt-get update + sudo apt-get install -y clang-format + - name: Install development tools + run: | + pip install -r requirements.txt + - name: Check license headers + run: make check-license + - name: Python style check + run: | + make format lint + test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; } + - name: Python script checks + run: make check-python-scripts + - name: C++ style check + run: |- + make format-cpp + test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; } diff --git a/.github/workflows/manylinux-install-cmake.sh b/.github/workflows/manylinux-install-cmake.sh index d78dab9b..1eb98be8 100755 --- a/.github/workflows/manylinux-install-cmake.sh +++ b/.github/workflows/manylinux-install-cmake.sh @@ -9,8 +9,6 @@ yum remove cmake -y # Add in curl yum install wget -y -yum install java-1.8.0-openjdk uuid uuid-devel libuuid libuuid-devel -y - # Download new cmake wget https://github.com/Kitware/CMake/releases/download/v3.19.4/cmake-3.19.4-Linux-x86_64.sh -O /tmp/cmake.sh chmod a+x /tmp/cmake.sh diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml deleted file mode 100644 index aca2f95f..00000000 --- a/.github/workflows/presubmit.yml +++ /dev/null @@ -1,72 +0,0 @@ -# Checks code that code meets requirements for a pull request. -# Any automated checks for code quality and compliance belongs here. -name: presubmit -on: [push, pull_request] -jobs: - check: - name: Source checks - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - with: - # Always clone the full depth so git-describe works. - fetch-depth: 0 - submodules: true - - name: Set up Python - uses: actions/setup-python@v2 - - name: Install dependencies - run: | - sudo apt update - sudo apt install clang-format - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Python style check - run: | - make format lint - test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; } - - name: C++ style check - run: | - make format-cpp - test $(git status --porcelain | wc -l) -eq 0 || { git diff; false; } - - name: Check license - run: make check-license - - name: Python checks - run: make check-python-scripts - test: - name: Test Python package - runs-on: ubuntu-20.04 - strategy: - matrix: - antlr_runtime_type: [static, shared] - python_version: [3.5, 3.6, 3.7, 3.8, 3.9] - include: - - python-version: 3.5 - TOXENV: py35 - - python-version: 3.6 - TOXENV: py36 - - python-version: 3.7 - TOXENV: py37 - - python-version: 3.8 - TOXENV: py38 - - python-version: 3.9 - TOXENV: py39 - fail-fast: false - steps: - - uses: actions/checkout@v2 - with: - # Always clone the full depth so git-describe works. - fetch-depth: 0 - submodules: true - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - sudo apt update - sudo apt install cmake default-jre-headless uuid-dev libantlr4-runtime-dev - python -m pip install --upgrade pip - pip install -r requirements.txt - python update_version.py - - name: Tox - run: ANTLR4_RUNTIME_TYPE=${{ matrix.antlr_runtime_type }} tox -e ${{ matrix.TOXENV }} diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 375f6dc4..1e305602 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,106 +1,165 @@ -name: PyPI +# Copyright (C) 2017-2021 The SymbiFlow Authors. +# +# Use of this source code is governed by a ISC-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/ISC +# +# SPDX-License-Identifier: ISC + +# !! WARNING !! +# Do not modify this file directly! +# !! WARNING !! +# +# It is generated from: ../workflows-src/publish-to-pypi.yml +# using the script from https://github.com/mithro/actions-includes@main on: push: pull_request: workflow_dispatch: - +name: PyPI jobs: - Source: - runs-on: ubuntu-20.04 name: Source - + runs-on: ubuntu-20.04 steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/publish-to-pypi.yml - name: 🧰 Checkout uses: actions/checkout@v2 with: - # Always clone the full depth so git-describe works. fetch-depth: 0 submodules: true - - - name: Install dependencies (Ubuntu) - run: | - sudo apt-get update - sudo apt-get install -y cmake default-jre-headless uuid-dev libantlr4-runtime-dev - - - name: 🐍 Set up Python + - name: 🐍 Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: 3.x - - - name: Install build dependencies + - name: Install latest pip run: | pip install -U pip - pip install -r requirements.txt - python update_version.py - - - name: Install package dependencies + - name: Install packaging tooling run: | - python setup.py install - + pip install twine wheel auditwheel build + - name: Install development tools + run: | + pip install -r requirements.txt - name: 🚧 Build distribution 📦 run: | - python setup.py sdist - - - name: Check distribution 📦 + python -m build --sdist --no-isolation . + - name: ✔︎ Check 📦 + shell: bash run: | - twine check dist/* - + shopt -s nullglob + for SRC in dist/*.zip; do + echo + echo "::group::Checking $SRC" + echo + python -m zipfile --test $SRC + python -m zipfile --list $SRC + echo + twine check $SRC + echo + echo "::endgroup::" + done + for SRC in dist/*.t*gz; do + echo + echo "::group::Checking $SRC" + echo + python -m tarfile --list $SRC + echo + twine check $SRC + echo + echo "::endgroup::" + done + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: source-${{ runner.os }} + path: dist - name: 📤 Publish source to Test PyPI env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }} - if: env.TWINE_PASSWORD != null + if: ${{ env.TWINE_PASSWORD != null }} run: | - twine upload --skip-existing --verbose --repository testpypi dist/*.tar.gz - + twine upload --skip-existing --verbose --repository testpypi dist/* - name: 📤 Publish source to PyPI - if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'SymbiFlow/fasm' + if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && startsWith('SymbiFlow', github.repository) && env.TWINE_PASSWORD != null }} env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | twine upload dist/* - - Linux: + Wheels-Linux: strategy: matrix: - include: - - { name: '3.6', python-version: 'cp36-cp36m' } - - { name: '3.7', python-version: 'cp37-cp37m' } - - { name: '3.8', python-version: 'cp38-cp38' } - - { name: '3.9', python-version: 'cp39-cp39' } + python-version: + - '3.6' + - '3.7' + - '3.8' + - '3.9' fail-fast: false - - name: '${{ matrix.name }} • manylinux' - runs-on: ubuntu-latest - + name: ${{ matrix.python-version }} • manylinux + runs-on: ubuntu-20.04 steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/publish-to-pypi.yml - name: 🧰 Checkout uses: actions/checkout@v2 with: - # Always clone the full depth so git-describe works. fetch-depth: 0 submodules: true - - - name: 🐍 Set up Python - uses: actions/setup-python@v2 - - - name: Install build dependencies + - name: Config Check + if: ${{ !startsWith(runner.os, 'Linux') }} run: | - pip install -U pip - pip install twine auditwheel - python update_version.py - + echo "Use" + echo + echo " SymbiFlow/actions/includes/python/publish-to-pypi-sheels-bin-other" + echo + echo "for Windows / Mac" + echo + exit 1 + - name: Install packaging tooling on runner + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + export PATH=$HOME/.local/bin:$PATH + pip install -U pip twine wheel auditwheel + - name: Check packaging tooling on runner + run: | + echo $PATH + which pip + which twine + which wheel + which auditwheel + - name: Workout manylinux-version + id: manylinux + shell: python + env: + PYTHON_VERSION: ${{ matrix.python-version }} + run: | + import os + MANYLINUX = { + "3.6": "cp36-cp36m", + "3.7": "cp37-cp37m", + "3.8": "cp38-cp38", + "3.9": "cp39-cp39", + }[os.environ['PYTHON_VERSION']] + print("::set-output name=version::"+MANYLINUX) - name: 🚧 Build distribution 📦 uses: RalfG/python-wheels-manylinux-build@v0.3.3-manylinux2010_x86_64 with: - build-requirements: 'cython' - pre-build-command: 'bash .github/workflows/manylinux-install-cmake.sh' - python-versions: ${{ matrix.python-version }} - #pip-wheel-args: '-w ./dist --no-deps --verbose' - + build-requirements: cython + system-packages: java-1.8.0-openjdk uuid uuid-devel libuuid libuuid-devel git + python-versions: ${{ steps.manylinux.outputs.version }} + pre-build-command: bash .github/workflows/manylinux-install-cmake.sh + package-path: '' + pip-wheel-args: -w ./dist --no-deps --verbose - name: List distribution 📦 run: | # Fix permissions @@ -114,104 +173,125 @@ jobs: # Remove the non-manylinux versions rm -v dist/*linux_x86_64*.whl ls -l dist/* - - - name: Check distribution 📦 + - name: ✔︎ Check 📦 + shell: bash run: | for WHEEL in dist/*.whl; do echo echo "::group::Checking $WHEEL" echo - python -m zipfile --list $WHEEL + python -m zipfile -t $WHEEL + python -m zipfile -l $WHEEL echo - auditwheel show $WHEEL + if [ "$(uname)" = "Linux" ]; then + auditwheel show $WHEEL + fi echo twine check $WHEEL echo echo "::endgroup::" done - + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: wheels-${{ runner.os }} + path: dist - name: 📤 Publish wheels to Test PyPI env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }} - if: env.TWINE_PASSWORD != null + if: ${{ env.TWINE_PASSWORD != null }} run: | - twine upload --skip-existing --verbose --repository testpypi dist/*.whl - - - name: 📤 Publish wheels to PyPI - if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'SymbiFlow/fasm' + twine upload --skip-existing --verbose --repository testpypi dist/* + - name: 📤 Publish source to PyPI + if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && startsWith('SymbiFlow', github.repository) && env.TWINE_PASSWORD != null }} env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/*.whl - - MacAndWindows: + twine upload dist/* + Wheels-Other: strategy: matrix: - os: [windows-latest, macos-latest] - python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy-3.6', 'pypy-3.7' ] + os: + - windows-latest + - macos-latest + python-version: + - '3.6' + - '3.7' + - '3.8' + - '3.9' fail-fast: false - name: ${{ matrix.python-version }} • ${{ matrix.os }} runs-on: ${{ matrix.os }} - steps: + - uses: mithro/actions-includes@main + if: runner.os == 'Linux' + continue-on-error: false + with: + workflow: .github/workflows/publish-to-pypi.yml - name: 🧰 Checkout uses: actions/checkout@v2 with: - # Always clone the full depth so git-describe works. fetch-depth: 0 submodules: true - - - name: Install dependencies (Mac OS X) - if: startsWith(matrix.os, 'macos') - run: | - true - - - name: Install dependencies (Windows) - if: startsWith(matrix.os, 'windows') + - name: Config Check + if: ${{ startsWith(runner.os, 'Linux') }} run: | - true - + echo "Use" + echo + echo " SymbiFlow/actions/includes/python/publish-to-pypi-sheels-bin-linux" + echo + echo "for Linux" + echo + exit 1 - name: 🐍 Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - - name: Install build dependencies + - name: Install latest pip run: | pip install -U pip - pip install -r requirements.txt - python update_version.py - - - name: Install package dependencies + - name: Install packaging tooling run: | - python setup.py install - + pip install twine wheel auditwheel build - name: 🚧 Build distribution 📦 run: | - python setup.py bdist_wheel - - - name: Check distribution 📦 + python -m build --wheel . + - name: ✔︎ Check 📦 shell: bash run: | - python -m zipfile -l dist/* - echo - twine check dist/* - + for WHEEL in dist/*.whl; do + echo + echo "::group::Checking $WHEEL" + echo + python -m zipfile -t $WHEEL + python -m zipfile -l $WHEEL + echo + if [ "$(uname)" = "Linux" ]; then + auditwheel show $WHEEL + fi + echo + twine check $WHEEL + echo + echo "::endgroup::" + done + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: wheels-${{ runner.os }} + path: dist - name: 📤 Publish wheels to Test PyPI env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }} - if: env.TWINE_PASSWORD != null + if: ${{ env.TWINE_PASSWORD != null }} run: | - twine upload --skip-existing --verbose --repository testpypi dist/*.whl - - - name: 📤 Publish wheels to PyPI - if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'SymbiFlow/fasm' + twine upload --skip-existing --verbose --repository testpypi dist/* + - name: 📤 Publish source to PyPI + if: ${{ github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && startsWith('SymbiFlow', github.repository) && env.TWINE_PASSWORD != null }} env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - twine upload dist/*.whl + twine upload dist/* diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml deleted file mode 100644 index 6392bd62..00000000 --- a/.github/workflows/wheel.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Builds a binary distibutable package. -# Minimal functionality checks may be run as part of the build process, but -# source code checks and extensive functionality checks (e.g. tox) belong in presubmit.yml -name: Python wheels -on: [push, pull_request] -jobs: - wheels: - runs-on: ubuntu-20.04 - strategy: - matrix: - python-version: [3.5, 3.6, 3.7, 3.8, 3.9] - fail-fast: false - steps: - - uses: actions/checkout@v2 - with: - # Always clone the full depth so git-describe works. - fetch-depth: 0 - submodules: true - - name: Install dependencies - run: | - sudo apt update - sudo apt install cmake default-jre-headless uuid-dev libantlr4-runtime-dev - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: python -m pip install --upgrade -r requirements.txt - - name: Generate version - run: python update_version.py - - name: Build wheels - run: python setup.py bdist_wheel - - name: Test wheel installation - run: | - python -m pip install dist/*.whl - (cd tests; python test_simple.py) - - uses: actions/upload-artifact@v2 - with: - name: fasm - path: dist diff --git a/MANIFEST.in b/MANIFEST.in index 42e8397b..272ac0b2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -33,17 +33,20 @@ prune docs/env # textx based parser recursive-include fasm/parser *.tx -recursive-include fasm/parser *.pyx -exclude fasm/parser/*.c # antlr based parser include src/* include src/antlr/* +# cython extension to antlr based parser +recursive-include fasm/parser *.pyx # Excludes -global-exclude .git exclude .gitmodules exclude update_version.py prune third_party prune .github -prune __pycache__ +prune */.git +prune */__pycache__ +global-exclude *.py[cod] +global-exclude *.o +global-exclude *.so diff --git a/Makefile b/Makefile index a5116601..0464a064 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,11 @@ setup.py: fasm/version.py # Build/install into the conda environment. # ------------------------------------------------------------------------ build-clean: - rm -rf dist fasm.egg-info + rm -rf build dist fasm.egg-info + rm -f fasm/parser/antlr_to_tuple.c + rm -f fasm/parser/*.so + +clean:: build-clean .PHONY: build-clean @@ -51,6 +55,13 @@ install: setup.py | $(CONDA_ENV_PYTHON) .PHONY: install +# Info about the environment +info: + @make --no-print-directory env-info + @echo + @$(IN_CONDA_ENV) python -W ignore .github/actions/download-and-run-tests/fasm-version.py + +.PHONY: info # Build/install locally rather than inside the environment. # ------------------------------------------------------------------------ @@ -79,6 +90,11 @@ test: fasm/version.py | $(CONDA_ENV_PYTHON) .PHONY: test +tests: test + @true + +.PHONY: tests + # Find files to apply tools to while ignoring files. define with_files $(IN_CONDA_ENV) git ls-files | grep -ve '^third_party\|^\.|^env' | grep -e $(1) | xargs -r -P $$(nproc) $(2) @@ -111,6 +127,17 @@ format-cpp: .PHONY: format-cpp +# Format the GitHub workflow files +GHA_WORKFLOW_SRCS = $(wildcard .github/workflows-src/*.yml) +GHA_WORKFLOW_OUTS = $(addprefix .github/workflows/,$(notdir $(GHA_WORKFLOW_SRCS))) + +.github/workflows/%.yml: .github/workflows-src/%.yml $(CONDA_ENV_PYTHON) + $(IN_CONDA_ENV) python -m actions_includes $< $@ + +format-gha: $(GHA_WORKFLOW_OUTS) + echo $(GHA_WORKFLOW_OUTS) + @true + # Format all the files! format: format-py format-cpp true diff --git a/fasm/parser/antlr_to_tuple.pyx b/fasm/parser/antlr_to_tuple.pyx index c57c6053..16bba284 100644 --- a/fasm/parser/antlr_to_tuple.pyx +++ b/fasm/parser/antlr_to_tuple.pyx @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +# cython: language_level=3 # -*- coding: utf-8 -*- # # Copyright (C) 2020 The SymbiFlow Authors. diff --git a/fasm/version.py b/fasm/version.py deleted file mode 100644 index 0406adc4..00000000 --- a/fasm/version.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (C) 2017-2020 The SymbiFlow Authors. -# -# Use of this source code is governed by a ISC-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/ISC -# -# SPDX-License-Identifier: ISC - -# ** WARNING ** -# This file is auto-generated by the update_version.py script. -# ** WARNING ** - -version_str = "0.0.2.post66" -version_tuple = (0, 0, 2, 66) -try: - from packaging.version import Version as V - pversion = V("0.0.2.post66") -except ImportError: - pass - -git_hash = "c0b734e6d373fcffd0522acdd102814bcefb626a" -git_describe = "v0.0.2-66-gc0b734e" -git_msg = """\ -commit c0b734e6d373fcffd0522acdd102814bcefb626a -Author: Tim 'mithro' Ansell -Date: Fri Feb 19 13:05:20 2021 -0800 - - Improve the warning message when falling back to the textX. - - Signed-off-by: Tim 'mithro' Ansell - -""" diff --git a/pyproject.toml b/pyproject.toml index e9f294dd..89738e7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,9 @@ [build-system] -requires = ["setuptools", "wheel", "cython"] +# WARNING: This needs to be kept in sync with the setup_requires in setup.py +# WARNING: This needs to be kept in sync with requirements.txt +requires = [ + "cython", + "setuptools>=42", + "wheel", +] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index e3a9915f..a238cc05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,15 @@ -check-manifest +# Get fasm tooling requirements +-e . +# WARNING: Must be kept in sync with pyproject.toml cython +setuptools>=42 +wheel +# Testing +check-manifest flake8 pytest -textx tox twine -wheel yapf==0.24.0 +# CI expansion +git+https://github.com/mithro/actions-includes.git#egg=actions-includes diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 33aea034..00000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[metadata] -license_files = LICENSE - -[bdist_wheel] -universal=1 diff --git a/setup.py b/setup.py index 784b8ad4..cbbefa04 100644 --- a/setup.py +++ b/setup.py @@ -17,13 +17,13 @@ import sys import traceback -from Cython.Build import cythonize from distutils.command.build import build from distutils.version import LooseVersion from setuptools import Extension from setuptools.command.build_ext import build_ext from setuptools.command.develop import develop from setuptools.command.install import install +from setuptools.command.sdist import sdist __dir__ = os.path.dirname(os.path.abspath(__file__)) @@ -33,12 +33,8 @@ # Read in the version information FASM_VERSION_FILE = os.path.join(__dir__, 'fasm', 'version.py') -with open(FASM_VERSION_FILE) as f: - if 'UNKNOWN' in f.read(): - print( - "Running update_version.py to generate {}".format( - FASM_VERSION_FILE)) - subprocess.check_call(['python', 'update_version.py'], cwd=__dir__) +if not os.path.exists(FASM_VERSION_FILE): + subprocess.check_call([sys.executable, 'update_version.py'], cwd=__dir__) with open(FASM_VERSION_FILE) as f: lines = f.readlines() version_line = [v.strip() for v in lines if v.startswith('version_str')] @@ -49,8 +45,16 @@ version = version_value[1:-1] +# C extensions +extensions = [] +cmdclass = {} + +# Antlr based parser +# ------------------------------------------------------------------------ # Based on: https://www.benjack.io/2018/02/02/python-cpp-revisited.html # GitHub: https://github.com/benjaminjack/python_cpp_example + + class CMakeExtension(Extension): def __init__(self, name, sourcedir='', prefix=''): Extension.__init__(self, name, sources=[]) @@ -252,7 +256,50 @@ def run(self): super().run() +extensions += [ + CMakeExtension('parse_fasm', sourcedir='src', prefix='fasm/parser'), +] +cmdclass['build_ext'] = AntlrCMakeBuild +cmdclass['build'] = BuildCommand +cmdclass['develop'] = DevelopCommand +cmdclass['install'] = InstallCommand +# ------------------------------------------------------------------------ + +# Cython based accelerator +# ------------------------------------------------------------------------ +# Cython recommends shipping the .c file as part of your sdist package. + + +class SdistCommand(sdist): + def run(self): + from Cython.Build import cythonize + cythonize("fasm/parser/antlr_to_tuple.pyx") + super().run() + + +CYTHON_EXT_FILEBASE = 'fasm/parser/antlr_to_tuple' +if os.path.exists(CYTHON_EXT_FILEBASE + '.c'): + # Building from sdist which already includes the generated + # `antlr_to_tuple.c` file, so can treat it like any other C extensions. + extensions += [ + Extension( + "fasm.parser.antlr_to_tuple", [CYTHON_EXT_FILEBASE + '.c']), + ] +else: + # Building without a `antlr_to_tuple.c` file, so need to use Cython to + # generate the new `antlr_to_tuple.c` file from the `antlr_to_tuple.pyx`. + from Cython.Build import cythonize + extensions += [ + Extension( + "fasm.parser.antlr_to_tuple", [CYTHON_EXT_FILEBASE + '.pyx']), + ] + extensions = cythonize(extensions) + cmdclass['sdist'] = SdistCommand +# ------------------------------------------------------------------------ + + setuptools.setup( + # Package human readable information name="fasm", version=version, author="SymbiFlow Authors", @@ -261,24 +308,30 @@ def run(self): long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/SymbiFlow/fasm", - packages=setuptools.find_packages(exclude=('tests*', )), - install_requires=['textx'], - include_package_data=True, + license="ISC", + license_files=["LICENSE"], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: ISC License (ISCL)", "Operating System :: OS Independent", ], + # Package contents control + packages=setuptools.find_packages(exclude=['tests*']), + include_package_data=True, entry_points={ 'console_scripts': ['fasm=fasm.tool:main'], }, - ext_modules=[ - CMakeExtension('parse_fasm', sourcedir='src', prefix='fasm/parser') - ] + cythonize("fasm/parser/antlr_to_tuple.pyx"), - cmdclass={ - 'build_ext': AntlrCMakeBuild, - 'build': BuildCommand, - 'develop': DevelopCommand, - 'install': InstallCommand, - }, + # Requirements + python_requires=">=3.6", + setup_requires=[ # WARNING: Must be kept in sync with pyproject.toml + "cython", + "setuptools>=42", + "wheel", + ], + install_requires=[ + 'textx', + ], + # C extension building + ext_modules=extensions, + cmdclass=cmdclass, )