Skip to content

Commit 0501422

Browse files
committed
change genmsg output dir to catkin lib dir
1 parent 5dfe91f commit 0501422

File tree

5 files changed

+98
-57
lines changed

5 files changed

+98
-57
lines changed

CMakeLists.txt

+45-19
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,50 @@ find_package(catkin REQUIRED COMPONENTS)
55

66
find_package(Ruby)
77

8-
###################################
9-
## catkin specific configuration ##
10-
###################################
118
catkin_package(
12-
CATKIN_DEPENDS roslang rosgraph_msgs
13-
DEPENDS ruby
9+
CATKIN_DEPENDS roslang rosgraph_msgs
10+
DEPENDS ruby
1411
)
1512

13+
#
14+
# macro definitions
15+
#
16+
macro(rosruby_setup)
17+
set(ROSRUBY_DEVEL_LIB_DESTINATION ${CATKIN_DEVEL_PREFIX}/lib/ruby/vendor_ruby)
18+
set(ROSRUBY_LIB_DESTINATION ${CATKIN_GLOBAL_LIB_DESTINATION}/ruby/vendor_ruby)
19+
endmacro()
1620

17-
# all install targets should use catkin DESTINATION variables
18-
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
21+
macro(rosruby_generate_messages)
22+
add_custom_target(rosruby_genmsg_${PROJECT_NAME} ALL
23+
COMMAND rosrun rosruby rosruby_genmsg.py -d ${ROSRUBY_DEVEL_LIB_DESTINATION} ${ARGN})
24+
install(DIRECTORY ${ROSRUBY_DEVEL_LIB_DESTINATION}/msg/
25+
DESTINATION ${ROSRUBY_LIB_DESTINATION}/msg
26+
)
27+
install(DIRECTORY ${ROSRUBY_DEVEL_LIB_DESTINATION}/srv/
28+
DESTINATION ${ROSRUBY_LIB_DESTINATION}/srv
29+
)
30+
endmacro()
31+
32+
macro(rosruby_add_libraries)
33+
foreach(file ${ARGN})
34+
get_filename_component(fullpath ${file} ABSOLUTE)
35+
get_filename_component(name ${file} NAME)
36+
add_custom_target(rosruby_${name}_link ALL
37+
COMMAND ${CMAKE_COMMAND} -E create_symlink ${fullpath} ${ROSRUBY_DEVEL_LIB_DESTINATION}/${name}
38+
DEPENDS rosruby_devel_mkdir)
39+
endforeach()
40+
endmacro()
41+
#
42+
# end macro
43+
#
44+
45+
rosruby_setup()
46+
47+
rosruby_generate_messages(rosgraph_msgs std_msgs roscpp_tutorials)
48+
49+
add_custom_target(rosruby_devel_mkdir ALL
50+
COMMAND ${CMAKE_COMMAND} -E make_directory ${ROSRUBY_DEVEL_LIB_DESTINATION})
1951

