# This file list source dependencies to avoid creating/running jobs
# those outcome cannot be changed by the modifications from a branch.

# Generic rule to not run the job during scheduled pipelines
# ----------------------------------------------------------
.scheduled_pipelines-rules:
  rules: &ignore_scheduled_pipelines
    if: '$CI_PIPELINE_SOURCE == "schedule"'
    when: never

# Mesa core source file dependencies
# ----------------------------------
.mesa-rules:
  rules:
    - *ignore_scheduled_pipelines
    - changes: &mesa_core_file_list
      - .gitlab-ci.yml
      - .gitlab-ci/**/*
      - include/**/*
      - meson.build
      - src/*
      - src/compiler/**/*
      - src/drm-shim/**/*
      - src/egl/**/*
      - src/gbm/**/*
      - src/glx/**/*
      - src/gtest/**/*
      - src/hgl/**/*
      - src/include/**/*
      - src/loader/**/*
      - src/mapi/**/*
      - src/mesa/*
      - src/mesa/drivers/*
      - src/mesa/drivers/common/**/*
      - src/mesa/drivers/dri/*
      - src/mesa/drivers/dri/common/**/*
      - src/mesa/main/**/*
      - src/mesa/math/**/*
      - src/mesa/program/**/*
      - src/mesa/sparc/**/*
      - src/mesa/state_tracker/**/*
      - src/mesa/swrast/**/*
      - src/mesa/swrast_setup/**/*
      - src/mesa/tnl/**/*
      - src/mesa/tnl_dd/**/*
      - src/mesa/vbo/**/*
      - src/mesa/x86/**/*
      - src/mesa/x86-64/**/*
      - src/util/**/*

.vulkan-rules:
  rules:
    - *ignore_scheduled_pipelines
    - changes: &vulkan_file_list
      - src/vulkan/**/*
      when: on_success
    - when: never

# Gallium core source file dependencies
# -------------------------------------
.gallium-rules:
  rules:
    - *ignore_scheduled_pipelines
    - changes: &gallium_core_file_list
      - src/gallium/*
      - src/gallium/auxiliary/**/*
      - src/gallium/drivers/*
      - src/gallium/include/**/*
      - src/gallium/frontends/dri/*
      - src/gallium/frontends/glx/**/*
      - src/gallium/targets/**/*
      - src/gallium/tests/**/*
      - src/gallium/winsys/*

.softpipe-rules:
  stage: software-renderer
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes: &softpipe_file_list
      - src/gallium/drivers/softpipe/**/*
      - src/gallium/winsys/sw/**/*
      when: on_success
    - when: never

.llvmpipe-rules:
  stage: software-renderer
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes: &llvmpipe_file_list
      - src/gallium/drivers/llvmpipe/**/*
      - src/gallium/winsys/sw/**/*
      when: on_success
    - when: never

.lavapipe-rules:
  stage: software-renderer
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes: &lavapipe_file_list
      - src/gallium/drivers/llvmpipe/**/*
      - src/gallium/frontends/lavapipe/**/*
      - src/gallium/winsys/sw/**/*
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - when: never

.llvmpipe-cl-rules:
  stage: software-renderer
  rules:
    - *ignore_scheduled_pipelines
    - changes:
      - .gitlab-ci.yml
      - .gitlab-ci/**/*
      - meson.build
      - include/**/*
      - src/compiler/**/*
      - src/include/**/*
      - src/util/**/*
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *llvmpipe_file_list
      when: on_success
    - changes: &clover_file_list
      - src/gallium/frontends/clover/**/*
      when: on_success
    - when: never

.freedreno-rules:
  stage: freedreno
  rules:
    - if: '$FD_FARM == "offline"'
      when: never
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes: &freedreno_file_list
      # Note: when https://gitlab.com/gitlab-org/gitlab/-/issues/198688
      # is supported, we can change the src/freedreno/ rule to explicitly
      # exclude tools
      - src/freedreno/**/*
      - src/gallium/drivers/freedreno/**/*
      - src/gallium/winsys/freedreno/**/*
      when: on_success
    - when: never

