Skip to content
This repository was archived by the owner on Jan 14, 2023. It is now read-only.

Commit 808ba65

Browse files
committed
a rebuild avoidance check integrated into the catkin api.
1 parent 1051904 commit 808ba65

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

cmake/genjava-catkin-api.cmake.em

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ macro(generate_rosjava_messages)
4141
ALL
4242
COMMAND ${CATKIN_ENV} ${PYTHON_EXECUTABLE} ${GENJAVA_BIN}
4343
${verbosity}
44+
--avoid-rebuilding
4445
-o ${CMAKE_CURRENT_BINARY_DIR}
4546
-p ${ARG_PACKAGES} # this has to be a list argument so it separates each arg (not a single string!)
4647
DEPENDS

src/genjava/genjava_main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def standalone_parse_arguments(argv):
9090
parser.add_argument('-o', '--output-dir', action='store', default='build', help='output directory for the java code (e.g. build/foo_msgs)')
9191
parser.add_argument('-v', '--verbose', default=False, action='store_true', help='enable verbosity in debugging (false)')
9292
parser.add_argument('-f', '--fakeit', default=False, action='store_true', help='dont build, just list the packages it would build (false)')
93+
parser.add_argument('-a', '--avoid-rebuilding', default=False, action='store_true', help='avoid rebuilding if the working directory is already present (false)')
9394
parsed_arguments = parser.parse_args(argv)
9495
return parsed_arguments
9596

@@ -105,7 +106,15 @@ def standalone_main(argv):
105106

106107
sorted_package_tuples = rosjava_build_tools.catkin.index_message_package_dependencies_from_local_environment(package_name_list=args.packages)
107108

109+
print("")
108110
print("Generating message artifacts for: \n%s" % [p.name for (unused_relative_path, p) in sorted_package_tuples])
111+
did_not_rebuild_these_packages = []
109112
if not args.fakeit:
110113
for unused_relative_path, p in sorted_package_tuples:
111-
gradle_project.standalone_create_and_build(p.name, args.output_dir, args.verbose)
114+
result = gradle_project.standalone_create_and_build(p.name, args.output_dir, args.verbose, args.avoid_rebuilding)
115+
if not result:
116+
did_not_rebuild_these_packages.append(p.name)
117+
if did_not_rebuild_these_packages:
118+
print("")
119+
print("Skipped re-generation of these message artifacts (clean first): %s" % did_not_rebuild_these_packages)
120+
print("")

src/genjava/gradle_project.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,20 @@ def build(msg_pkg_name, output_dir, verbosity):
172172
subprocess.call(cmd, stderr=subprocess.STDOUT,)
173173

174174

175-
def standalone_create_and_build(msg_pkg_name, output_dir, verbosity):
175+
def standalone_create_and_build(msg_pkg_name, output_dir, verbosity, avoid_rebuilding=False):
176176
'''
177-
Brute force create and build the message artifact distregarding any smarts
177+
Brute force create and build the message artifact disregarding any smarts
178178
such as whether message files changed or not. For use with the standalone
179179
package builder.
180+
:param str msg_pkg_name:
181+
:param str output_dir:
182+
:param bool verbosity:
183+
:param bool avoid_rebuilding: don't rebuild if working dir is already there
184+
:return bool : whether it built, or skipped because it was avoiding a rebuild
180185
'''
186+
genjava_gradle_dir = os.path.join(output_dir, msg_pkg_name)
187+
if os.path.exists(genjava_gradle_dir) and avoid_rebuilding:
188+
return False
181189
create(msg_pkg_name, output_dir)
182190
working_directory = os.path.join(os.path.abspath(output_dir), msg_pkg_name)
183191
gradle_wrapper = os.path.join(os.path.abspath(output_dir), msg_pkg_name, 'gradlew')
@@ -186,3 +194,4 @@ def standalone_create_and_build(msg_pkg_name, output_dir, verbosity):
186194
cmd.append('--quiet')
187195
#print("COMMAND........................%s" % cmd)
188196
subprocess.call(cmd, stderr=subprocess.STDOUT,)
197+
return True

0 commit comments

Comments
 (0)