Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update configs #99

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/scripts/onCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ git submodule update --init
echo "#######################################################"
echo "### Install Dependencies ###"
echo "#######################################################"
./install_dependencies.sh 2>&1 | tee -a $HOME/install_dependencies.log
velocitas exec build-system install

echo "#######################################################"
echo "### VADF package status ###"
Expand Down
8 changes: 4 additions & 4 deletions .velocitas-lock.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"packages": {
"devenv-runtimes": "v3.1.0",
"devenv-github-workflows": "v6.0.0",
"devenv-github-templates": "v1.0.4",
"devenv-devcontainer-setup": "v2.1.0"
"devenv-runtimes": "v4.0.0",
"devenv-github-workflows": "v6.0.1",
"devenv-github-templates": "v1.0.5",
"devenv-devcontainer-setup": "v2.2.1"
}
}
13 changes: 7 additions & 6 deletions .velocitas.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"packages": {
"devenv-runtimes": "v3.1.0",
"devenv-github-workflows": "v6.0.0",
"devenv-github-templates": "v1.0.4",
"devenv-devcontainer-setup": "v2.1.0"
"devenv-runtimes": "v4.0.0",
"devenv-github-workflows": "v6.0.1",
"devenv-github-templates": "v1.0.5",
"devenv-devcontainer-setup": "v2.2.1"
},
"components": [
"runtime-local",
Expand All @@ -15,7 +15,8 @@
"devcontainer-setup",
"vehicle-signal-interface",
"grpc-interface-support",
"sdk-installer"
"sdk-installer",
"build-system"
],
"variables": {
"language": "cpp",
Expand All @@ -24,5 +25,5 @@
"githubRepoId": "eclipse-velocitas/vehicle-app-cpp-template",
"vehicleAppPort": -1
},
"cliVersion": "v0.9.0"
"cliVersion": "v0.9.1"
}
6 changes: 3 additions & 3 deletions NOTICE-3RD-PARTY-CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
|identify|2.5.36|MIT|
|idna|3.7|BSD|
|jinja2|3.1.4|BSD|
|lxml|5.2.1|New BSD|
|lxml|5.2.2|New BSD|
|MarkupSafe|2.1.5|New BSD|
|node-semver|0.6.1|MIT|
|nodeenv|1.8.0|BSD|
|patch-ng|1.17.4|MIT|
|platformdirs|4.2.1|MIT|
|platformdirs|4.2.2|MIT|
|pluginbase|1.0.1|BSD|
|pre-commit|3.5.0|MIT|
|pygments|2.18.0|Simplified BSD|
Expand All @@ -35,7 +35,7 @@
|six|1.16.0|MIT|
|tqdm|4.66.4|MIT<br/>Mozilla Public License 2.0 (MPL 2.0)|
|urllib3|1.26.18|MIT|
|virtualenv|20.26.1|MIT|
|virtualenv|20.26.2|MIT|
## Workflows
| Dependency | Version | License |
|:-----------|:-------:|--------:|
Expand Down
2 changes: 1 addition & 1 deletion app/AppManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"type": "vehicle-signal-interface",
"config": {
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v3.0/vss_rel_3.0.json",
"src": "https://github.com/COVESA/vehicle_signal_specification/releases/download/v4.0/vss_rel_4.0.json",
"datapoints":
{
"required": [
Expand Down
194 changes: 194 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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.
#
# SPDX-License-Identifier: Apache-2.0

import json
import os
import subprocess
from argparse import ArgumentParser
from pathlib import Path
from typing import List

from shared_utils import get_valid_arch
from velocitas_lib import get_workspace_dir

CMAKE_EXECUTABLE = "cmake"
CONAN_EXECUTABLE = "conan"


def safe_get_workspace_dir() -> str:
"""A safe version of get_workspace_dir which defaults to '.'."""
try:
return get_workspace_dir()
except Exception:
return "."


def get_build_tools_path(build_folder_path: str) -> str:
paths: List[str] = []
with open(
os.path.join(build_folder_path, "conanbuildinfo.txt"), encoding="utf-8"
) as file:
for line in file:
if line.startswith("PATH="):
path_list = json.loads(line[len("PATH=") :])
paths.extend(path_list)
return ";".join(paths)


def print_build_info(
build_variant: str,
build_arch: str,
host_arch: str,
build_target: str,
is_static_build: bool,
) -> None:
"""Print information about the build.

Args:
build_variant (str): The variant of the build: "release" or "debug"
build_arch (str): The architecture the app is built for.
build_target (str): Which artefact is being built.
is_static_build (bool): Enable static building.
"""
cmake_version = subprocess.check_output(
[CMAKE_EXECUTABLE, "--version"], encoding="utf-8"
).strip()
conan_version = subprocess.check_output(
[CONAN_EXECUTABLE, "--version"], encoding="utf-8"
).strip()

print(f"CMake version {cmake_version}")
print(f"Conan version {conan_version}")
print(f"Build arch {build_arch}")
print(f"Host arch {host_arch}")
print(f"Build variant {build_variant}")
print(f"Build target {build_target}")
print(f"Static build {'yes' if is_static_build else 'no'}")


def build(
build_variant: str,
build_arch: str,
host_arch: str,
build_target: str,
static_build: bool,
coverage: bool = True,
) -> None:
build_folder = os.path.join(safe_get_workspace_dir(), "build")

cxx_flags = ["-g"]
if coverage:
cxx_flags.append("--coverage")

if build_variant == "release":
cxx_flags.append("-O3")
else:
cxx_flags.append("-O0")

os.makedirs(build_folder, exist_ok=True)

xcompile_toolchain_file = ""
if build_arch != host_arch:
profile_build_path = (
Path(__file__)
.absolute()
.parent.joinpath("cmake", f"{build_arch}_to_{host_arch}.cmake")
)
xcompile_toolchain_file = f"-DCMAKE_TOOLCHAIN_FILE={profile_build_path}"

subprocess.run(
[
CMAKE_EXECUTABLE,
"--no-warn-unused-cli",
"-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE",
f"-DCMAKE_BUILD_TYPE:STRING={build_variant}",
f'-DBUILD_TOOLS_PATH:STRING="{get_build_tools_path(build_folder)}"',
f"-DSTATIC_BUILD:BOOL={'TRUE' if static_build else 'FALSE'}",
xcompile_toolchain_file,
"-S..",
"-B.",
"-G",
"Ninja",
f"-DCMAKE_CXX_FLAGS={' '.join(cxx_flags)}",
],
cwd=build_folder,
)
subprocess.run(
[
CMAKE_EXECUTABLE,
"--build",
".",
"--config",
build_variant,
"--target",
build_target,
],
cwd=build_folder,
)


def cli() -> None:
parser = ArgumentParser(
description="""Build targets of the project
============================================================================
Builds the targets of the project in different flavors."""
)
parser.add_argument(
"-d",
"--debug",
action="store_const",
const="debug",
dest="variant",
help="Builds the target(s) in debug mode.",
)
parser.add_argument(
"-r",
"--release",
action="store_const",
const="release",
dest="variant",
help="Builds the target(s) in release mode.",
)
parser.add_argument(
"-t", "--target", help="Builds only the target <name> instead of all targets."
)
parser.add_argument(
"-s", "--static", action="store_true", help="Links all dependencies statically."
)
parser.add_argument(
"-x",
"--cross",
action="store",
help="Enables cross-compilation to the defined target architecture.",
)
args = parser.parse_args()
if not args.variant:
args.variant = "debug"
if not args.target:
args.target = "all"
build_arch = subprocess.check_output(["arch"], encoding="utf-8").strip()

host_arch = args.cross

if host_arch is None:
host_arch = build_arch
else:
host_arch = get_valid_arch(host_arch)

print_build_info(args.variant, build_arch, host_arch, args.target, args.static)
build(args.variant, build_arch, host_arch, args.target, args.static)


if __name__ == "__main__":
cli()
108 changes: 6 additions & 102 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
# Copyright (c) 2022-2024 Contributors to the Eclipse Foundation
# This file is maintained by velocitas CLI, do not modify manually. Change settings in .velocitas.json

# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
Expand All @@ -13,104 +15,6 @@
#
# SPDX-License-Identifier: Apache-2.0

#
# Builds the targets of the project in different flavors.
#

set -e

function print_help() {
echo "Build targets of the project
============================================================================
Builds the targets of the project in different flavors.

Arguments:
-d, --debug Builds the target(s) in debug mode.
-r, --release Builds the target(s) in release mode.
-t <name>, --target <name> Builds only the target <name> instead of all targets.
-s, --static Links all dependencies statically.
-h, --help Shows this help.
"
}

BUILD_VARIANT=debug
BUILD_ARCH=$(arch)
BUILD_TARGET=all
STATIC_BUILD=OFF

POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case $1 in
-d|--debug)
BUILD_VARIANT="debug"
shift
;;
-r|--release)
BUILD_VARIANT="release"
shift
;;
-t|--target)
BUILD_TARGET="$2"
shift
shift
;;
-s|--static)
STATIC_BUILD=ON
shift
;;
-h|--help)
print_help
exit 0
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done