20-
## Mark executable scripts (Python etc.) for installation
21-
## in contrast to setup.py, you can choose the destination
2252
install(PROGRAMS
2353
bin/rubyroscore
2454
samples/add_two_ints_client.rb
@@ -34,14 +64,10 @@ install(PROGRAMS
3464
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
3565
)
3666

37-
install(DIRECTORY lib/
38-
DESTINATION ${CATKIN_GLOBAL_LIB_DESTINATION}/ruby
39-
FILES_MATCHING PATTERN "*.rb"
40-
)
67+
rosruby_add_libraries(
68+
lib/ros.rb
69+
lib/ros)
4170

42-
## Mark other files for installation (e.g. launch and bag files, etc.)
43-
# install(FILES
44-
# # myfile1
45-
# # myfile2
46-
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
47-
# )
71+
install(DIRECTORY lib/
72+
DESTINATION ${ROSRUBY_LIB_DESTINATION}
73+
)

README.md

+33-21
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,28 @@ This project supports ruby ROS client. You can program intelligent robots by rub
1414
Requirements
1515
----------
1616
- ruby (1.8.7/1.9.3)
17-
- ROS (groovy)
17+
- ROS (hydro/groovy)
1818

1919
electric/fuerte
2020
---------
2121
If you are using electric or fuerte, please use v0.2.1.
2222

23+
24+
Install (binary)
25+
------------------
26+
If you want to use groovy,
27+
28+
```bash
29+
sudo apt-get install ros-groovy-rosruby
30+
```
31+
32+
and add RUBYLIB environmental variable.
33+
34+
```bash
35+
$ echo "export RUBYLIB=/opt/ros/groovy/lib/ruby/vendor_ruby" >> ~/.bashrc
36+
$ source ~/.bashrc
37+
```
38+
2339
Install from source
2440
---------------
2541
Install ROS and ruby first. ROS document is [http://ros.org/wiki/ROS/Installation](http://ros.org/wiki/ROS/Installation) .
@@ -37,25 +53,14 @@ $ catkin_make
3753
please add RUBYLIB environment variable, like below (if you are using bash).
3854

3955
```bash
40-
$ echo "export RUBYLIB=`rospack find rosruby`/lib" >> ~/.bashrc
56+
$ echo "export RUBYLIB=~/catkin_ws/devel/lib/ruby/vendor_ruby" >> ~/.bashrc
4157
$ source ~/.bashrc
4258
```
4359

44-
If you are using install environment for catkin....(advanced)
45-
---------------------------------------------------------------
46-
if you want to use rosruby in `install` environment,
47-
this means you are doing like this.
48-
49-
```bash
50-
$ catkin_make install
51-
$ source ~/catkin_ws/install/setup.bash
52-
```
60+
if you want to use install environment, please edit develop -> install
5361

54-
then you must use below RUBYLIB environment.
62+
export RUBYLIB=~/catkin_ws/install/lib/ruby/vendor_ruby
5563

56-
```bash
57-
export RUBYLIB=~/catkin_ws/install/lib/ruby
58-
```
5964

6065
Message generation
6166
-----------------------
@@ -66,14 +71,9 @@ generage rosruby messages.
6671
For example,
6772

6873
```bash
69-
$ rosrun rosruby rosruby_genmsg.py geometry_msgs nav_msgs
74+
$ rosrun rosruby rosruby_genmsg.py geometry_msgs nav_msgs -d ~/catkin_ws/devel/lib/ruby/vendor_ruby/
7075
```
7176

72-
Arguments are msg package names. If arguments are not given,
73-
that converts msg/srv to .rb which is needed by sample programs.
74-
75-
This generates message files in ~/.ros/rosruby directory.
76-
7777
Sample Source
7878
--------------
7979

@@ -205,3 +205,15 @@ $ rake yard
205205
```
206206
207207
You can access to the generated documents from [here](http://otl.github.com/rosruby/doc/).
208+
209+
210+
catkin and CMakeLists.txt
211+
-----------------------------
212+
213+
rosruby's CMakeLists.txt defines some macros for your package that uses rosruby.
214+
you can use these if you add `find_package(rosruby)` to CMakeLists.txt.
215+
216+
* rosruby_setup() : setup some macros and variables for rosruby
217+
* rosruby_generate_messages(message_pkg1 message_okg2 ...) : generates rosruby msg/srv files
218+
* rosruby_add_libraries(files or dirs) : install lib files for devel environment.
219+

Rakefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ Gem::PackageTask.new(rosruby_spec).define
4040
desc "Generate precompiled msg gem"
4141
task :msg_gem do
4242
target_msg_packages = "actionlib_msgs pr2_controllers_msgs std_msgs visualization_msgs actionlib_tutorials roscpp stereo_msgs geometry_msgs rosgraph_msgs tf nav_msgs sensor_msgs trajectory_msgs std_srvs"
43-
system("scripts/rosruby_genmsg.py #{target_msg_packages}")
43+
system("scripts/rosruby_genmsg.py #{target_msg_packages} -d /tmp/rosruby/")
4444
mkdir_p('msg_gem/lib')
45-
cp_r(Dir.glob("#{ENV['HOME']}/.ros/rosruby/msg_gen/ruby/*"), "msg_gem/lib/")
46-
cp_r(Dir.glob("#{ENV['HOME']}/.ros/rosruby/srv_gen/ruby/*"), "msg_gem/lib/")
45+
cp_r(Dir.glob("/tmp/rosruby/msg/*"), "msg_gem/lib/")
46+
cp_r(Dir.glob("/tmp/rosruby/srv/*"), "msg_gem/lib/")
4747
chdir('msg_gem') do
4848
namespace :msg do
4949
msg_spec = Gem::Specification.new do |s|

lib/ros.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
# add rospackage paths to $:.
1111
#
1212

13-
require 'ros/package'
1413
if not ENV['ROS_MASTER_URI']
1514
ENV['ROS_MASTER_URI'] = 'http://localhost:11311'
1615
puts "Warning: ROS_MASTER_URI is not set. Using #{ENV['ROS_MASTER_URI']}"
1716
end
1817

19-
ROS::load_manifest('rosruby')
20-
["#{ENV['HOME']}/.ros/rosruby/msg_gen/ruby", "#{ENV['HOME']}/.ros/rosruby/srv_gen/ruby"].each do |path|
21-
if File.exists?(path)
22-
if not $:.include?(path)
23-
$:.push(path)
18+
ENV['RUBYLIB'].split(':').each do |rubylib_path|
19+
["#{rubylib_path}/msg", "#{rubylib_path}/srv"].each do |path|
20+
if File.exists?(path)
21+
if not $:.include?(path)
22+
$:.push(path)
23+
end
2424
end
2525
end
2626
end

scripts/rosruby_genmsg.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,18 @@ def get_all_deps(packages):
4141

4242

4343
if __name__ == "__main__":
44-
if len(sys.argv) == 1:
45-
packages = ['std_msgs', 'rosgraph_msgs', 'roscpp_tutorials', 'actionlib_msgs', 'actionlib_tutorials', 'tf', 'nav_msgs']
46-
else:
47-
packages = sys.argv[1:]
48-
44+
import argparse
45+
parser = argparse.ArgumentParser(description='generate rosruby msg/srv files')
46+
parser.add_argument('packages', nargs='+')
47+
parser.add_argument('-d', '--output-dir')
48+
args = parser.parse_args()
49+
packages = args.packages
50+
base_dir = os.environ.get("HOME") + "/.ros/rosruby"
51+
if args.output_dir:
52+
base_dir = args.output_dir
4953
for pack in get_all_deps(packages):
5054
msg_dir = "%s/msg/"%get_pkg_dir(pack)
51-
base_dir = os.environ.get("HOME") + "/.ros/rosruby"
52-
msg_output_prefix = "%s/msg_gen/ruby"%base_dir
55+
msg_output_prefix = "%s/msg"%base_dir
5356
if os.path.exists(msg_dir):
5457
for file in os.listdir(msg_dir):
5558
base, ext = os.path.splitext(file)
@@ -58,7 +61,7 @@ def get_all_deps(packages):
5861
genmsg_ruby.gen_msg(msg_dir+file, msg_output_prefix)
5962

6063
srv_dir = "%s/srv/"%get_pkg_dir(pack)
61-
srv_output_prefix = "%s/srv_gen/ruby"%base_dir
64+
srv_output_prefix = "%s/srv"%base_dir
6265
if os.path.exists(srv_dir):
6366
for file in os.listdir(srv_dir):
6467
base, ext = os.path.splitext(file)

0 commit comments

Comments
 (0)