# Unfortunately YAML doesn't let us concatenate arrays, so we have to do the
# rules duplication manually
.freedreno-rules-restricted:
  stage: freedreno
  rules:
    - if: '$FD_FARM == "offline"'
      when: never
    # If the triggerer has access to the restricted traces and if it is pre-merge
    - if: '($GITLAB_USER_LOGIN !~ "/^(robclark|anholt|flto|cwabbott0|Danil|tomeu)$/") &&
           ($GITLAB_USER_LOGIN != "marge-bot" || $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != $CI_COMMIT_REF_NAME)'
      when: never
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes:
        *freedreno_file_list
      when: on_success
    - when: never

# Unfortunately YAML doesn't let us concatenate arrays, so we have to do the
# rules duplication manually
.freedreno-rules-performance:
  stage: freedreno
  rules:
    - if: '$FD_FARM == "offline"'
      when: never
    - *ignore_scheduled_pipelines
    # Run only on pre-merge pipelines from Marge
    - if: '$GITLAB_USER_LOGIN != "marge-bot" || $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != $CI_COMMIT_REF_NAME'
      when: never
    - changes:
        *mesa_core_file_list
      when: manual
    - changes:
        *gallium_core_file_list
      when: manual
    - changes:
        *vulkan_file_list
      when: manual
    - changes:
        *freedreno_file_list
      when: manual
    - when: never

.panfrost-midgard-rules:
  stage: arm
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes: &panfrost_gallium_file_list
      - src/gallium/drivers/panfrost/**/*
      - src/gallium/winsys/panfrost/**/*
      when: on_success
    - changes: &panfrost_common_file_list
      - src/panfrost/ci/*
      - src/panfrost/include/*
      - src/panfrost/lib/*
      - src/panfrost/shared/*
      - src/panfrost/util/*
      when: on_success
    - changes:
      - src/panfrost/midgard/**/*
      when: on_success
    - when: never

.panfrost-bifrost-rules:
  stage: arm
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *panfrost_common_file_list
      when: on_success
    - changes:
        *panfrost_gallium_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes: &panfrost_vulkan_file_list
      - src/panfrost/vulkan/*
      when: on_success
    - changes:
      - src/panfrost/bifrost/**/*
      when: on_success
    - when: never

.vc4-rules:
  stage: broadcom
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
      - src/broadcom/**/*
      - src/gallium/drivers/vc4/**/*
      - src/gallium/winsys/kmsro/**/*
      - src/gallium/winsys/vc4/**/*
      when: on_success
    - when: never

.v3d-rules:
  stage: broadcom
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
      - src/broadcom/**/*
      - src/gallium/drivers/v3d/**/*
      - src/gallium/winsys/kmsro/**/*
      - src/gallium/winsys/v3d/**/*
      when: on_success
    - when: never

.v3dv-rules:
  stage: broadcom
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes:
      - src/broadcom/**/*
      when: on_success
    - when: never

.lima-rules:
  stage: arm
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
      - src/gallium/drivers/lima/**/*
      - src/gallium/winsys/lima/**/*
      - src/lima/**/*
      when: on_success
    - when: never

.radv-rules:
  stage: amd
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes: &radv_file_list
      - src/amd/**/*
      - src/vulkan/**/*
      when: on_success
    - when: never

.virgl-rules:
  stage: layered-backends
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *llvmpipe_file_list
      when: on_success
    - changes: &virgl_file_list
      - src/gallium/drivers/virgl/**/*
      - src/gallium/winsys/virgl/**/*
      when: on_success
    - when: never

.radeonsi-rules:
  stage: amd
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes: &radeonsi_file_list
      - src/gallium/drivers/radeonsi/**/*
      - src/gallium/winsys/amdgpu/**/*
      - src/amd/*
      - src/amd/addrlib/**/*
      - src/amd/common/**/*
      - src/amd/llvm/**/*
      - src/amd/registers/**/*
      when: on_success
    - when: never

