Class: FilePathUtils

Inherits:
Object show all
Defined in:
lib/ceedling/file_path_utils.rb

Constant Summary collapse

GLOB_MATCHER =
/[\*\?\{\}\[\]]/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_path?(path) ⇒ Boolean

return whether the given path is to be aggregated (no aggregation modifier defaults to same as +:)

Returns:

  • (Boolean)


58
59
60
# File 'lib/ceedling/file_path_utils.rb', line 58

def self.add_path?(path)
  return (path =~ /^-:/).nil?
end

.extract_path(path) ⇒ Object

extract directory path from between optional add/subtract aggregation modifiers and up to glob specifiers note: slightly different than File.dirname in that /files/foo remains /files/foo and does not become /files



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ceedling/file_path_utils.rb', line 37

def self.extract_path(path)
  path = path.sub(/^(\+|-):/, '')

  # find first occurrence of path separator followed by directory glob specifier: *, ?, {, }, [, ]
  find_index = (path =~ GLOB_MATCHER)

  # no changes needed (lop off final path separator)
  return path.chomp('/') if (find_index.nil?)

  # extract up to first glob specifier
  path = path[0..(find_index-1)]

  # lop off everything up to and including final path separator
  find_index = path.rindex('/')
  return path[0..(find_index-1)] if (not find_index.nil?)

  # return string up to first glob specifier if no path separator found
  return path
end

.extract_path_no_aggregation_operators(path) ⇒ Object

get path (and glob) lopping off optional +: / -: prefixed aggregation modifiers



63
64
65
# File 'lib/ceedling/file_path_utils.rb', line 63

def self.extract_path_no_aggregation_operators(path)
  return path.sub(/^(\+|-):/, '')
end

.os_executable_ext(executable) ⇒ Object



30
31
32
33
# File 'lib/ceedling/file_path_utils.rb', line 30

def self.os_executable_ext(executable)
  return executable.ext('.exe') if SystemWrapper.windows?
  return executable
end

.reform_glob(path) ⇒ Object

all the globs that may be in a path string work fine with one exception; to recurse through all subdirectories, the glob is dir// but our paths use convention of only dir/**



70
71
72
73
# File 'lib/ceedling/file_path_utils.rb', line 70

def self.reform_glob(path)
  return path if (path =~ /\/\*\*$/).nil?
  return path + '/**'
end

.standardize(path) ⇒ Object

standardize path to use ‘/’ path separator & have no trailing path separator



23
24
25
26
27
28
# File 'lib/ceedling/file_path_utils.rb', line 23

def self.standardize(path)
  path.strip!
  path.gsub!(/\\/, '/')
  path.chomp!('/')
  return path
end

Instance Method Details

#form_fail_results_filepath(filepath) ⇒ Object



127
128
129
# File 'lib/ceedling/file_path_utils.rb', line 127

def form_fail_results_filepath(filepath)
  return File.join( @configurator.project_test_results_path, File.basename(filepath).ext(@configurator.extension_testfail) )
end

#form_mocks_source_filelist(mocks) ⇒ Object



184
185
186
187
188
# File 'lib/ceedling/file_path_utils.rb', line 184

def form_mocks_source_filelist(mocks)
  list = (@file_wrapper.instantiate_file_list(mocks))
  sources = list.map{|file| "#{@configurator.cmock_mock_path}/#{file}#{@configurator.extension_source}"}
  return sources
end

#form_pass_results_filelist(path, files) ⇒ Object



195
196
197
198
# File 'lib/ceedling/file_path_utils.rb', line 195

def form_pass_results_filelist(path, files)
  list = @file_wrapper.instantiate_file_list(files)
  return list.pathmap("#{path}/%n#{@configurator.extension_testpass}")
end

#form_pass_results_filepath(filepath) ⇒ Object



123
124
125
# File 'lib/ceedling/file_path_utils.rb', line 123

def form_pass_results_filepath(filepath)
  return File.join( @configurator.project_test_results_path, File.basename(filepath).ext(@configurator.extension_testpass) )
