5 from util
import roscompile
7 FILES_TO_NOT_INSTALL = [
'CHANGELOG.rst',
'README.md',
'.travis.yml',
'bitbucket-pipelines.yml']
13 'exec': (
'TARGETS', {
'${CATKIN_PACKAGE_BIN_DESTINATION}': [
'RUNTIME DESTINATION']}),
14 'library': (
'TARGETS', {
'${CATKIN_PACKAGE_LIB_DESTINATION}': [
'ARCHIVE DESTINATION',
'LIBRARY DESTINATION'],
15 '${CATKIN_GLOBAL_BIN_DESTINATION}': [
'RUNTIME DESTINATION']}),
16 'headers': (
'FILES', {
'${CATKIN_PACKAGE_INCLUDE_DESTINATION}': [
'DESTINATION']}),
17 'misc': (
'FILES', {
'${CATKIN_PACKAGE_SHARE_DESTINATION}': [
'DESTINATION']})
22 """ For a given catkin destination, return the matching install type """ 23 for name, (kw, destination_map)
in INSTALL_CONFIGS.iteritems():
24 if destination
in destination_map:
29 """ For a given CMake command, determine the install type(s) that this command uses. 31 If there is a non-empty subfolder, we only return the install types if the command 32 installs into the catkin_destination with the given subfolder """ 34 for section
in cmd.get_sections(
'DESTINATION'):
35 the_folder = section.values[0]
36 if len(subfolder) > 0:
37 if subfolder
not in the_folder:
39 the_folder = the_folder.replace(
'/' + subfolder,
'')
47 """ Our definition of a CMake command section is ONE all-caps word followed by tokens. 48 Installing stuff requires these weird TWO word sections (i.e. ARCHIVE DESTINATION). 50 Ergo, we need to find the section that matches the second word, presuming the section 51 before matched the first word. 54 for section
in cmd.get_real_sections():
55 if section.name == words[i]:
57 if i < len(words) - 1:
69 for pattern
in patterns:
70 if pattern[0] == pattern[-1]
and pattern[0] ==
'"':
71 pattern = pattern[1:-1]
72 if fnmatch.fnmatch(item, pattern):
77 """ This finds the appopriate section of the command (with a possibly multiword key, see get_multiword_section) 78 and ensures the given value is in it. If the appopriate section is not found, it adds it. """ 82 section = cmd.get_section(key)
87 if value
not in section.values:
91 cmd.add_section(key, [value])
95 """ For a given command and destination_map, ensure that the command has all 96 the appropriate CMake sections with the matching catkin destinations. 97 If the subfolder is defined, the subfolder is appended to the catkin destination.""" 98 for destination, section_names
in destination_map.iteritems():
99 for section_name
in section_names:
100 if len(subfolder) > 0:
101 destination = os.path.join(destination, subfolder)
106 empty_sections_to_remove = {}
107 for destination, section_names
in destination_map.iteritems():
108 for section_name
in section_names:
109 parts = section_name.split()
111 empty_sections_to_remove[parts[0]] = destination
112 sections = cmd.get_real_sections()
114 for i, section
in enumerate(sections):
115 if section.name
not in empty_sections_to_remove
or len(section.values) != 0:
117 next = sections[i + 1]
118 dest = empty_sections_to_remove[section.name]
119 if next.name ==
'DESTINATION' and len(next.values) == 1
and next.values[0] == dest:
120 to_remove.append(section)
121 to_remove.append(next)
122 if len(to_remove) > 0:
123 for section
in to_remove:
124 cmd.sections.remove(section)
130 for cmd
in cmake.content_map[
'install']:
137 section_name, destination_map = INSTALL_CONFIGS[install_type]
138 if directory
and section_name ==
'FILES':
139 section_name =
'DIRECTORY' 144 cmake.remove_command(cmd)
150 items = [os.path.join(subfolder, item)
for item
in items]
153 section = cmd.get_section(section_name)
155 if section_name !=
'FILES':
157 section = cmd.get_section(
'DIRECTORY')
161 nonmatching_items = []
164 nonmatching_items.append(item)
165 items = nonmatching_items
168 section.values = [value
for value
in section.values
if value
in items]
169 items = [item
for item
in items
if item
not in section.values]
174 print(
'\tInstalling',
', '.join(items))
177 cmd.add_section(section_name, items)
178 cmake.add_command(cmd)
181 section = cmd.get_section(section_name)
182 section.values += items
190 if package.name
and package.source_code.has_header_files():
196 extra_files_by_folder = collections.defaultdict(list)
197 rel_paths = [obj.rel_fn
for obj
in package.launches + package.plugin_configs] + package.misc_files
198 for rel_path
in sorted(rel_paths):
199 if rel_path
in FILES_TO_NOT_INSTALL:
201 path, base = os.path.split(rel_path)
202 extra_files_by_folder[path].append(base)
204 for folder, files
in extra_files_by_folder.iteritems():
210 for cmd
in package.cmake.content_map[
'install']:
211 dir_section = cmd.get_section(
'DIRECTORY')
212 dest_sections = cmd.get_sections(
'DESTINATION')
214 if not dir_section
or not dest_sections:
216 directory = dir_section.values[0]
217 final_slash = directory[-1] ==
'/' 219 for section
in dest_sections:
220 destination = section.values[0]
221 if not final_slash
and destination.endswith(directory):
223 section.values[0] = destination[:-len(directory) - 1]
def matches_patterns(item, patterns)
def check_complex_section(cmd, key, value)
def get_multiword_section(cmd, words)
def update_cplusplus_installs(package)
def fix_double_directory_installs(package)
def install_section_check(cmake, items, install_type, directory=False, subfolder='')
def update_misc_installs(package)
def remove_install_section(cmd, destination_map)
def get_commands_by_type(cmake, name, subfolder='')
def get_install_types(cmd, subfolder='')
def install_sections(cmd, destination_map, subfolder='')
def get_install_type(destination)