From 893679f07f8366cab23d53e36b06f7d822060acc Mon Sep 17 00:00:00 2001
From: Zygmunt Krynicki <zygmunt.krynicki@huawei.com>
Date: Mon, 22 Feb 2021 13:19:46 +0100
Subject: [PATCH] Check out git branch before initializing bitbake

Stefan observed that CI job initializes bitbake with layer configuration
from the layer as checked out by git-repo, and only then switches to the
branch being tested.

This resulted in bitbake incorrectly failing to notice a layer that was
added by the tested patch.

The solution is to move all of the bitbake initialization stage from the
.build jobs "script_before" section, to the "script" section. In effect
any derivative job can use "script_before" to freely alter the source
tree before bitbake is initialized. Due to the lucky arrangement of YAML
anchors, the .build job's "script" keeps running with bitbake
environment sourced, so it can do exactly what one would expect - build
the desired recipe.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@huawei.com>
---
 .ostc-ci/gitlab-ci.yml | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/.ostc-ci/gitlab-ci.yml b/.ostc-ci/gitlab-ci.yml
index e403c544..64567d88 100644
--- a/.ostc-ci/gitlab-ci.yml
+++ b/.ostc-ci/gitlab-ci.yml
@@ -84,6 +84,11 @@ stages:
     # the manifest file.
     - test -d "$SCRATCH_DIR"/workspace/sources || ( echo "assumption violated - expected the workspace to contain the sources directory" && ls "$SCRATCH_DIR"/workspace && exit 1 )
 
+  script: &workspace-do
+    # Reload the value of SCRATCH_DIR set in the before_script phase. Those run
+    # in separate shell processes and do not share environment variables.
+    - SCRATCH_DIR="$(cat "$CI_PROJECT_DIR"/.scratch-dir-name)"
+
     # Initialize bitbake build environment by sourcing the oe-init-build-env
     # into the running bash process. This has the side-effect of changing the
     # current working directory and populating the $SCRATCH_DIR/workspace/build
@@ -105,10 +110,6 @@ stages:
     # Collect stats just before the build.
     - du -sh "$SCRATCH_DIR"/workspace/build/*
 
-  script: &workspace-do
-    # Reload the value of SCRATCH_DIR set in the before_script phase. Those run
-    # in separate shell processes and do not share environment variables.
-    - SCRATCH_DIR="$(cat "$CI_PROJECT_DIR"/.scratch-dir-name)"
     - cd "$SCRATCH_DIR"/workspace && . ./sources/poky/oe-init-build-env build
     # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
     # NOTE: From now on, we are running inside "$SCRATCH_DIR"/workspace/build
-- 
GitLab