7 from .cmake
import NEWLINE_PLUS_8
8 from .util
import roscompile
10 FILES_TO_NOT_INSTALL = [
'CHANGELOG.rst',
'README.md',
'.travis.yml',
'bitbucket-pipelines.yml']
16 'exec': (
'TARGETS', {
'${CATKIN_PACKAGE_BIN_DESTINATION}': [
'RUNTIME DESTINATION']}),
17 'library': (
'TARGETS', {
'${CATKIN_PACKAGE_LIB_DESTINATION}': [
'ARCHIVE DESTINATION',
'LIBRARY DESTINATION'],
18 '${CATKIN_GLOBAL_BIN_DESTINATION}': [
'RUNTIME DESTINATION']}),
19 'headers': (
'FILES', {
'${CATKIN_PACKAGE_INCLUDE_DESTINATION}': [
'DESTINATION']}),
20 'misc': (
'FILES', {
'${CATKIN_PACKAGE_SHARE_DESTINATION}': [
'DESTINATION']})
25 """For a given catkin destination, return the matching install type.""" 26 for name, (kw, destination_map)
in INSTALL_CONFIGS.items():
27 if destination
in destination_map:
32 """For a given CMake command, determine the install type(s) that this command uses. 34 If there is a non-empty subfolder, we only return the install types if the command 35 installs into the catkin_destination with the given subfolder 38 for section
in cmd.get_sections(
'DESTINATION'):
39 the_folder = section.values[0]
40 if len(subfolder) > 0:
41 if subfolder
not in the_folder:
43 the_folder = the_folder.replace(
'/' + subfolder,
'')
51 """Find a section that matches the last word, assuming all the previous sections matched the other words. 53 Our definition of a CMake command section is ONE all-caps word followed by tokens. 54 Installing stuff requires these weird TWO word sections (i.e. ARCHIVE DESTINATION). 56 Ergo, we need to find the section that matches the second word, presuming the section 57 before matched the first word. 60 for section
in cmd.get_real_sections():
61 if section.name == words[i]:
63 if i < len(words) - 1:
75 for pattern
in patterns:
76 if pattern[0] == pattern[-1]
and pattern[0] ==
'"':
77 pattern = pattern[1:-1]
78 if fnmatch.fnmatch(item, pattern):
83 """Find the section matching the key and ensure the value is in it. 85 Key could be multiple words, see get_multiword_section. 86 If the appopriate section is not found, it adds it. 90 section = cmd.get_section(key)
95 if value
not in section.values:
99 cmd.add_section(key, [value],
SectionStyle(NEWLINE_PLUS_8))
103 """Ensure that the command has all the appropriate CMake sections with the matching catkin destinations. 105 If the subfolder is defined, the subfolder is appended to the catkin destination. 107 for destination, section_names
in destination_map.items():
108 for section_name
in section_names:
109 if len(subfolder) > 0:
110 destination = os.path.join(destination, subfolder)
115 empty_sections_to_remove = {}
116 for destination, section_names
in destination_map.items():
117 for section_name
in section_names:
118 parts = section_name.split()
120 empty_sections_to_remove[parts[0]] = destination
121 sections = cmd.get_real_sections()
123 for i, section
in enumerate(sections):
124 if section.name
not in empty_sections_to_remove
or len(section.values) != 0:
126 next_section = sections[i + 1]
127 dest = empty_sections_to_remove[section.name]
128 if next_section.name ==
'DESTINATION' and len(next_section.values) == 1
and next_section.values[0] == dest:
129 to_remove.append(section)
130 to_remove.append(next_section)
131 if len(to_remove) > 0:
132 for section
in to_remove:
133 cmd.sections.remove(section)
139 for cmd
in cmake.content_map[
'install']:
146 section_name, destination_map = INSTALL_CONFIGS[install_type]
147 if directory
and section_name ==
'FILES':
148 section_name =
'DIRECTORY' 153 cmake.remove_command(cmd)
159 items = [os.path.join(subfolder, item)
for item
in items]
162 section = cmd.get_section(section_name)
164 if section_name !=
'FILES':
166 section = cmd.get_section(
'DIRECTORY')
170 nonmatching_items = []
173 nonmatching_items.append(item)
174 items = nonmatching_items
177 section.values = [value
for value
in section.values
if value
in items]
178 items = [item
for item
in items
if item
not in section.values]
183 print(
'\tInstalling %s' %
', '.join(items))
186 cmd.add_section(section_name, items)
187 cmake.add_command(cmd)
191 section.values += items
199 if package.name
and package.source_code.has_header_files():
205 extra_files_by_folder = collections.defaultdict(list)
206 rel_paths = [obj.rel_fn
for obj
in package.launches + package.plugin_configs + package.urdf_files]
207 rel_paths += package.misc_files
208 for rel_path
in sorted(rel_paths):
209 if rel_path
in FILES_TO_NOT_INSTALL:
211 path, base = os.path.split(rel_path)
212 extra_files_by_folder[path].append(base)
214 for folder, files
in sorted(extra_files_by_folder.items()):
220 for cmd
in package.cmake.content_map[
'install']:
221 dir_section = cmd.get_section(
'DIRECTORY')
222 dest_sections = cmd.get_sections(
'DESTINATION')
224 if not dir_section
or not dest_sections:
226 directory = dir_section.values[0]
227 final_slash = directory[-1] ==
'/' 229 for section
in dest_sections:
230 destination = section.values[0]
231 if not final_slash
and destination.endswith(directory):
233 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)