Skip to content

Commit 9ac12ac

Browse files
authored
Merge pull request #15 from RobotecAI/build_scripts_improvements
Build scripts improvements
2 parents fd7758f + 0b634a7 commit 9ac12ac

File tree

7 files changed

+118
-49
lines changed

7 files changed

+118
-49
lines changed

README-UBUNTU.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ Start with installation of dependencies. Make sure to complete each step of `ros
1515
* Run `pull_repositories.sh`. This will pull `ros2cs` as well as your custom messages. You might be asked for gitlab credentials. Remember to **pull this repository with each update** (e.g. with `vcs pull`).
1616
* Run `build.sh` script.
1717
* You can build tests by adding `--with-tests` argument to `build` command.
18+
* You can build with `--clean-install` to make sure your installation directory is cleaned before deploying.
1819
* It invokes `colcon_build` with `--merge-install` argument to simplify libraries installation.
1920
* It deploys built plugins into the Asset directory. Note that only plugins built for the current platform will be deployed (there is no cross-compilation).
20-
* It prepares Unity Asset that is ready to import into your Unity project.
21-
* Run `create_unity_asset.sh -u <your-path-to-unity-editor-executable>` to generate .unitypackage file in `install/unity_package`
21+
* It prepares Unity Asset that is ready to import into your Unity project (`install/asset/` directory).
22+
* Run `create_unity_package.sh -u <your-path-to-unity-editor-executable>` to generate .unitypackage file in `install/unity_package`
2223

2324
## OS-Specific usage remarks
2425

README-WINDOWS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ It is necessary to complete all the steps for `ros2cs` [Prerequisites](https://g
2020
* Run `pull_repositories.ps1`. This will pull `ros2cs` as well as your custom messages. You might be asked for github credentials.
2121
* Run `build.ps1` script.
2222
* Optionally, you can build tests by adding `--with-tests` argument to `build` command.
23+
* You can build with `--clean-install` to make sure your installation directory is cleaned before deploying.
2324
* This ivokes `colcon_build` with `--merge-install` argument to simplify libraries installation.
2425
* It deploys built plugins into the Asset directory. Note that only plugins built for the current platform will be deployed (there is no cross-compilation).
25-
* It prepares Unity Asset that is ready to import into your Unity project.
26+
* It prepares Unity Asset that is ready to import into your Unity project (`install/asset/` directory).
2627
* By default, build process generates standalone libraries on Windows.
2728
You can disable this feature by setting CMake option `STANDALONE_BUILD` to `OFF` (e.g. through editing `build.ps1`).
28-
* In order to generate `Ros2ForUnity.unitypackage` please run `create_unity_asset.ps1`. Please provide path to your Unity executable when prompted.
29+
* In order to generate `Ros2ForUnity.unitypackage` please run `create_unity_package.ps1`. Please provide path to your Unity executable when prompted.
2930
* Asset can be found in `install\unity_package` directory
30-
* In case your Unity license has expired, the `create_unity_asset.ps1` won't throw any errors but `Ros2ForUnity.unitypackage` won't be generated too.
31+
* In case your Unity license has expired, the `create_unity_package.ps1` won't throw any errors but `Ros2ForUnity.unitypackage` won't be generated too.
3132
* At this moment you have two valid forms of the Asset.
3233
* One is available as `src\Ros2ForUnity` folder which you can simply copy to Unity3D `Assets` directory.
3334
* Second one is `Ros2ForUnity.unitypackage` which you can import in Unity3D.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Please see OS-specific instructions:
4747
2. Open or create Unity project.
4848
3. Go to Assets in the menu bar (at the top of the Unity Window).
4949
4. Select `Import Package``Custom Package`.
50-
5. In the file browser, select the .unitypackage file built by `create_unity_asset` script (by default located in `install/unity_package`) and follow the instructions on the screen.
50+
5. In the file browser, select the .unitypackage file built by `create_unity_package` script (by default located in `install/unity_package`) and follow the instructions on the screen.
5151
6. Create a top-level object containing `ROS2UnityComponent.cs`. This is the central Monobehavior for `ROS2 For Unity` that manages all the nodes. Refer to class documentation for details.
5252
7. Add example script to any object in the hierarchy tab, e.g. by dragging `ROS2TalkerExample.cs` to the object in the inspector tab.
5353
8. Select another object in the hierarchy tab and add repeat the previous step using `ROS2ListenerExample.cs`.

build.ps1

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,50 @@
1-
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
21

3-
function Print-Help {
4-
"
5-
Usage:
6-
build.ps1 [--with-tests]
2+
<#
3+
.SYNOPSIS
4+
Builds Ros2ForUnity asset
5+
.DESCRIPTION
6+
This script builds Ros2DorUnity asset
7+
.PARAMETER with_tests
8+
Build tests
9+
.PARAMETER standalone
10+
Add ros2 binaries. Currently standalone flag is fixed to true, so there is no way to build without standalone libs. Parameter kept for future releases
11+
.PARAMETER clean_install
12+
Makes a clean installation. Removes install dir before deploying
13+
#>
14+
Param (
15+
[Parameter(Mandatory=$false)][switch]$with_tests=$false,
16+
[Parameter(Mandatory=$false)][switch]$standalone=$true,
17+
[Parameter(Mandatory=$false)][switch]$clean_install=$false
18+
)
19+
20+
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
721

8-
Options:
9-
--with-tests - build with tests.
10-
"
22+
if(-Not (Test-Path -Path "$scriptPath\src\ros2cs")) {
23+
Write-Host "Pull repositories with 'pull_repositories.ps1' first." -ForegroundColor Red
24+
exit 1
1125
}
1226

13-
$tests=0
14-
$msg="Build started."
15-
if ($args[0] -eq "--with-tests") {
16-
$tests=1
17-
$msg+=" (with tests)"
18-
} elseif ($args[0] -eq "--help" -Or $args[0] -eq "-h") {
19-
Print-Help
20-
exit
27+
Write-Host $msg -ForegroundColor Green
28+
$options = @{
29+
with_tests = $with_tests
30+
standalone = $standalone
2131
}
2232

23-
$tests_info=0
24-
$plugin_path=Join-Path -Path $scriptPath -ChildPath "\src\Ros2ForUnity\Plugins\"
33+
if($clean_install) {
34+
Write-Host "Cleaning install directory..." -ForegroundColor White
35+
Remove-Item -Path "$scriptPath\install" -Force -Recurse -ErrorAction Ignore
36+
}
37+
& "$scriptPath\src\ros2cs\build.ps1" @options
38+
if($?) {
39+
md -Force $scriptPath\install\asset | Out-Null
40+
Copy-Item -Path $scriptPath\src\Ros2ForUnity -Destination $scriptPath\install\asset\ -Recurse -Force
41+
42+
$plugin_path=Join-Path -Path $scriptPath -ChildPath "\install\asset\Ros2ForUnity\Plugins\"
43+
Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
44+
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path
45+
} else {
46+
Write-Host "Ros2cs build failed!" -ForegroundColor Red
47+
exit 1
48+
}
2549

26-
Write-Host $msg -ForegroundColor Green
27-
colcon build --merge-install --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$tests
2850

29-
Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
30-
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path

build.sh

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,63 @@
22
SCRIPT=$(readlink -f $0)
33
SCRIPTPATH=`dirname $SCRIPT`
44

5-
if [ -z "${ROS_DISTRO}" ]; then
6-
echo "Source your ros2 distro first (Foxy and Galactic are supported)"
7-
exit 1
8-
fi
9-
10-
TESTS=0
11-
MSG="Build started."
12-
if [ "$1" = "--with-tests" ]; then
13-
TESTS=1
14-
MSG="$MSG (with tests)"
15-
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
5+
display_usage() {
166
echo "Usage: "
17-
echo "build.sh [--with-tests]"
7+
echo ""
8+
echo "build.sh [--with-tests] [--standalone] [--clean-install]"
189
echo ""
1910
echo "Options:"
20-
echo "--with-tests - build with tests."
11+
echo "--with-tests - build with tests"
12+
echo "--standalone - standalone version"
13+
echo "--clean-install - makes a clean installation, removes install directory before deploying"
14+
}
15+
16+
if [ ! -d "$SCRIPTPATH/src/ros2cs" ]; then
17+
echo "Pull repositories with 'pull_repositories.sh' first."
2118
exit 1
2219
fi
2320

24-
echo $MSG
25-
#TODO - call ros2cs ./build.sh instead, but with this workspace directory (parametrize the script)
26-
colcon build --merge-install --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$TESTS -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-rpath=." && $SCRIPTPATH/deploy_unity_plugins.sh $SCRIPTPATH/src/Ros2ForUnity/Plugins/
21+
OPTIONS=""
22+
STANDALONE=0
23+
TESTS=0
24+
CLEAN_INSTALL=0
25+
26+
while [[ $# -gt 0 ]]; do
27+
key="$1"
28+
case $key in
29+
-t|--with-tests)
30+
OPTIONS="$OPTIONS --with-tests"
31+
TESTS=1
32+
shift # past argument
33+
;;
34+
-s|--standalone)
35+
OPTIONS="$OPTIONS --standalone"
36+
STANDALONE=1
37+
shift # past argument
38+
;;
39+
-c|--clean-install)
40+
CLEAN_INSTALL=1
41+
shift # past argument
42+
;;
43+
-h|--help)
44+
display_usage
45+
exit 0
46+
shift # past argument
47+
;;
48+
*) # unknown option
49+
shift # past argument
50+
;;
51+
esac
52+
done
53+
54+
if [ $CLEAN_INSTALL == 1 ]; then
55+
echo "Cleaning install directory..."
56+
rm -rf "$SCRIPTPATH/install"
57+
fi
58+
if $SCRIPTPATH/src/ros2cs/build.sh $OPTIONS; then
59+
mkdir -p $SCRIPTPATH/install/asset && cp -R $SCRIPTPATH/src/Ros2ForUnity $SCRIPTPATH/install/asset/Ros2ForUnity
60+
$SCRIPTPATH/deploy_unity_plugins.sh $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/
61+
else
62+
echo "Ros2cs build failed!"
63+
exit 1
64+
fi

create_unity_asset.ps1 renamed to create_unity_package.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
2424
$temp_dir = $Env:TEMP
2525

2626
if(-Not $PSBoundParameters.ContainsKey('input_asset')) {
27-
$input_asset= Join-Path -Path $scriptPath -ChildPath "\src\Ros2ForUnity"
27+
$input_asset= Join-Path -Path $scriptPath -ChildPath "\install\asset\Ros2ForUnity"
2828
}
2929

3030
if(-Not $PSBoundParameters.ContainsKey('output_dir')) {
3131
$output_dir= Join-Path -Path $scriptPath -ChildPath "\install\unity_package"
3232
}
3333

34+
if(-Not (Test-Path -Path "$input_asset")) {
35+
Write-Host "Input asset '$input_asset' doesn't exist! Use 'build.ps1' to build project first." -ForegroundColor Red
36+
exit 1
37+
}
38+
3439
if(-Not (Test-Path -Path "$output_dir")) {
3540
mkdir ${output_dir} | Out-Null
3641
}

create_unity_asset.sh renamed to create_unity_package.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ display_usage() {
77
echo "This script creates a temporary Unity project in '/tmp' directory, copy input asset and makes an unity package out of it. Valid Unity license is required."
88
echo ""
99
echo "Usage:"
10-
echo "create_unity_asset.sh -u <UNITY_PATH> -i [INPUT_ASSET] -p [PACKAGE_NAME] -o [OUTPUT_DIR]"
10+
echo "create_unity_package.sh -u <UNITY_PATH> -i [INPUT_ASSET] -p [PACKAGE_NAME] -o [OUTPUT_DIR]"
1111
echo ""
1212
echo "UNITY_PATH - Unity editor executable path"
13-
echo "INPUT_ASSET - input asset to pack into unity package, default = 'src/Ros2ForUnity'"
13+
echo "INPUT_ASSET - input asset to pack into unity package, default = 'install/asset/Ros2ForUnity'"
1414
echo "PACKAGE_NAME - unity package name, default = 'Ros2ForUnity'"
1515
echo "OUTPUT_DIR - output file directory, default = 'install/unity_package'"
1616
}
1717

1818
UNITY_PATH=""
19-
INPUT_ASSET="src/Ros2ForUnity"
19+
INPUT_ASSET="install/asset/Ros2ForUnity"
2020
PACKAGE_NAME="Ros2ForUnity"
2121
OUTPUT_DIR="$SCRIPTPATH/install/unity_package"
2222

@@ -48,7 +48,6 @@ while [[ $# -gt 0 ]]; do
4848
display_usage
4949
exit 0
5050
shift # past argument
51-
shift # past value
5251
;;
5352
*) # unknown option
5453
shift # past argument
@@ -63,6 +62,11 @@ if [ -z "$UNITY_PATH" ] || [ -z "$PACKAGE_NAME" ] || [ -z "$INPUT_ASSET" ] || [
6362
exit 1
6463
fi
6564

65+
if [ ! -d "$INPUT_ASSET" ]; then
66+
echo "Input asset '$INPUT_ASSET' doesn't exist! Use 'build.sh' to build project first."
67+
exit 1
68+
fi
69+
6670
UNITY_VERSION=`$UNITY_PATH -version`
6771

6872
# Test if unity editor is valid

0 commit comments

Comments
 (0)