|
1 | 1 | Import("env") |
2 | | -import os, sys |
3 | 2 |
|
4 | | -############################## |
5 | | -#### Install dependencies #### |
6 | | -############################## |
7 | | - |
8 | | -pip_packages = [x.split("==")[0] for x in os.popen('{} -m pip freeze'.format(env['PYTHONEXE'])).read().split('\n')] |
9 | | -required_packages = ["catkin-pkg", "lark-parser", "empy", "colcon-common-extensions", "importlib-resources", "pyyaml"] |
10 | | -if all([x in pip_packages for x in required_packages]): |
11 | | - print("All required Python pip packages are installed") |
12 | | - |
13 | | -for p in [x for x in required_packages if x not in pip_packages]: |
14 | | - print('Installing {} with pip at PlatformIO environment'.format(p)) |
15 | | - env.Execute('$PYTHONEXE -m pip install {}'.format(p)) |
16 | | - |
17 | | -import microros_utils.library_builder as library_builder |
| 3 | +import os |
| 4 | +import shutil |
18 | 5 |
|
19 | 6 | ########################## |
20 | 7 | #### Global variables #### |
|
36 | 23 | } |
37 | 24 |
|
38 | 25 | project_options = env.GetProjectConfig().items(env=env["PIOENV"], as_dict=True) |
| 26 | +main_path = os.path.realpath(".") |
39 | 27 | global_env = DefaultEnvironment() |
40 | 28 | board = env['BOARD'] |
41 | 29 | framework = env['PIOFRAMEWORK'][0] |
42 | | -main_path = os.path.realpath(".") |
43 | 30 | extra_packages_path = "{}/extra_packages".format(env['PROJECT_DIR']) |
44 | 31 |
|
45 | 32 | selected_board_meta = boards_metas[board] if board in boards_metas else "colcon.meta" |
|
56 | 43 | # Do not include build folder |
57 | 44 | env['SRC_FILTER'] += ' -<build/include/*>' |
58 | 45 |
|
| 46 | +################################ |
| 47 | +#### Library custom targets #### |
| 48 | +################################ |
| 49 | + |
| 50 | +def clean_microros_callback(*args, **kwargs): |
| 51 | + library_path = main_path + '/libmicroros' |
| 52 | + build_path = main_path + '/build' |
| 53 | + |
| 54 | + # Delete library and build folders |
| 55 | + shutil.rmtree(library_path, ignore_errors=True) |
| 56 | + shutil.rmtree(build_path, ignore_errors=True) |
| 57 | + |
| 58 | + print("micro-ROS library cleaned!") |
| 59 | + os._exit(0) |
| 60 | + |
| 61 | +env.AddPlatformTarget("clean_microros", None, clean_microros_callback) |
| 62 | + |
| 63 | +def build_microros(*args, **kwargs): |
| 64 | + ############################## |
| 65 | + #### Install dependencies #### |
| 66 | + ############################## |
| 67 | + |
| 68 | + pip_packages = [x.split("==")[0] for x in os.popen('{} -m pip freeze'.format(env['PYTHONEXE'])).read().split('\n')] |
| 69 | + required_packages = ["catkin-pkg", "lark-parser", "empy", "colcon-common-extensions", "importlib-resources", "pyyaml", "pytz", "markupsafe==2.0.1"] |
| 70 | + if all([x in pip_packages for x in required_packages]): |
| 71 | + print("All required Python pip packages are installed") |
| 72 | + |
| 73 | + for p in [x for x in required_packages if x not in pip_packages]: |
| 74 | + print('Installing {} with pip at PlatformIO environment'.format(p)) |
| 75 | + env.Execute('$PYTHONEXE -m pip install {}'.format(p)) |
| 76 | + |
| 77 | + import microros_utils.library_builder as library_builder |
| 78 | + |
| 79 | + ################################# |
| 80 | + #### Build micro-ROS library #### |
| 81 | + ################################# |
| 82 | + |
| 83 | + print("Configuring {} with transport {}".format(board, microros_transport)) |
| 84 | + |
| 85 | + cmake_toolchain = library_builder.CMakeToolchain( |
| 86 | + main_path + "/platformio_toolchain.cmake", |
| 87 | + env['CC'], |
| 88 | + env['CXX'], |
| 89 | + env['AR'], |
| 90 | + "{} {} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='".format(' '.join(env['CFLAGS']), ' '.join(env['CCFLAGS'])), |
| 91 | + "{} {} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='".format(' '.join(env['CXXFLAGS']), ' '.join(env['CCFLAGS'])) |
| 92 | + ) |
59 | 93 |
|
60 | | -################################# |
61 | | -#### Build micro-ROS library #### |
62 | | -################################# |
| 94 | + builder = library_builder.Build(library_folder=main_path, packages_folder=extra_packages_path) |
| 95 | + builder.run('{}/metas/{}'.format(main_path, selected_board_meta), cmake_toolchain.path, microros_user_meta) |
63 | 96 |
|
64 | | -print("Configuring {} with transport {}".format(board, microros_transport)) |
| 97 | + ####################################################### |
| 98 | + #### Add micro-ROS library/includes to environment #### |
| 99 | + ####################################################### |
65 | 100 |
|
66 | | -cmake_toolchain = library_builder.CMakeToolchain( |
67 | | - main_path + "/platformio_toolchain.cmake", |
68 | | - env['CC'], |
69 | | - env['CXX'], |
70 | | - env['AR'], |
71 | | - "{} {} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='".format(' '.join(env['CFLAGS']), ' '.join(env['CCFLAGS'])), |
72 | | - "{} {} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='".format(' '.join(env['CXXFLAGS']), ' '.join(env['CCFLAGS'])) |
73 | | -) |
| 101 | + # Add library |
| 102 | + if (board == "portenta_h7_m7" or board == "nanorp2040connect"): |
| 103 | + # Workaround for including the library in the linker group |
| 104 | + # This solves a problem with duplicated symbols in Galactic |
| 105 | + global_env["_LIBFLAGS"] = "-Wl,--start-group " + global_env["_LIBFLAGS"] + " -l{} -Wl,--end-group".format(builder.library_name) |
| 106 | + else: |
| 107 | + global_env.Append(LIBS=[builder.library_name]) |
74 | 108 |
|
75 | | -builder = library_builder.Build(library_folder=main_path, packages_folder=extra_packages_path) |
76 | | -builder.run('{}/metas/{}'.format(main_path, selected_board_meta), cmake_toolchain.path, microros_user_meta) |
| 109 | + # Add library path |
| 110 | + global_env.Append(LIBPATH=[builder.library_path]) |
77 | 111 |
|
78 | | -####################################################### |
79 | | -#### Add micro-ROS library/includes to environment #### |
80 | | -####################################################### |
| 112 | + # Add required defines |
| 113 | + global_env.Append(CPPDEFINES=[("CLOCK_MONOTONIC", 1)]) |
81 | 114 |
|
82 | | -# Add library |
83 | | -if (board == "portenta_h7_m7" or board == "nanorp2040connect"): |
84 | | - # Workaround for including the library in the linker group |
85 | | - # This solves a problem with duplicated symbols in Galactic |
86 | | - global_env["_LIBFLAGS"] = "-Wl,--start-group " + global_env["_LIBFLAGS"] + " -l{} -Wl,--end-group".format(builder.library_name) |
87 | | -else: |
88 | | - global_env.Append(LIBS=[builder.library_name]) |
| 115 | + # Add micro-ROS include path |
| 116 | + global_env.Append(CPPPATH=[main_path + "/libmicroros/include"]) |
89 | 117 |
|
90 | | -# Add library path |
91 | | -global_env.Append(LIBPATH=[builder.library_path]) |
| 118 | + # Add micro-ROS include path to library include path |
| 119 | + env.Append(CPPPATH=[main_path + "/libmicroros/include"]) |
92 | 120 |
|
93 | | -# Add required defines |
94 | | -global_env.Append(CPPDEFINES=[("CLOCK_MONOTONIC", 1)]) |
| 121 | + # Add platformio library general include path |
| 122 | + global_env.Append(CPPPATH=[ |
| 123 | + main_path + "/platform_code", |
| 124 | + main_path + "/platform_code/{}/{}".format(framework, microros_transport)]) |
95 | 125 |
|
96 | | -# Add micro-ROS include path |
97 | | -global_env.Append(CPPPATH=[main_path + "/build/libmicroros/include"]) |
| 126 | + # Add platformio library general to library include path |
| 127 | + env.Append(CPPPATH=[ |
| 128 | + main_path + "/platform_code", |
| 129 | + main_path + "/platform_code/{}/{}".format(framework, microros_transport)]) |
98 | 130 |
|
99 | | -# Add micro-ROS include path to library include path |
100 | | -env.Append(CPPPATH=[main_path + "/build/libmicroros/include"]) |
| 131 | + # Add micro-ROS defines to user application |
| 132 | + global_env.Append(CPPDEFINES=[('MICRO_ROS_TRANSPORT_{}_{}'.format(framework.upper(), microros_transport.upper()), 1)]) |
| 133 | + global_env.Append(CPPDEFINES=[('MICRO_ROS_DISTRO_ {} '.format(microros_distro.upper()), 1)]) |
101 | 134 |
|
102 | | -# Add platformio library general include path |
103 | | -global_env.Append(CPPPATH=[ |
104 | | - main_path + "/platform_code", |
105 | | - main_path + "/platform_code/{}/{}".format(framework, microros_transport)]) |
| 135 | + # Add platformio library for Arduino framework |
| 136 | + if 'arduino' == framework: |
| 137 | + # Include path for Arduino framework |
| 138 | + global_env.Append(CPPPATH=[main_path + "/arduino"]) |
| 139 | + # Clock implementation for Arduino framework |
| 140 | + env['SRC_FILTER'] += ' +<platform_code/arduino/clock_gettime.cpp>' |
106 | 141 |
|
107 | | -# Add platformio library general to library include path |
108 | | -env.Append(CPPPATH=[ |
109 | | - main_path + "/platform_code", |
110 | | - main_path + "/platform_code/{}/{}".format(framework, microros_transport)]) |
| 142 | + # Add transport sources according to the framework and the transport |
| 143 | + env['SRC_FILTER'] += ' +<platform_code/{}/{}/micro_ros_transport.cpp>'.format(framework, microros_transport) |
111 | 144 |
|
112 | | -# Add micro-ROS defines to user application |
113 | | -global_env.Append(CPPDEFINES=[('MICRO_ROS_TRANSPORT_{}_{}'.format(framework.upper(), microros_transport.upper()), 1)]) |
114 | | -global_env.Append(CPPDEFINES=[('MICRO_ROS_DISTRO_ {} '.format(microros_distro.upper()), 1)]) |
115 | 145 |
|
116 | | -# Add platformio library for Arduino framework |
117 | | -if 'arduino' == framework: |
118 | | - # Include path for Arduino framework |
119 | | - global_env.Append(CPPPATH=[main_path + "/arduino"]) |
120 | | - # Clock implementation for Arduino framework |
121 | | - env['SRC_FILTER'] += ' +<platform_code/arduino/clock_gettime.cpp>' |
| 146 | +from SCons.Script import COMMAND_LINE_TARGETS |
122 | 147 |
|
123 | | -# Add transport sources according to the framework and the transport |
124 | | -env['SRC_FILTER'] += ' +<platform_code/{}/{}/micro_ros_transport.cpp>'.format(framework, microros_transport) |
| 148 | +if "clean_microros" not in COMMAND_LINE_TARGETS: |
| 149 | + build_microros() |
0 commit comments