Add '--only-target' option to build command
authorDmitriy Nikiforov <d.nikiforov@partner.samsung.com>
Thu, 27 Jul 2017 17:00:05 +0000 (20:00 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Mon, 14 Aug 2017 16:52:20 +0000 (19:52 +0300)
infra/commands/build.sh

index a04f5c3..be7a092 100755 (executable)
@@ -27,10 +27,13 @@ Usage: ${EXEC} build [OPTS] TARGET_DIR
 Builds a target in the specified directory.
 
 Options:
-  -h, --help        Prints this message.
-  -a, --arch ARCH   Architecture: x86_64 or i586 (default: x86_64)
-  -s, --spec SPEC   Path to the custom target specification file to be
-                    used instead of the default one.
+  -h, --help         Prints this message.
+  -a, --arch ARCH    Architecture: x86_64 or i586 (default: x86_64)
+  -o, --only-target  Build only target functions, without rebuild of dependencies.
+                     Use cautiously. This option will only work if you built THIS
+                     target without this option before.
+  -s, --spec SPEC    Path to the custom target specification file to be
+                     used instead of the default one.
 EOF
 }
 
@@ -67,6 +70,10 @@ while [[ ${1} = -* ]]; do
             ARCH=${2}
             shift 2
             ;;
+        '-o'|'--only-target')
+            ONLY_TARGET=1
+            shift
+            ;;
         '-s'|'--spec')
             CUSTOM_SPEC="${2}"
             shift 2
@@ -115,6 +122,10 @@ if [[ ! -d ${target_dir} ]]; then
     exit 1
 fi
 
+target_name=$(basename "${target_dir}")
+build_rpm_dir="${BUILD_ARTIFACTS_DIR}/${target_name}/${ARCH}/rpm"
+build_target_dir="${BUILD_ARTIFACTS_DIR}/${target_name}/${ARCH}/target"
+
 gbs_build_root="${GBS_ROOT}/local/BUILD-ROOTS/scratch.${ARCH}.0"
 rpm_root="${GBS_ROOT}/local/repos/${GBS_PROFILE}/${ARCH}/RPMS"
 
@@ -130,78 +141,76 @@ output_dir="${gbs_build_root}${chroot_output_dir}"
 
 echo "Building ${target_dir}:"
 
-# Check if target spec exists
-if [[ -n "${CUSTOM_SPEC}" ]]; then
-    spec_file="${CUSTOM_SPEC}"
-else
-    spec_file="${target_dir}/${TARGET_SPEC}"
-    if [[ ! -f "${spec_file}" ]]; then
-        echo "No '${TARGET_SPEC}' file in ${target_dir}. Skipping build..."
-        return
+if (( ONLY_TARGET != 1 )); then
+    # Check if target spec exists
+    if [[ -n "${CUSTOM_SPEC}" ]]; then
+        spec_file="${CUSTOM_SPEC}"
+    else
+        spec_file="${target_dir}/${TARGET_SPEC}"
+        if [[ ! -f "${spec_file}" ]]; then
+            echo "No '${TARGET_SPEC}' file in ${target_dir}. Skipping build..."
+            return
+        fi
     fi
-fi
-
-# Parse target spec
-echo "Parsing ${spec_file} file..."
-eval 'declare -A spec=('`print_spec_values ${spec_file}`')'
-
-if [[ -z ${spec[main]} ]]; then
-    echo "Error: 'main' field is missing. Skipping build..."
-    return
-fi
 
-# ensure that the main project will be the last one to build the
-# fuzzing target on top of it
-projects=(${spec[extra]} ${spec[main]})
+    # Parse target spec
+    echo "Parsing ${spec_file} file..."
+    eval 'declare -A spec=('`print_spec_values ${spec_file}`')'
 