end

#form_preprocessed_file_filepath(filepath) ⇒ Object



163
164
165
# File 'lib/ceedling/file_path_utils.rb', line 163

def form_preprocessed_file_filepath(filepath)
  return File.join( @configurator.project_test_preprocess_files_path, File.basename(filepath) )
end

#form_preprocessed_includes_list_filepath(filepath) ⇒ Object



167
168
169
# File 'lib/ceedling/file_path_utils.rb', line 167

def form_preprocessed_includes_list_filepath(filepath)
  return File.join( @configurator.project_test_preprocess_includes_path, File.basename(filepath) )
end

#form_preprocessed_mockable_headers_filelist(mocks) ⇒ Object



175
176
177
178
179
180
181
182
# File 'lib/ceedling/file_path_utils.rb', line 175

def form_preprocessed_mockable_headers_filelist(mocks)
  list = @file_wrapper.instantiate_file_list(mocks)
  headers = list.map do |file|
    module_name = File.basename(file).sub(/^#{@configurator.cmock_mock_prefix}/, '').sub(/\.[a-zA-Z]+$/,'')
    "#{@configurator.project_test_preprocess_files_path}/#{module_name}#{@configurator.extension_header}"
  end
  return headers
end

#form_release_build_asm_object_filepath(filepath) ⇒ Object



94
95
96
# File 'lib/ceedling/file_path_utils.rb', line 94

def form_release_build_asm_object_filepath(filepath)
  return File.join( @configurator.project_release_build_output_asm_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_release_build_asm_objects_filelist(files) ⇒ Object



102
103
104
# File 'lib/ceedling/file_path_utils.rb', line 102

def form_release_build_asm_objects_filelist(files)
  return (@file_wrapper.instantiate_file_list(files)).pathmap("#{@configurator.project_release_build_output_asm_path}/%n#{@configurator.extension_object}")
end

#form_release_build_c_list_filepath(filepath) ⇒ Object



106
107
108
# File 'lib/ceedling/file_path_utils.rb', line 106

def form_release_build_c_list_filepath(filepath)
  return File.join( @configurator.project_release_build_output_c_path, File.basename(filepath).ext(@configurator.extension_list) )
end

#form_release_build_c_object_filepath(filepath) ⇒ Object



90
91
92
# File 'lib/ceedling/file_path_utils.rb', line 90

def form_release_build_c_object_filepath(filepath)
  return File.join( @configurator.project_release_build_output_c_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_release_build_c_objects_filelist(files) ⇒ Object



98
99
100
# File 'lib/ceedling/file_path_utils.rb', line 98

def form_release_build_c_objects_filelist(files)
  return (@file_wrapper.instantiate_file_list(files)).pathmap("#{@configurator.project_release_build_output_c_path}/%n#{@configurator.extension_object}")
end

#form_release_build_cache_path(filepath) ⇒ Object

release ###



82
83
84
# File 'lib/ceedling/file_path_utils.rb', line 82

def form_release_build_cache_path(filepath)
  return File.join( @configurator.project_release_build_cache_path, File.basename(filepath) )
end

#form_release_dependencies_filelist(files) ⇒ Object



110
111
112
# File 'lib/ceedling/file_path_utils.rb', line 110

def form_release_dependencies_filelist(files)
  return (@file_wrapper.instantiate_file_list(files)).pathmap("#{@configurator.project_release_dependencies_path}/%n#{@configurator.extension_dependencies}")
end

#form_release_dependencies_filepath(filepath) ⇒ Object



86
87
88
# File 'lib/ceedling/file_path_utils.rb', line 86

def form_release_dependencies_filepath(filepath)
  return File.join( @configurator.project_release_dependencies_path, File.basename(filepath).ext(@configurator.extension_dependencies) )
end

#form_runner_filepath_from_test(filepath) ⇒ Object



131
132
133
# File 'lib/ceedling/file_path_utils.rb', line 131

def form_runner_filepath_from_test(filepath)
  return File.join( @configurator.project_test_runners_path, File.basename(filepath, @configurator.extension_source)) + @configurator.test_runner_file_suffix + @configurator.extension_source
end

#form_runner_object_filepath_from_test(filepath) ⇒ Object



139
140
141
# File 'lib/ceedling/file_path_utils.rb', line 139

def form_runner_object_filepath_from_test(filepath)
  return (form_test_build_c_object_filepath(filepath)).sub(/(#{@configurator.extension_object})$/, "#{@configurator.test_runner_file_suffix}\\1")
end

#form_temp_path(filepath, prefix = '') ⇒ Object

instance methods ##########



77
78
79
# File 'lib/ceedling/file_path_utils.rb', line 77

def form_temp_path(filepath, prefix='')
  return File.join( @configurator.project_temp_path, prefix + File.basename(filepath) )
end

#form_test_build_asm_object_filepath(filepath) ⇒ Object



147
148
149
# File 'lib/ceedling/file_path_utils.rb', line 147

def form_test_build_asm_object_filepath(filepath)
  return File.join( @configurator.project_test_build_output_asm_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_test_build_c_object_filepath(filepath) ⇒ Object



143
144
145
# File 'lib/ceedling/file_path_utils.rb', line 143

def form_test_build_c_object_filepath(filepath)
  return File.join( @configurator.project_test_build_output_c_path, File.basename(filepath).ext(@configurator.extension_object) )
end

#form_test_build_cache_path(filepath) ⇒ Object

tests ###



115
116
117
# File 'lib/ceedling/file_path_utils.rb', line 115

def form_test_build_cache_path(filepath)
  return File.join( @configurator.project_test_build_cache_path, File.basename(filepath) )
end

#form_test_build_list_filepath(filepath) ⇒ Object



159
160
161
# File 'lib/ceedling/file_path_utils.rb', line 159

def form_test_build_list_filepath(filepath)
  return File.join( @configurator.project_test_build_output_path, File.basename(filepath).ext(@configurator.extension_list) )
end

#form_test_build_map_filepath(filepath) ⇒ Object



155
156
157
# File 'lib/ceedling/file_path_utils.rb', line 155

def form_test_build_map_filepath(filepath)
  return File.join( @configurator.project_test_build_output_path, File.basename(filepath).ext(@configurator.extension_map) )
end

#form_test_build_objects_filelist(sources) ⇒ Object



171
172
173
# File 'lib/ceedling/file_path_utils.rb', line 171

def form_test_build_objects_filelist(sources)
  return (@file_wrapper.instantiate_file_list(sources)).pathmap("#{@configurator.project_test_build_output_c_path}/%n#{@configurator.extension_object}")
end

#form_test_dependencies_filelist(files) ⇒ Object



190
191
192
193
# File 'lib/ceedling/file_path_utils.rb', line 190

def form_test_dependencies_filelist(files)
  list = @file_wrapper.instantiate_file_list(files)
  return list.pathmap("#{@configurator.project_test_dependencies_path}/%n#{@configurator.extension_dependencies}")
end

#form_test_dependencies_filepath(filepath) ⇒ Object



119
120
121
# File 'lib/ceedling/file_path_utils.rb', line 119

def form_test_dependencies_filepath(filepath)
  return File.join( @configurator.project_test_dependencies_path, File.basename(filepath).ext(@configurator.extension_dependencies) )
end

#form_test_executable_filepath(filepath) ⇒ Object



151
152
153
# File 'lib/ceedling/file_path_utils.rb', line 151

def form_test_executable_filepath(filepath)
  return File.join( @configurator.project_test_build_output_path, File.basename(filepath).ext(@configurator.extension_executable) )
end

#form_test_filepath_from_runner(filepath) ⇒ Object



135
136
137
# File 'lib/ceedling/file_path_utils.rb', line 135

def form_test_filepath_from_runner(filepath)
  return filepath.sub(/#{TEST_RUNNER_FILE_SUFFIX}/, '')
end