<commit_before>#!/bin/bash

set -xe

if [ -z "$LEGATO_ROOT" ]; then
    echo "LEGATO_ROOT not set"
    exit 1
fi

. "$LEGATO_ROOT/framework/tools/scripts/shlib"

SCRIPT_PATH="$( cd `dirname "$0"` && pwd )/`basename $0`"
if [ -L "$SCRIPT_PATH" ]; then
    SCRIPT_PATH=$(readlink $SCRIPT_PATH)
fi

VIRT_TARGET_ARCH=${VIRT_TARGET_ARCH:-x86}

## Create build directory

if [ -z "$BUILD_DIR" ]; then
    BUILD_DIR="$LEGATO_ROOT/build/virt-${VIRT_TARGET_ARCH}/docker"
fi

mkdir -p $BUILD_DIR

## Prepare files to be packaged in Docker image

# Configuration Script
cp "$LEGATO_ROOT/framework/tools/scripts/legato-qemu" "$BUILD_DIR"

# Download Legato image & Linux image
if [ -z "$SKIP_DOWNLOAD" ]; then
    export USER_DIR="$BUILD_DIR"

    # Use ONLY_PREPARE=1 to prevent the script from starting qemu.
    # Use OPT_PERSIST=0 to prevent the script from generating an empty userfs partition.
    ONLY_PREPARE=1 OPT_PERSIST=0 $BUILD_DIR/legato-qemu

    export KERNEL_IMG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/kernel"
    export ROOTFS_IMG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/rootfs.qcow2"

    export LEGATO_IMG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/legato.squashfs"

    export QEMU_CONFIG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/qemu-config"
fi

if [ ! -f "$LEGATO_IMG" ]; then
    echo "legato image ($LEGATO_IMG) not available, please build Legato before packaging the Docker image"
    echo "or do not set SKIP_DOWNLOAD=1."
    exit 1
fi

if [ -z "$USERFS_IMG" ] || [ ! -e "$USERFS_IMG" ]; then

    USERFS_SIZE=${USERFS_SIZE:-2G}
    USERFS_IMG=${USERFS_IMG:-"$BUILD_DIR/userfs.qcow2"}

    echo "userfs image ($USERFS_IMG) does not exist, creating one that contain sample apps."

    TARGET="virt_${VIRT_TARGET_ARCH}"
    FindToolchain

    FindTool "qemu-img" QEMU_IMG
    CheckRet

    FindTool "mkfs.ext4" MKFS_EXT4
    CheckRet

    set -e

    $QEMU_IMG create -f raw "${USERFS_IMG}.ext4" $USERFS_SIZE

    # Prepare content
    rm -rf "$BUILD_DIR/userfs"
    mkdir "$BUILD_DIR/userfs"

    # ... copy sample apps
    if ! cp -R "$LEGATO_ROOT/build/virt/samples" "$BUILD_DIR/userfs/"; then
        echo "sample apps not available, did you run 'make tests_virt' to build sample and test code?"
        exit 1
    fi

    # Generate an ext4 partition that will be used as /mnt/flash
    $MKFS_EXT4 -L userfs -d "$BUILD_DIR/userfs/" "${USERFS_IMG}.ext4"
<commit_msg>[virt] Do not fail packaging if sample apps are not available<commit_after>#!/bin/bash

set -xe

if [ -z "$LEGATO_ROOT" ]; then
    echo "LEGATO_ROOT not set"
    exit 1
fi

. "$LEGATO_ROOT/framework/tools/scripts/shlib"

SCRIPT_PATH="$( cd `dirname "$0"` && pwd )/`basename $0`"
if [ -L "$SCRIPT_PATH" ]; then
    SCRIPT_PATH=$(readlink $SCRIPT_PATH)
fi

VIRT_TARGET_ARCH=${VIRT_TARGET_ARCH:-x86}

## Create build directory

if [ -z "$BUILD_DIR" ]; then
    BUILD_DIR="$LEGATO_ROOT/build/virt-${VIRT_TARGET_ARCH}/docker"
fi

mkdir -p $BUILD_DIR

## Prepare files to be packaged in Docker image

# Configuration Script
cp "$LEGATO_ROOT/framework/tools/scripts/legato-qemu" "$BUILD_DIR"

# Download Legato image & Linux image
if [ -z "$SKIP_DOWNLOAD" ]; then
    export USER_DIR="$BUILD_DIR"

    # Use ONLY_PREPARE=1 to prevent the script from starting qemu.
    # Use OPT_PERSIST=0 to prevent the script from generating an empty userfs partition.
    ONLY_PREPARE=1 OPT_PERSIST=0 $BUILD_DIR/legato-qemu

    export KERNEL_IMG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/kernel"
    export ROOTFS_IMG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/rootfs.qcow2"

    export LEGATO_IMG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/legato.squashfs"

    export QEMU_CONFIG="$USER_DIR/img-virt-${VIRT_TARGET_ARCH}/qemu-config"
fi

if [ ! -f "$LEGATO_IMG" ]; then
    echo "legato image ($LEGATO_IMG) not available, please build Legato before packaging the Docker image"
    echo "or do not set SKIP_DOWNLOAD=1."
    exit 1
fi

if [ -z "$USERFS_IMG" ] || [ ! -e "$USERFS_IMG" ]; then

    USERFS_SIZE=${USERFS_SIZE:-2G}
    USERFS_IMG=${USERFS_IMG:-"$BUILD_DIR/userfs.qcow2"}

    echo "userfs image ($USERFS_IMG) does not exist, creating one that contain sample apps."

    TARGET="virt_${VIRT_TARGET_ARCH}"
    FindToolchain

    FindTool "qemu-img" QEMU_IMG
    CheckRet

    FindTool "mkfs.ext4" MKFS_EXT4
    CheckRet

    set -e

    $QEMU_IMG create -f raw "${USERFS_IMG}.ext4" $USERFS_SIZE

    # Prepare content
    rm -rf "$BUILD_DIR/userfs"
    mkdir "$BUILD_DIR/userfs"

    # ... copy sample apps
    if ! cp -R "$LEGATO_ROOT/build/virt/samples" "$BUILD_DIR/userfs/"; then
        echo "Sample apps not available, did you run 'make tests_virt' to build sample and test code?"
        echo "Continuing without ..."
    fi

    # Generate an ext4 partition that will be used as /mnt/flash
    $MKFS_EXT4 -L userfs -d "$BUILD_DIR/userfs/" "${USERFS_IMG}.ext4"

{'fraction_non_alphanumeric': 0.12487057361772624, 'fraction_numerical': 0.008490370677158831, 'mean_word_length': 3.698443579766537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3918541', 'n_tokens_mistral': 1889, 'n_tokens_neox': 1771, 'n_words': 443}