yaml-vfs 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaml-vfs/file_collector.rb +38 -40
- data/lib/yaml-vfs/utils.rb +3 -3
- data/lib/yaml-vfs/version.rb +1 -1
- data/lib/yaml-vfs/yaml_vfs.rb +157 -39
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e4890cc09e0ec81ac2207d17794117c63e5a75b11119df87560083c0affb2b6
|
4
|
+
data.tar.gz: c863931919a9d44647d17ce9612668f89aba9392c00cf515c4b5f5f97e7074c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72ee57fdaff9d9a559a7af00fae9be99355f3cffbde3ea6d88580609f8298153fcc383352b3a15bc268694be005697abfad10b53ecd83a02bc881ff9096bab00
|
7
|
+
data.tar.gz: c5acbf1325db6cf85bdaea38c7950e00ff057d6e5fef90d836a4bd770842b63e61c895251a42cd29e0e1e94c7dc9e5087886237852b5c5fd15323a822e233572
|
@@ -5,7 +5,6 @@ require 'set'
|
|
5
5
|
module VFS
|
6
6
|
HEADER_FILES_EXTENSIONS = %w[.h .hh .hpp .ipp .tpp .hxx .def .inl .inc].freeze
|
7
7
|
VFS_FILES_EXTENSIONS = %w[.yaml .yml .json].freeze
|
8
|
-
|
9
8
|
# vfs file collector entry
|
10
9
|
class FileCollectorEntry
|
11
10
|
attr_reader :real_path, :virtual_path
|
@@ -18,31 +17,22 @@ module VFS
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def self.entrys_from_framework(framework_path, public_headers, private_headers, real_modules)
|
21
|
-
entrys =
|
22
|
-
unless public_headers.empty?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
v_p = File.join(framework_path, 'PrivateHeaders', File.basename(header))
|
31
|
-
new(header, v_p)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
unless real_modules.empty?
|
35
|
-
entrys += real_modules.map do |m|
|
36
|
-
v_p = File.join(framework_path, 'Modules', File.basename(m))
|
37
|
-
new(m, v_p)
|
20
|
+
entrys = {}
|
21
|
+
entrys['Headers'] = public_headers unless public_headers.empty?
|
22
|
+
entrys['PrivateHeaders'] = private_headers unless private_headers.empty?
|
23
|
+
entrys['Modules'] = real_modules unless real_modules.empty?
|
24
|
+
|
25
|
+
entrys.flat_map do |key, values|
|
26
|
+
values.map do |path|
|
27
|
+
v_p = File.join(framework_path, key, File.basename(path))
|
28
|
+
new(path, v_p)
|
38
29
|
end
|
39
30
|
end
|
40
|
-
entrys
|
41
31
|
end
|
42
32
|
|
43
33
|
def self.entrys_from_framework_dir(framework_path, real_header_dir, real_modules_dir)
|
44
|
-
raise ArgumentError, 'real_header must set and exist'
|
45
|
-
raise ArgumentError, 'real_modules must set and exist'
|
34
|
+
raise ArgumentError, 'real_header must set and exist' unless File.exist?(real_header_dir || '')
|
35
|
+
raise ArgumentError, 'real_modules must set and exist' unless File.exist?(real_header_dir || '')
|
46
36
|
|
47
37
|
real_header_dir = File.join(real_header_dir, '**', '*')
|
48
38
|
real_headers = Pathname.glob(real_header_dir).select { |file| HEADER_FILES_EXTENSIONS.include?(file.extname) }
|
@@ -51,20 +41,16 @@ module VFS
|
|
51
41
|
end
|
52
42
|
|
53
43
|
def self.entrys_from_target(target_path, public_headers, private_headers)
|
54
|
-
entrys =
|
55
|
-
unless
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
entrys += public_headers.map do |header|
|
63
|
-
v_p = File.join(target_path, 'Headers', File.basename(header))
|
64
|
-
new(header, v_p)
|
44
|
+
entrys = {}
|
45
|
+
entrys['Headers'] = public_headers unless public_headers.empty?
|
46
|
+
entrys['PrivateHeaders'] = private_headers unless private_headers.empty?
|
47
|
+
|
48
|
+
entrys.flat_map do |key, values|
|
49
|
+
values.map do |path|
|
50
|
+
v_p = File.join(target_path, key, File.basename(path))
|
51
|
+
new(path, v_p)
|
65
52
|
end
|
66
53
|
end
|
67
|
-
entrys
|
68
54
|
end
|
69
55
|
|
70
56
|
def self.entrys_from_target_dir(target_path, public_dir, private_dir)
|
@@ -83,29 +69,41 @@ module VFS
|
|
83
69
|
|
84
70
|
# vfs gen
|
85
71
|
class FileCollector
|
72
|
+
EMPTY_VFS_FILE = '{"case-sensitive":"false","roots":[],"version":0}'
|
73
|
+
private_constant :EMPTY_VFS_FILE
|
86
74
|
def initialize(entrys)
|
87
75
|
@entrys = entrys || []
|
88
76
|
@vfs_writer = YAMLVFSWriter.new
|
89
77
|
end
|
90
78
|
|
91
79
|
def write_mapping(name)
|
92
|
-
add_write_file
|
93
|
-
@vfs_writer.case_sensitive = false
|
80
|
+
stream = add_write_file
|
94
81
|
path = Pathname(name).expand_path
|
95
82
|
unless VFS_FILES_EXTENSIONS.include?(File.extname(path))
|
96
83
|
path.mkpath unless path.exist?
|
97
84
|
path = path.join('all-product-headers.yaml')
|
98
85
|
end
|
99
|
-
stream
|
100
|
-
File.open(path, 'w') { |f| f.write(stream) }
|
86
|
+
update_changed_file(path, stream)
|
101
87
|
end
|
102
88
|
|
103
89
|
private
|
104
90
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
91
|
+
def update_changed_file(path, contents)
|
92
|
+
if path.exist?
|
93
|
+
content_stream = StringIO.new(contents)
|
94
|
+
identical = File.open(path, 'rb') { |f| FileUtils.compare_stream(f, content_stream) }
|
95
|
+
return if identical
|
108
96
|
end
|
97
|
+
path.dirname.mkpath
|
98
|
+
File.open(path, 'w') { |f| f.write(contents) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_write_file
|
102
|
+
return EMPTY_VFS_FILE if @entrys.empty?
|
103
|
+
|
104
|
+
@entrys.each { |entry| @vfs_writer.add_file_mapping(entry.virtual_path, entry.real_path) }
|
105
|
+
@vfs_writer.case_sensitive = false
|
106
|
+
@vfs_writer.write
|
109
107
|
end
|
110
108
|
end
|
111
109
|
end
|
data/lib/yaml-vfs/utils.rb
CHANGED
@@ -12,11 +12,11 @@ end
|
|
12
12
|
String.class_eval do
|
13
13
|
def indent(count, char = ' ')
|
14
14
|
gsub(/([^\n]*)(\n|$)/) do
|
15
|
-
last_iteration = (
|
15
|
+
last_iteration = (Regexp.last_match(1) == '' && Regexp.last_match(2) == '')
|
16
16
|
line = ''
|
17
17
|
line << (char * count) unless last_iteration
|
18
|
-
line <<
|
19
|
-
line <<
|
18
|
+
line << Regexp.last_match(1)
|
19
|
+
line << Regexp.last_match(2)
|
20
20
|
line
|
21
21
|
end
|
22
22
|
end
|
data/lib/yaml-vfs/version.rb
CHANGED
data/lib/yaml-vfs/yaml_vfs.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: false
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'json'
|
@@ -82,14 +82,6 @@ module VFS
|
|
82
82
|
|
83
83
|
private
|
84
84
|
|
85
|
-
def dir_indent
|
86
|
-
@dir_stack.length * 4
|
87
|
-
end
|
88
|
-
|
89
|
-
def file_indent
|
90
|
-
(@dir_stack.length + 1) * 4
|
91
|
-
end
|
92
|
-
|
93
85
|
def contained_in?(parent, path)
|
94
86
|
path.ascend { |p| break true if parent == p } || false
|
95
87
|
end
|
@@ -104,27 +96,24 @@ module VFS
|
|
104
96
|
def start_directory(path)
|
105
97
|
name = @dir_stack.empty? ? path : contained_part(@dir_stack.last, path)
|
106
98
|
@dir_stack << path
|
107
|
-
|
108
|
-
@stream
|
109
|
-
@stream
|
110
|
-
@stream
|
111
|
-
@stream += "'contents': [\n".indent(indent + 2)
|
99
|
+
@stream << '{'
|
100
|
+
@stream << "'type':'directory',"
|
101
|
+
@stream << "'name':\"#{name}\","
|
102
|
+
@stream << "'contents':["
|
112
103
|
end
|
113
104
|
|
114
105
|
def end_directory
|
115
|
-
|
116
|
-
@stream
|
117
|
-
@stream += '}'.indent(indent)
|
106
|
+
@stream << ']'
|
107
|
+
@stream << '}'
|
118
108
|
@dir_stack.pop
|
119
109
|
end
|
120
110
|
|
121
111
|
def write_entry(v_path, r_path)
|
122
|
-
|
123
|
-
@stream
|
124
|
-
@stream
|
125
|
-
@stream
|
126
|
-
@stream
|
127
|
-
@stream += '}'.indent(file_indent)
|
112
|
+
@stream << '{'
|
113
|
+
@stream << "'type':'file',"
|
114
|
+
@stream << "'name':\"#{v_path}\","
|
115
|
+
@stream << "'external-contents':\"#{r_path}\""
|
116
|
+
@stream << '}'
|
128
117
|
end
|
129
118
|
|
130
119
|
def overlay_dir_sub_rpath(use, overlay_dir, rpath)
|
@@ -137,24 +126,18 @@ module VFS
|
|
137
126
|
end
|
138
127
|
|
139
128
|
def write_yaml_header(use_external_names, case_sensitive, overlay_relative, _overlay_dir)
|
140
|
-
@stream = "{
|
141
|
-
@stream
|
142
|
-
@stream
|
129
|
+
@stream = "{'version':0,"
|
130
|
+
@stream << "'case-sensitive':'#{case_sensitive}'," unless case_sensitive.nil?
|
131
|
+
@stream << "'use-external-names':'#{use_external_names}'," unless use_external_names.nil?
|
143
132
|
use_overlay_relative = !overlay_relative.nil?
|
144
|
-
@stream
|
145
|
-
@stream
|
133
|
+
@stream << "'overlay_relative':'#{overlay_relative}'," if use_overlay_relative
|
134
|
+
@stream << "'roots':["
|
146
135
|
use_overlay_relative
|
147
136
|
end
|
148
137
|
|
149
138
|
def write_yaml_footer(entries)
|
150
|
-
unless entries.empty?
|
151
|
-
|
152
|
-
@stream += "\n"
|
153
|
-
end_directory
|
154
|
-
end
|
155
|
-
@stream += "\n"
|
156
|
-
end
|
157
|
-
@stream += " ]\n}\n"
|
139
|
+
end_directory until @dir_stack.empty? unless entries.empty?
|
140
|
+
@stream << ']}'
|
158
141
|
@stream
|
159
142
|
end
|
160
143
|
|
@@ -170,7 +153,6 @@ module VFS
|
|
170
153
|
def until_end_directory(dir)
|
171
154
|
dir_popped_from_stack = false
|
172
155
|
until @dir_stack.empty? || contained_in?(@dir_stack.last, dir)
|
173
|
-
@stream += "\n"
|
174
156
|
end_directory
|
175
157
|
dir_popped_from_stack = true
|
176
158
|
end
|
@@ -188,13 +170,149 @@ module VFS
|
|
188
170
|
|
189
171
|
def start_directory_or_return(dir, current_dir_empty, use_overlay_relative, overlay_dir, entry)
|
190
172
|
if dir == @dir_stack.last
|
191
|
-
@stream
|
173
|
+
@stream << ',' unless current_dir_empty
|
192
174
|
else
|
193
|
-
@stream
|
175
|
+
@stream << ',' if until_end_directory(dir) || !current_dir_empty
|
194
176
|
start_directory(dir)
|
195
177
|
current_dir_empty = true
|
196
178
|
end
|
197
179
|
use_overlay_relative_and_write_entry(use_overlay_relative, overlay_dir, current_dir_empty, entry)
|
198
180
|
end
|
199
181
|
end
|
182
|
+
# class JSONWriter
|
183
|
+
# attr_reader :dir_stack
|
184
|
+
|
185
|
+
# def write(entries, use_external_names, case_sensitive, overlay_relative, overlay_dir)
|
186
|
+
# use_overlay_relative = write_yaml_header(use_external_names, case_sensitive, overlay_relative, overlay_dir)
|
187
|
+
# unless entries.empty?
|
188
|
+
# current_dir_empty = write_root_entry(entries, use_overlay_relative, overlay_dir)
|
189
|
+
# entries.drop(1).reduce(current_dir_empty) do |empty, entry|
|
190
|
+
# dir = entry.directory? ? entry.v_path : entry.v_path.dirname
|
191
|
+
# start_directory_or_return(dir, empty, use_overlay_relative, overlay_dir, entry)
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
# write_yaml_footer(entries)
|
195
|
+
# end
|
196
|
+
|
197
|
+
# def initialize
|
198
|
+
# @dir_stack = []
|
199
|
+
# end
|
200
|
+
|
201
|
+
# private
|
202
|
+
|
203
|
+
# def dir_indent
|
204
|
+
# @dir_stack.length * 4
|
205
|
+
# end
|
206
|
+
|
207
|
+
# def file_indent
|
208
|
+
# (@dir_stack.length + 1) * 4
|
209
|
+
# end
|
210
|
+
|
211
|
+
# def contained_in?(parent, path)
|
212
|
+
# path.ascend { |p| break true if parent == p } || false
|
213
|
+
# end
|
214
|
+
|
215
|
+
# def contained_part(parent, path)
|
216
|
+
# raise ArgumentError if parent.nil?
|
217
|
+
# raise ArgumentError unless contained_in?(parent, path)
|
218
|
+
|
219
|
+
# path.relative_path_from(parent)
|
220
|
+
# end
|
221
|
+
|
222
|
+
# def start_directory(path)
|
223
|
+
# name = @dir_stack.empty? ? path : contained_part(@dir_stack.last, path)
|
224
|
+
# @dir_stack << path
|
225
|
+
# indent = dir_indent
|
226
|
+
# @stream += "{\n"
|
227
|
+
# @stream += "'type': 'directory',\n".indent(indent + 2)
|
228
|
+
# @stream += "'name': \"#{name}\",\n".indent(indent + 2)
|
229
|
+
# @stream += "'contents': [\n".indent(indent + 2)
|
230
|
+
# end
|
231
|
+
|
232
|
+
# def end_directory
|
233
|
+
# indent = dir_indent
|
234
|
+
# @stream += "]\n".indent(indent + 2)
|
235
|
+
# @stream += '}'
|
236
|
+
# @dir_stack.pop
|
237
|
+
# end
|
238
|
+
|
239
|
+
# def write_entry(v_path, r_path)
|
240
|
+
# indent = file_indent
|
241
|
+
# @stream += "{\n"
|
242
|
+
# @stream += "'type': 'file',\n".indent(indent + 2)
|
243
|
+
# @stream += "'name': \"#{v_path}\",\n".indent(indent + 2)
|
244
|
+
# @stream += "'external-contents': \"#{r_path}\"\n".indent(indent + 2)
|
245
|
+
# @stream += '}'.indent(file_indent)
|
246
|
+
# end
|
247
|
+
|
248
|
+
# def overlay_dir_sub_rpath(use, overlay_dir, rpath)
|
249
|
+
# if use
|
250
|
+
# raise ArgumentError, 'Overlay dir must be contained in RPath' unless rpath.fnmatch?("#{overlay_dir}*")
|
251
|
+
|
252
|
+
# rpath = rpath.relative_path_from(overlay_dir).expand_path
|
253
|
+
# end
|
254
|
+
# rpath
|
255
|
+
# end
|
256
|
+
|
257
|
+
# def write_yaml_header(use_external_names, case_sensitive, overlay_relative, _overlay_dir)
|
258
|
+
# @stream = "{\n 'version': 0,\n"
|
259
|
+
# @stream += " 'case-sensitive': '#{case_sensitive}',\n" unless case_sensitive.nil?
|
260
|
+
# @stream += " 'use-external-names': '#{use_external_names}',\n" unless use_external_names.nil?
|
261
|
+
# use_overlay_relative = !overlay_relative.nil?
|
262
|
+
# @stream += " 'overlay_relative': '#{overlay_relative}',\n" if use_overlay_relative
|
263
|
+
# @stream += " 'roots': [\n"
|
264
|
+
# use_overlay_relative
|
265
|
+
# end
|
266
|
+
|
267
|
+
# def write_yaml_footer(entries)
|
268
|
+
# unless entries.empty?
|
269
|
+
# until @dir_stack.empty?
|
270
|
+
# @stream += "\n"
|
271
|
+
# end_directory
|
272
|
+
# end
|
273
|
+
# @stream += "\n"
|
274
|
+
# end
|
275
|
+
# @stream += " ]\n}\n"
|
276
|
+
# @stream
|
277
|
+
# end
|
278
|
+
|
279
|
+
# def write_root_entry(entries, use_overlay_relative, overlay_dir)
|
280
|
+
# return true if entries.empty?
|
281
|
+
|
282
|
+
# f_entry = entries.first
|
283
|
+
# start_directory(f_entry.directory? ? f_entry.v_path : f_entry.v_path.dirname)
|
284
|
+
# current_dir_empty = f_entry.directory?
|
285
|
+
# use_overlay_relative_and_write_entry(use_overlay_relative, overlay_dir, current_dir_empty, f_entry)
|
286
|
+
# end
|
287
|
+
|
288
|
+
# def until_end_directory(dir)
|
289
|
+
# dir_popped_from_stack = false
|
290
|
+
# until @dir_stack.empty? || contained_in?(@dir_stack.last, dir)
|
291
|
+
# @stream += "\n"
|
292
|
+
# end_directory
|
293
|
+
# dir_popped_from_stack = true
|
294
|
+
# end
|
295
|
+
# dir_popped_from_stack
|
296
|
+
# end
|
297
|
+
|
298
|
+
# def use_overlay_relative_and_write_entry(use_overlay_relative, overlay_dir, current_dir_empty, entry)
|
299
|
+
# rpath = overlay_dir_sub_rpath(use_overlay_relative, overlay_dir, entry.r_path)
|
300
|
+
# unless entry.directory?
|
301
|
+
# write_entry(entry.v_path.basename, rpath)
|
302
|
+
# current_dir_empty = false
|
303
|
+
# end
|
304
|
+
# current_dir_empty
|
305
|
+
# end
|
306
|
+
|
307
|
+
# def start_directory_or_return(dir, current_dir_empty, use_overlay_relative, overlay_dir, entry)
|
308
|
+
# if dir == @dir_stack.last
|
309
|
+
# @stream += ",\n" unless current_dir_empty
|
310
|
+
# else
|
311
|
+
# @stream += ",\n" if until_end_directory(dir) || !current_dir_empty
|
312
|
+
# start_directory(dir)
|
313
|
+
# current_dir_empty = true
|
314
|
+
# end
|
315
|
+
# use_overlay_relative_and_write_entry(use_overlay_relative, overlay_dir, current_dir_empty, entry)
|
316
|
+
# end
|
317
|
+
# end
|
200
318
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-vfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cat1237
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|