echo "CMake version "`cmake --version`
echo "Conan version "`conan --version`
echo "Build variant ${BUILD_VARIANT}"
echo "Build arch ${BUILD_ARCH}"
echo "Build target ${BUILD_TARGET}"
echo "Static build ${STATIC_BUILD}"

CMAKE_CXX_FLAGS="--coverage -g -O0"

if [ "${BUILD_VARIANT}" == "release" ]; then
CMAKE_CXX_FLAGS="--coverage -s -g -O3"
fi

mkdir -p build && cd build

# Expose the PATH of the build-time requirements from Conan to CMake - this is NOT handled by
# any of Conan's CMake generators at the moment, hence we parse the conanbuildinfo.txt which
# is generated and holds these paths. This allows us to always use the protoc and grpc cpp plugin
# of the build system.
BUILD_TOOLS_PATH=""
CONAN_BUILD_TOOLS_PATHS=$(sed '/^PATH=/!d;s/PATH=//g;s/,/\n/g' ./conanbuildinfo.txt | tr -d '[]'\" )
while read -r p; do
if [[ ! -z "${p// }" ]]; then
BUILD_TOOLS_PATH="$BUILD_TOOLS_PATH;$p"
fi
done < <(echo "$CONAN_BUILD_TOOLS_PATHS")

cmake --no-warn-unused-cli \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \
-DCMAKE_BUILD_TYPE:STRING=${BUILD_VARIANT} \
-DBUILD_TOOLS_PATH:STRING="${BUILD_TOOLS_PATH}" \
-DSTATIC_BUILD:BOOL=${STATIC_BUILD} \
-S.. \
-B../build \
-G Ninja \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}"

cmake --build . --config ${BUILD_VARIANT} --target ${BUILD_TARGET} --
cd ..
# Provides backward compatibility for all scripts and pipelines
# which use the bash variant.
python3 ./build.py $@
Loading
Loading