name: Build Conan dependencies
description: "Install Conan dependencies, optionally forcing a rebuild of all dependencies."

# Note that actions do not support 'type' and all inputs are strings, see
# https://docs.github.com/en/actions/reference/workflows-and-actions/metadata-syntax#inputs.
inputs:
  build_dir:
    description: "The directory where to build."
    required: true
  build_type:
    description: 'The build type to use ("Debug", "Release").'
    required: true
  build_nproc:
    description: "The number of processors to use for building."
    required: true
  force_build:
    description: 'Force building of all dependencies ("true", "false").'
    required: false
    default: "false"
  log_verbosity:
    description: "The logging verbosity."
    required: false
    default: "verbose"

runs:
  using: composite
  steps:
    - name: Install Conan dependencies
      shell: bash
      env:
        BUILD_DIR: ${{ inputs.build_dir }}
        BUILD_NPROC: ${{ inputs.build_nproc }}
        BUILD_OPTION: ${{ inputs.force_build == 'true' && '*' || 'missing' }}
        BUILD_TYPE: ${{ inputs.build_type }}
        LOG_VERBOSITY: ${{ inputs.log_verbosity }}
      run: |
        echo 'Installing dependencies.'
        mkdir -p "${BUILD_DIR}"
        cd "${BUILD_DIR}"
        conan install \
          --output-folder . \
          --build="${BUILD_OPTION}" \
          --options:host='&:tests=True' \
          --options:host='&:xrpld=True' \
          --settings:all build_type="${BUILD_TYPE}" \
          --conf:all tools.build:jobs=${BUILD_NPROC} \
          --conf:all tools.build:verbosity="${LOG_VERBOSITY}" \
          --conf:all tools.compilation:verbosity="${LOG_VERBOSITY}" \
          ..