-# unmount '/proc' if it was mounted, otherwise gbs-build might fail
-sudo chroot "${gbs_build_root}" umount /proc 2>/dev/null || true
-
-target_name=$(basename "${target_dir}")
-build_rpm_dir="${BUILD_ARTIFACTS_DIR}/${target_name}/${ARCH}/rpm"
-build_target_dir="${BUILD_ARTIFACTS_DIR}/${target_name}/${ARCH}/target"
-
-# build each project
-for project in ${projects[@]}; do
-    repo_url="${project%\$*}"
-    branch="${project##*$}"
-    project_name="$(basename ${repo_url})"
-    git_dir="${SRCS_DIR}/${project_name}"
-
-    # clone the repo or pull new changes
-    if [[ ! -d "${git_dir}" ]]; then
-        echo "Cloning ${repo} (${branch} branch) into ${git_dir} ..."
-        mkdir -p "${git_dir}"
-        git clone -q --single-branch --branch "${branch}" "${repo_url}" "${git_dir}"
-    else
-        pushd "${git_dir}"
+    if [[ -z ${spec[main]} ]]; then
+        echo "Error: 'main' field is missing. Skipping build..."
+        return
+    fi
 
-        # check if remote url should be updated
-        if [[ $(git remote get-url origin) != "${repo_url}" ]]; then
-            git remote set-url origin "${repo_url}"
+    # ensure that the main project will be the last one to build the
+    # fuzzing target on top of it
+    projects=(${spec[extra]} ${spec[main]})
+
+    # unmount '/proc' if it was mounted, otherwise gbs-build might fail
+    sudo chroot "${gbs_build_root}" umount /proc 2>/dev/null || true
+
+    # build each project
+    for project in ${projects[@]}; do
+        repo_url="${project%\$*}"
+        branch="${project##*$}"
+        project_name="$(basename ${repo_url})"
+        git_dir="${SRCS_DIR}/${project_name}"
+
+        # clone the repo or pull new changes
+        if [[ ! -d "${git_dir}" ]]; then
+            echo "Cloning ${repo} (${branch} branch) into ${git_dir} ..."
+            mkdir -p "${git_dir}"
+            git clone -q --single-branch --branch "${branch}" "${repo_url}" "${git_dir}"
+        else
+            pushd "${git_dir}"
+
+            # check if remote url should be updated
+            if [[ $(git remote get-url origin) != "${repo_url}" ]]; then
+                git remote set-url origin "${repo_url}"
+            fi
+
+            # fetch and checkout any new changes
+            echo "Pulling changes for ${repo_url} (${branch} branch)..."
+            git fetch -q origin "${branch}"
+            git checkout -q FETCH_HEAD
+            popd
         fi
 
-        # fetch and checkout any new changes
-        echo "Pulling changes for ${repo_url} (${branch} branch)..."
-        git fetch -q origin "${branch}"
-        git checkout -q FETCH_HEAD
-        popd
-    fi
-
-    # run the gbs build
-    gbs -c "${GBS_CONFIG}" build \
-        -A "${ARCH}" \
-        -B "${GBS_ROOT}" \
-        --extra-packs=$(join ',' ${LIBFUZZER_PKGS[@]}) \
-        ${EXTRA_GBS_ARGS[@]} \
-        "${git_dir}"
-
-    # copy build artifacts
-    mkdir -p "${build_rpm_dir}"
-    cp -f "${rpm_root}/"* "${build_rpm_dir}"
-done
+        # run the gbs build
+        gbs -c "${GBS_CONFIG}" build \
+            -A "${ARCH}" \
+            -B "${GBS_ROOT}" \
+            --extra-packs=$(join ',' ${LIBFUZZER_PKGS[@]}) \
+            ${EXTRA_GBS_ARGS[@]} \
+            "${git_dir}"
+
+        # copy build artifacts
+        mkdir -p "${build_rpm_dir}"
+        cp -f "${rpm_root}/"* "${build_rpm_dir}"
+    done
+fi
 
-# build fuzzing target
+# copy fuzzing target sources
 cp -rf "${target_dir}/"* "${build_root}"
 mkdir -p "${output_dir}"