<commit_before>#!/usr/bin/env bash

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################


#=================================================
#                   Utils
#=================================================
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${DIR}"

source "${DIR}/scripts/apollo_base.sh"

# check operating system
OP_SYSTEM=$(uname -o)
case $OP_SYSTEM in
  *"Linux")
     echo "System check passed. Build continue ..."
     ;;
  *)
     error "Unsupported system: ${OP_SYSTEM}."
     error "Please use Linux, we recommend Ubuntu 14.04."
     exit 1
     ;;
esac

# the machine type, currently support x86_64, aarch64
MACHINE_ARCH=$(uname -m)

IS_X86_64=false
IS_AARCH64=false

BUILD_TARGETS=""
TEST_TARGETS=""
CAN_CARD="fake_can"

rm -rf ./third_party/ros
if [ "$MACHINE_ARCH" == 'x86_64' ]; then
   IS_X86_64=true
   sed "s/MACHINE_ARCH/x86_64/g" WORKSPACE.in > WORKSPACE
elif [ "$MACHINE_ARCH" == 'aarch64' ]; then
   IS_AARCH64=true
   sed "s/MACHINE_ARCH/aarch64/g" WORKSPACE.in > WORKSPACE
fi

if ! $IS_X86_64 && ! $IS_AARCH64 ; then
   fail "Unknown machine architecture $MACHINE_ARCH"
   exit 1
fi

function check_esd_files() {
  if [ -f ./third_party/can_card_library/esd_can/include/ntcan.h \
      -a -f ./third_party/can_card_library/esd_can/lib/libntcan.so \
      -a -f ./third_party/can_card_library/esd_can/lib/libntcan.so.4 \
      -a -f ./third_party/can_card_library/esd_can/lib/libntcan.so.4.0.1 ]; then
      USE_ESD_CAN=true
      CAN_CARD="esd_can"
  else
      warning "${YELLOW}ESD CAN library supplied by ESD Electronics does not exist.${NO_COLOR}"
      warning "${YELLOW}If you need ESD CAN, please refer to third_party/can_card_library/esd_can/README.md${NO_COLOR}"
      USE_ESD_CAN=false
  fi
}

check_esd_files

function generate_build_targets() {
  BUILD_TARGETS=$(bazel query //... | grep -v "_test$" | grep -v "third_party" \
    | grep -v "_cpplint$" | grep -v "release" | grep -v "kernel")
  if ! $USE_ESD_CAN; then
     BUILD_TARGETS=$(echo $BUILD_TARGETS |tr ' ' '\n' | grep -v "hwmonitor" | grep -v "esd")
  fi
}

function generate_test_targets() {
  TEST_TARGETS=$(bazel query //... | grep "_test$" | grep -v "third_party" | grep -v "kernel")
  if ! $USE_ESD_CAN; then
     TEST_TARGETS=$(echo $TEST_TARGETS| tr ' ' '\n' | grep -v "hwmonitor" | grep -v "esd")
  fi
}

#=================================================
#              Build functions
#=================================================


function apollo_build() {
  START_TIME=$(($(date +%s%N)/1000000))

  # Avoid query release directory.
  if [ -d release ];then
    rm -rf release
  fi
  echo "Start building, please wait ..."
  generate_build_targets
  echo "Building on $MACHINE_ARCH, with targets:"
  echo "$BUILD_TARGETS"
  echo "$BUILD_TARGETS" | xargs bazel --batch --batch_cpu_scheduling build --define ARCH="$MACHINE_ARCH" --define CAN_CARD=${CAN_CARD} --cxxopt=-DUSE_ESD_CAN=${USE_ESD_CAN} -c dbg
  if [ $? -eq 0 ]; then<commit_msg>limit the bazel compile resource by set --jobs=10<commit_after>#!/usr/bin/env bash

###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################


#=================================================
#                   Utils
#=================================================
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${DIR}"

source "${DIR}/scripts/apollo_base.sh"

# check operating system
OP_SYSTEM=$(uname -o)
case $OP_SYSTEM in
  *"Linux")
     echo "System check passed. Build continue ..."
     ;;
  *)
     error "Unsupported system: ${OP_SYSTEM}."
     error "Please use Linux, we recommend Ubuntu 14.04."
     exit 1
     ;;
esac

# the machine type, currently support x86_64, aarch64
MACHINE_ARCH=$(uname -m)

IS_X86_64=false
IS_AARCH64=false

BUILD_TARGETS=""
TEST_TARGETS=""
CAN_CARD="fake_can"

rm -rf ./third_party/ros
if [ "$MACHINE_ARCH" == 'x86_64' ]; then
   IS_X86_64=true
   sed "s/MACHINE_ARCH/x86_64/g" WORKSPACE.in > WORKSPACE
elif [ "$MACHINE_ARCH" == 'aarch64' ]; then
   IS_AARCH64=true
   sed "s/MACHINE_ARCH/aarch64/g" WORKSPACE.in > WORKSPACE
fi

if ! $IS_X86_64 && ! $IS_AARCH64 ; then
   fail "Unknown machine architecture $MACHINE_ARCH"
   exit 1
fi

function check_esd_files() {
  if [ -f ./third_party/can_card_library/esd_can/include/ntcan.h \
      -a -f ./third_party/can_card_library/esd_can/lib/libntcan.so \
      -a -f ./third_party/can_card_library/esd_can/lib/libntcan.so.4 \
      -a -f ./third_party/can_card_library/esd_can/lib/libntcan.so.4.0.1 ]; then
      USE_ESD_CAN=true
      CAN_CARD="esd_can"
  else
      warning "${YELLOW}ESD CAN library supplied by ESD Electronics does not exist.${NO_COLOR}"
      warning "${YELLOW}If you need ESD CAN, please refer to third_party/can_card_library/esd_can/README.md${NO_COLOR}"
      USE_ESD_CAN=false
  fi
}

check_esd_files

function generate_build_targets() {
  BUILD_TARGETS=$(bazel query //... | grep -v "_test$" | grep -v "third_party" \
    | grep -v "_cpplint$" | grep -v "release" | grep -v "kernel")
  if ! $USE_ESD_CAN; then
     BUILD_TARGETS=$(echo $BUILD_TARGETS |tr ' ' '\n' | grep -v "hwmonitor" | grep -v "esd")
  fi
}

function generate_test_targets() {
  TEST_TARGETS=$(bazel query //... | grep "_test$" | grep -v "third_party" | grep -v "kernel")
  if ! $USE_ESD_CAN; then
     TEST_TARGETS=$(echo $TEST_TARGETS| tr ' ' '\n' | grep -v "hwmonitor" | grep -v "esd")
  fi
}

#=================================================
#              Build functions
#=================================================


function apollo_build() {
  START_TIME=$(($(date +%s%N)/1000000))

  # Avoid query release directory.
  if [ -d release ];then
    rm -rf release
  fi
  echo "Start building, please wait ..."
  generate_build_targets
  echo "Building on $MACHINE_ARCH, with targets:"
  echo "$BUILD_TARGETS"
  echo "$BUILD_TARGETS" | xargs bazel --batch --batch_cpu_scheduling build --jobs=10 --define ARCH="$MACHINE_ARCH" --define CAN_CARD=${CAN_CARD} --cxxopt=-DUSE_ESD_CAN=${USE_ESD_CAN} -c dbg
  if [ $? -eq 0 ]; then
{'fraction_non_alphanumeric': 0.2151694459386767, 'fraction_numerical': 0.017482517482517484, 'mean_word_length': 3.9415282392026576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2907343', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2430, 'n_words': 661}