From dc6c8ae38c8224c135bdf15912e2f5fcf9e6f6a4 Mon Sep 17 00:00:00 2001
From: Davide Gardenal <davide.gardenal@huawei.com>
Date: Thu, 21 Jul 2022 16:07:33 +0200
Subject: [PATCH] .oniro-ci: add new Linux hidden job definition

build-linux-image, build-linux-oniro-image-base and
build-linux-oniro-image-tests are new linux hidden jobs that defines
the flavor to be Linux and set the recipe to build to oniro-image-base
and oniro-image-base-tests respectively.

linux-qemu-x86 and linux-seco-imx8mm-c61-2gb extends them. This is
the first iteration and in later commits all the jobs will be
migrated to the new structure.

This is giving us a more precise control over the artifacts upload,
especially with the gcc and clang split.

This commit is not breaking any of the jobs that are not using the
new definition.

Signed-off-by: Davide Gardenal <davide.gardenal@huawei.com>
---
 .oniro-ci/build-generic.yaml         | 26 +++++++++++++++++++++++---
 .oniro-ci/machines-and-flavours.yaml | 13 ++++++-------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/.oniro-ci/build-generic.yaml b/.oniro-ci/build-generic.yaml
index 2190c7d2..36b41bab 100644
--- a/.oniro-ci/build-generic.yaml
+++ b/.oniro-ci/build-generic.yaml
@@ -258,7 +258,8 @@
 .build-image:
   extends: .build-recipe
   variables:
-    CI_ONIRO_JOB_ARTIFACTS: ""
+    CI_ONIRO_JOB_ARTIFACTS: "*.wic.* *.bmap ovmf.qcow2"
+    CI_ONIRO_STORE_IMAGE_ARTIFACT: 0
   script:
     - !reference [.build-recipe, script]
     # Move artifacts for recovery, which only considers $CI_PROJECT_DIR and
@@ -276,11 +277,12 @@
     # build and boot.
     - find "$BITBAKE_DEPLOY_DIR"/images/ -name *.wic -exec rm -rf {} \;
     - cp -a "$BITBAKE_DEPLOY_DIR"/licenses/ "$CI_PROJECT_DIR"/artifacts || true
-    # Only copy the files defined in the CI_ONIRO_JOB_ARTIFACTS variable. Most
+    # If CI_ONIRO_STORE_IMAGE_ARTIFACT is 1 copy the files defined in the CI_ONIRO_JOB_ARTIFACTS variable. Most
     # of the remaining files are redundant and quite large.
+    - if test "$CI_ONIRO_STORE_IMAGE_ARTIFACT" != "1"; then (echo "CI_ONIRO_STORE_IMAGE_ARTIFACT is not set, artifacts will not be saved!") fi
     - |
       set -x
-      if test -n "$CI_ONIRO_JOB_ARTIFACTS" && test -d "$BITBAKE_DEPLOY_DIR"; then
+      if test -n "$CI_ONIRO_JOB_ARTIFACTS" && test -d "$BITBAKE_DEPLOY_DIR" && test "$CI_ONIRO_STORE_IMAGE_ARTIFACT" = "1"; then
         (
           cd "$BITBAKE_DEPLOY_DIR"
           for artifact in $CI_ONIRO_JOB_ARTIFACTS; do
@@ -302,9 +304,27 @@
   variables:
     CI_ONIRO_BB_LOCAL_CONF_plus_equals_INHERIT: create-spdx
     CI_ONIRO_JOB_ARTIFACTS: "*.wic.* *.bmap"
+    CI_ONIRO_STORE_IMAGE_ARTIFACT: 1
   script:
     - !reference [.build-image, script]
 
+.build-linux-image:
+  extends: .build-image
+  variables:
+    CI_ONIRO_BUILD_FLAVOUR: linux
+    CI_ONIRO_BB_LOCAL_CONF_plus_equals_INHERIT: rm_work
+    CI_ONIRO_BB_LOCAL_CONF_plus_equals_INHERIT: create-spdx
+
+.build-linux-oniro-image-base:
+  extends: .build-linux-image
+  variables:
+    CI_ONIRO_RECIPE_NAME: oniro-image-base
+
+.build-linux-oniro-image-tests:
+  extends: .build-linux-image
+  variables:
+    CI_ONIRO_RECIPE_NAME: oniro-image-base-tests
+
 .build-rauc-bundle:
   extends: .build-image
   variables:
diff --git a/.oniro-ci/machines-and-flavours.yaml b/.oniro-ci/machines-and-flavours.yaml
index db1dcbf7..2205a0f4 100644
--- a/.oniro-ci/machines-and-flavours.yaml
+++ b/.oniro-ci/machines-and-flavours.yaml
@@ -32,23 +32,22 @@
       allow_failure: true
 
 .linux-qemu-x86:
-  extends: [.build-wic-image, .check-abi]
+  extends: [.build-linux-oniro-image-tests, .check-abi]
   variables:
     MACHINE: qemux86
-    CI_ONIRO_BUILD_FLAVOUR: linux
-    CI_ONIRO_RECIPE_NAME: oniro-image-base-tests
     # Set CI_ONIRO_BUILD_CACHE to "pub", overriding the value defined in the
     # .build job. This enables sharing of download and sstate-cache created
     # during this job.
     #
     # This is done assuming that there are no non-redistributable or otherwise
     # tainted build intermediate files, downloads or published artifacts.
-    CI_ONIRO_BB_LOCAL_CONF_BB_GENERATE_MIRROR_TARBALLS: 1
-    CI_ONIRO_JOB_ARTIFACTS: "*.wic.* *.bmap ovmf.qcow2"
+    CI_ONIRO_BUILD_CACHE: "pub"
 linux-qemu-x86-gcc:
- extends: [.linux-qemu-x86, .toolchain-gcc]
+  extends: [.linux-qemu-x86, .toolchain-gcc]
+  variables:
+    CI_ONIRO_STORE_IMAGE_ARTIFACT: 1 # artifacts used by lava-qemu-x86
 linux-qemu-x86-clang:
- extends: [.linux-qemu-x86, .toolchain-clang]
+  extends: [.linux-qemu-x86, .toolchain-clang]
 
 .linux-qemu-x86_64:
   extends: [.build-wic-image, .check-abi]
-- 
GitLab