This repository was archived by the owner on Jan 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathgenjava_main.py
More file actions
120 lines (105 loc) · 5.9 KB
/
genjava_main.py
File metadata and controls
120 lines (105 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Software License Agreement (BSD License)
#
# Copyright (c) 2014, Daniel Stonier.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
##############################################################################
# Imports
##############################################################################
from __future__ import print_function
import argparse
import os
#import sys
#import traceback
#import genmsg
#import genmsg.command_line
import rosjava_build_tools
import catkin_pkg.packages
from . import gradle_project
##############################################################################
# Methods
##############################################################################
def parse_arguments(argv):
parser = argparse.ArgumentParser(description='Generate java code for a single ros message.')
#parser.add_argument('-m', '--message', action='store', help='the message file')
parser.add_argument('-p', '--package', action='store', help='package to find the message file')
parser.add_argument('-o', '--output-dir', action='store', help='output directory for the java code (e.g. build/foo_msgs)')
parser.add_argument('-c', '--compile', default=False, action='store_true', help='switch to compile mode (default is generating mode)')
parser.add_argument('-v', '--verbosity', default=False, action='store_true', help='enable verbosity in debugging (false)')
# The include path has a special format, e.g.
# -Ifoo_msgs:/mnt/zaphod/ros/rosjava/hydro/src/foo_msgs/msg;-Istd_msgs:/opt/ros/hydro/share/std_msgs/cmake/../msg
#parser.add_argument('-I', '--include-path', action='append', help="include paths to the package and deps msg files")
#myargs = rospy.myargv(argv=sys.argv)
#return parser.parse_args(args=myargs[1:])
return parser.parse_args(argv)
##############################################################################
# Main
##############################################################################
def main(argv):
'''
Used as the builder for genjava on the fly as other message language interfaces
are built. There is a bit of smarts inside this to work out when msgs have
changed and so forth.
'''
args = parse_arguments(argv[1:])
#print("genjava %s/%s" % (args.package, args.message))
if not args.compile:
gradle_project.create(args.package, args.output_dir)
else:
gradle_project.build(args.package, args.output_dir, args.verbosity)
def standalone_parse_arguments(argv):
parser = argparse.ArgumentParser(description='Generate artifacts for any/all discoverable message packages.')
parser.add_argument('-p', '--packages', action='store', nargs='*', default=[], help='a list of packages to generate artifacts for')
parser.add_argument('-o', '--output-dir', action='store', default='build', help='output directory for the java code (e.g. build/foo_msgs)')
parser.add_argument('-v', '--verbose', default=False, action='store_true', help='enable verbosity in debugging (false)')
parser.add_argument('-f', '--fakeit', default=False, action='store_true', help='dont build, just list the packages it would build (false)')
parser.add_argument('-a', '--avoid-rebuilding', default=False, action='store_true', help='avoid rebuilding if the working directory is already present (false)')
parsed_arguments = parser.parse_args(argv)
return parsed_arguments
def standalone_main(argv):
'''
This guy is a brute force standalone message artifact generator. It parses
the environment looking for the package (or just all) you wish to
generate artifacts for.
'''
args = standalone_parse_arguments(argv[1:])
#print("genjava %s/%s/%s" % (args.package, args.output_dir, args.verbose))
sorted_package_tuples = rosjava_build_tools.catkin.index_message_package_dependencies_from_local_environment(package_name_list=args.packages)
print("")
print("Generating message artifacts for: \n%s" % [p.name for (unused_relative_path, p) in sorted_package_tuples])
did_not_rebuild_these_packages = []
if not args.fakeit:
for unused_relative_path, p in sorted_package_tuples:
result = gradle_project.standalone_create_and_build(p.name, args.output_dir, args.verbose, args.avoid_rebuilding)
if not result:
did_not_rebuild_these_packages.append(p.name)
if did_not_rebuild_these_packages:
print("")
print("Skipped re-generation of these message artifacts (clean first): %s" % did_not_rebuild_these_packages)
print("")