.radeonsi-vaapi-rules:
  stage: amd
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *radeonsi_file_list
      when: on_success
    - changes: &radeon_vcn_file_list
      - src/gallium/frontends/va/**/*
      - src/gallium/drivers/radeon/**/*
      when: on_success
    - when: never

.i915g-rules:
  stage: intel
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
      - src/gallium/drivers/i915/**/*
      - src/gallium/winsys/i915/**/*
      - src/intel/**/*
      when: on_success
    - when: never

.iris-rules:
  stage: intel
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes: &iris_file_list
      - src/gallium/drivers/iris/**/*
      - src/gallium/winsys/iris/**/*
      - src/intel/**/*
      when: on_success
    - when: never

# Unfortunately YAML doesn't let us concatenate arrays, so we have to do the
# rules duplication manually
.iris-rules-performance:
  stage: intel
  rules:
    - *ignore_scheduled_pipelines
    # Run only on pre-merge pipelines from Marge
    - if: '$GITLAB_USER_LOGIN != "marge-bot" || $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != $CI_COMMIT_REF_NAME'
      when: never
    - changes:
        *mesa_core_file_list
      when: manual
    - changes:
        *gallium_core_file_list
      when: manual
    - changes:
        *iris_file_list
      when: manual
    - when: never

.anv-rules:
  stage: intel
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes:
      - src/intel/**/*
      when: on_success
    - when: never

.zink-rules:
  stage: layered-backends
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *lavapipe_file_list
      when: on_success
    - changes: &zink_file_list
      - src/gallium/drivers/zink/**/*
      when: on_success
    - when: never

# Unfortunately YAML doesn't let us concatenate arrays, so we have to do the
# rules duplication manually
.windows-build-rules:
  rules:
    - *ignore_scheduled_pipelines
    - changes: 
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *lavapipe_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes: &d3d12_file_list
      - src/gallium/drivers/d3d12/**/*
      - src/microsoft/**/*
      - src/gallium/frontends/wgl/*
      - src/gallium/winsys/d3d12/wgl/*
      - src/gallium/targets/libgl-gdi/*
      - src/gallium/targets/libgl-d3d12/*
      when: on_success
    - changes:
        *zink_file_list
      when: on_success
    - changes:
        *radv_file_list
      when: on_success
    - when: never

.windows-test-rules:
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *lavapipe_file_list
      when: on_success
    - changes:
        *vulkan_file_list
      when: on_success
    - changes: *d3d12_file_list
      when: on_success
    - when: never

.etnaviv-rules:
  stage: etnaviv
  rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
      - src/etnaviv/**/*
      - src/gallium/drivers/etnaviv/**/*
      - src/gallium/winsys/etnaviv/**/*
      - src/gallium/auxiliary/renderonly/**/*
      - src/gallium/winsys/kmsro/**/*
      - src/gallium/winsys/etnaviv/**/*
      when: on_success
    - when: never

# Rules for unusual architectures that only build a subset of drivers
.ppc64el-rules:
   rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *softpipe_file_list
      when: on_success
    - changes:
        *llvmpipe_file_list
      when: on_success
    - changes:
        *lavapipe_file_list
      when: on_success
    - changes:
        *radv_file_list
      when: on_success
    - changes:
        *radeonsi_file_list
      when: on_success
    - changes:
        *zink_file_list
      when: on_success
    - changes:
        *virgl_file_list
      when: on_success
    - changes:
      - src/gallium/drivers/nouveau/**/*
      - src/gallium/winsys/nouveau/**/*
      when: on_success
    - when: never

.s390x-rules:
   rules:
    - *ignore_scheduled_pipelines
    - changes:
        *mesa_core_file_list
      when: on_success
    - changes:
        *gallium_core_file_list
      when: on_success
    - changes:
        *softpipe_file_list
      when: on_success
    - changes:
        *llvmpipe_file_list
      when: on_success
    - changes:
        *lavapipe_file_list
      when: on_success
    - changes:
        *zink_file_list
      when: on_success
    - when: never
