<commit_before>#!/bin/bash
#
# Common functions for other scripts.

RED='\e[91m'
BLD='\e[1m'
BLD_RED='\e[1;91m'
RST='\e[0m'

function error {
	msg="$1"
	echo -e "${BLD_RED}ERROR${RST}${RED}: ${msg}${RST}"
}

function note {
	msg="$1"
	echo -e "${BLD}NOTE${RST}: ${msg}"
}

# If variable is already defined, replace it
# else define it.
# Params:
#   $1: variable which will be updated. Eg: IMAGE_INSTALL_append
#   $2: value which will be set. Eg: " bzip2 zlib"
#   $3: config file which will be modified. Eg: conf/local.conf
function add_or_replace {
	key="$1"
	val="$2"
	file="$3"

	if grep -q "^$key\s*?*=" $file 2> /dev/null; then
		sed -i -e "s#\(^$key\s*?*=\).*#\1 \"$val\"#" $file
	else
		echo "$key = \"$val\"" >> $file
	fi
}

# Set up a build directory.
# No params.
function setup_builddir {
	note "Setup build directory."
	cd $WORKDIR
	rm -rf build/conf
	export TEMPLATECONF=meta-debian/conf
	source ./poky/oe-init-build-env
	add_or_replace "HOSTTOOLS_append" " gitproxy" conf/local.conf

	# Configurations for u-boot
	add_or_replace "UBOOT_MACHINE_qemux86" "qemu-x86_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemux86-64" "qemu-x86_64_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemumips" "qemu_mips_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemuppc" "qemu-ppce500_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemuarm" "qemu_arm_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemuarm64" "qemu_arm64_defconfig" conf/local.conf<commit_msg>tests/common.sh: Check if gitproxy exists before add to HOSTTOOLS<commit_after>#!/bin/bash
#
# Common functions for other scripts.

RED='\e[91m'
BLD='\e[1m'
BLD_RED='\e[1;91m'
RST='\e[0m'

function error {
	msg="$1"
	echo -e "${BLD_RED}ERROR${RST}${RED}: ${msg}${RST}"
}

function note {
	msg="$1"
	echo -e "${BLD}NOTE${RST}: ${msg}"
}

# If variable is already defined, replace it
# else define it.
# Params:
#   $1: variable which will be updated. Eg: IMAGE_INSTALL_append
#   $2: value which will be set. Eg: " bzip2 zlib"
#   $3: config file which will be modified. Eg: conf/local.conf
function add_or_replace {
	key="$1"
	val="$2"
	file="$3"

	if grep -q "^$key\s*?*=" $file 2> /dev/null; then
		sed -i -e "s#\(^$key\s*?*=\).*#\1 \"$val\"#" $file
	else
		echo "$key = \"$val\"" >> $file
	fi
}

# Set up a build directory.
# No params.
function setup_builddir {
	note "Setup build directory."
	cd $WORKDIR
	rm -rf build/conf
	export TEMPLATECONF=meta-debian/conf
	source ./poky/oe-init-build-env

	if which gitproxy &> /dev/null; then
		add_or_replace "HOSTTOOLS_append" " gitproxy" conf/local.conf
	fi

	# Configurations for u-boot
	add_or_replace "UBOOT_MACHINE_qemux86" "qemu-x86_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemux86-64" "qemu-x86_64_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemumips" "qemu_mips_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemuppc" "qemu-ppce500_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemuarm" "qemu_arm_defconfig" conf/local.conf
	add_or_replace "UBOOT_MACHINE_qemuarm64" "qemu_arm64_defconfig" conf/local.conf
{'fraction_non_alphanumeric': 0.1532567049808429, 'fraction_numerical': 0.02362707535121328, 'mean_word_length': 4.717153284671533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6838268', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1330, 'n_words': 291}