Skip to content

Commit bfec45f

Browse files
committed
Post install scripts for installing metadata files
1 parent 375b894 commit bfec45f

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2019-2022 Robotec.ai.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#if UNITY_EDITOR
16+
using System.IO;
17+
using UnityEngine;
18+
using UnityEditor;
19+
using UnityEditor.Build;
20+
using UnityEditor.Build.Reporting;
21+
22+
namespace ROS2
23+
{
24+
25+
/// <summary>
26+
/// An internal class responsible for installing ros2-for-unity metadata files
27+
/// </summary>
28+
internal class PostInstall : IPostprocessBuildWithReport
29+
{
30+
public int callbackOrder { get { return 0; } }
31+
public void OnPostprocessBuild(BuildReport report)
32+
{
33+
var r2fuMetadataName = "metadata_ros2_for_unity.xml";
34+
var r2csMetadataName = "metadata_ros2cs.xml";
35+
36+
// FileUtil.CopyFileOrDirectory: All file separators should be forward ones "/".
37+
var r2fuMeta = ROS2ForUnity.GetRos2ForUnityPath() + "/" + r2fuMetadataName;
38+
var r2csMeta = ROS2ForUnity.GetPluginPath() + "/" + r2csMetadataName;
39+
var outputDir = Directory.GetParent(report.summary.outputPath);
40+
var execFilename = Path.GetFileNameWithoutExtension(report.summary.outputPath);
41+
FileUtil.CopyFileOrDirectory(
42+
r2fuMeta, outputDir + "/" + execFilename + "_Data/" + r2fuMetadataName);
43+
FileUtil.CopyFileOrDirectory(
44+
r2csMeta, outputDir + "/" + execFilename + "_Data/Plugins/" + r2csMetadataName);
45+
}
46+
47+
}
48+
49+
}
50+
#endif

src/Ros2ForUnity/Scripts/ROS2ForUnity.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum Platform
3838
Linux
3939
}
4040

41-
private Platform GetOS()
41+
private static Platform GetOS()
4242
{
4343
if (Application.platform == RuntimePlatform.LinuxEditor || Application.platform == RuntimePlatform.LinuxPlayer)
4444
{
@@ -51,11 +51,11 @@ private Platform GetOS()
5151
throw new System.NotSupportedException("Only Linux and Windows are supported");
5252
}
5353

54-
private bool InEditor() {
54+
private static bool InEditor() {
5555
return Application.isEditor;
5656
}
5757

58-
private string GetOSName()
58+
private static string GetOSName()
5959
{
6060
switch (GetOS())
6161
{
@@ -83,7 +83,7 @@ private string GetEnvPathVariableValue()
8383
return Environment.GetEnvironmentVariable(GetEnvPathVariableName());
8484
}
8585

86-
private string GetRos2ForUnityPath()
86+
public static string GetRos2ForUnityPath()
8787
{
8888
char separator = Path.DirectorySeparatorChar;
8989
string appDataPath = Application.dataPath;
@@ -95,7 +95,7 @@ private string GetRos2ForUnityPath()
9595
return pluginPath;
9696
}
9797

98-
private string GetPluginPath()
98+
public static string GetPluginPath()
9999
{
100100
char separator = Path.DirectorySeparatorChar;
101101
string ros2ForUnityPath = GetRos2ForUnityPath();

0 commit comments

Comments
 (0)