flgen 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -17
- data/lib/flgen/context.rb +16 -2
- data/lib/flgen/file_list.rb +71 -73
- data/lib/flgen/predefined_macros.yaml +12 -0
- data/lib/flgen/version.rb +1 -1
- data/lib/flgen.rb +1 -0
- metadata +5 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17c6dc413fbc743f3014c128fc304fee0459fbe5ecc3fc9e7f9d12f0d26427d0
|
4
|
+
data.tar.gz: 262aec83a71a59ca34904e8be6f81787c5075ba5b9ac1726fb9668b3aa4832db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5515a610870d4d9ff29db0cf01f09db1aa19beaa354c85894153e21732894d7f82a5d68ca959060aee97bf4791f6457a0ee61e06aaf4e69ed3a61fdf6051787
|
7
|
+
data.tar.gz: 5be5528a8aaa6d2ce79fa5fcf91adf9ed95977c5fedbb5a4c70a97164a2647862aa6231d0888dab7c5166495275c2f161bbfbad473b07ea00ad97f29b099e13d
|
data/README.md
CHANGED
@@ -34,14 +34,19 @@ FLGen prives APIs listed below to describe your filelists.
|
|
34
34
|
* Add the given directory to the list of include direcotries.
|
35
35
|
* `library_directory(path, from: nil)`
|
36
36
|
* Add the given directory to the list of library directories.
|
37
|
+
* `find_files(patterns, from: nil)`
|
38
|
+
* Return an array of filenames matching the given patterns strings.
|
39
|
+
* See [here](https://docs.ruby-lang.org/en/3.2/Dir.html#method-c-glob) for the format of a pattern string.
|
40
|
+
* `find_file(patterns, from: nil)`
|
41
|
+
* Return the first filename matching the given pattern strings.
|
42
|
+
* `file?(path, from: :current)`
|
43
|
+
* Return `true` if the given file exists.
|
44
|
+
* `directory?(path, from: :current)`
|
45
|
+
* Return `true` if the given directory exists.
|
37
46
|
* `define_macro(name, value = nil)`
|
38
47
|
* Define a text macro.
|
39
48
|
* `macro?(name)`/`macro_defined?(name)`
|
40
49
|
* Return `true` if the given macro is defined.
|
41
|
-
* `file?(path, from: :current)`
|
42
|
-
* Return `treu` if the given file exists.
|
43
|
-
* `directory?(path, from: :current)`
|
44
|
-
* Return `true` if the given directory exists.
|
45
50
|
* `env?(name)`
|
46
51
|
* Return `true` if the givne environment variable is defined.
|
47
52
|
* `env(name)`
|
@@ -54,7 +59,7 @@ FLGen prives APIs listed below to describe your filelists.
|
|
54
59
|
* If `tool` is specified the given argument is added only when `tool` is matched with the targe tool.
|
55
60
|
* `target_tool?(tool)`
|
56
61
|
* Return `true` if the given tool is matched with the targe tool.
|
57
|
-
* `default_search_path(**
|
62
|
+
* `default_search_path(**search_paths)`
|
58
63
|
* Change the default behavior when the `from` argument is not specified.
|
59
64
|
* `reset_default_search_path(*target_types)`
|
60
65
|
* Reset the default behavior when the `from` argument is not specified.
|
@@ -74,7 +79,9 @@ end
|
|
74
79
|
The `from` argument is to specify how to search the given file or directory. You can specify one of three below.
|
75
80
|
|
76
81
|
* a directory path
|
77
|
-
*
|
82
|
+
* Search the given file or directory from the directory path specified by the `from` argument.
|
83
|
+
* `:cwd`
|
84
|
+
* Search the given file or directory from the current working directory.
|
78
85
|
* `:current`
|
79
86
|
* Search the given file or directory from the directory where the current filelist is.
|
80
87
|
* `:root`
|
@@ -86,22 +93,22 @@ The `from` argument is to specify how to search the given file or directory. You
|
|
86
93
|
|
87
94
|
Default behaviors when the `from` argument is not spcified are listed below:
|
88
95
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
|
97
|
+
| API name | Default `from` argument |
|
98
|
+
|:------------------|:------------------------|
|
99
|
+
| source_file | :current |
|
100
|
+
| file_list | :root |
|
101
|
+
| library_file | :current |
|
102
|
+
| include_directory | :current |
|
103
|
+
| library_directory | :current |
|
104
|
+
| find_files | :current |
|
105
|
+
| find_file | :current |
|
99
106
|
|
100
107
|
You can change the above default behaviors by using the `default_search_path` API.
|
101
108
|
In addition, you can reset the default behaviors by using the `reset_default_search_path` API.
|
102
109
|
|
103
110
|
```ruby
|
104
|
-
|
111
|
+
default_search_path source_file: :root, file_list: :current
|
105
112
|
source_file 'foo.sv' # FLGen will search the 'foo.sv' file from the root directories.
|
106
113
|
file_list 'bar.list.rb' # FLGen will eaarch the 'bar.list.rb' file from the directory where this file list is.
|
107
114
|
|
data/lib/flgen/context.rb
CHANGED
@@ -4,6 +4,7 @@ module FLGen
|
|
4
4
|
class Context
|
5
5
|
def initialize(options)
|
6
6
|
@options = options
|
7
|
+
define_predefined_macros
|
7
8
|
end
|
8
9
|
|
9
10
|
attr_reader :options
|
@@ -35,7 +36,7 @@ module FLGen
|
|
35
36
|
else
|
36
37
|
[macro, value]
|
37
38
|
end
|
38
|
-
add_macro_definition(k
|
39
|
+
add_macro_definition(k, v, false)
|
39
40
|
end
|
40
41
|
|
41
42
|
def macros
|
@@ -95,8 +96,21 @@ module FLGen
|
|
95
96
|
arguments.none? { |arg| arg.type == :library_file && arg.path == file }
|
96
97
|
end
|
97
98
|
|
98
|
-
def
|
99
|
+
def define_predefined_macros
|
100
|
+
return unless options[:tool]
|
101
|
+
|
102
|
+
list_name = File.join(__dir__, 'predefined_macros.yaml')
|
103
|
+
list = YAML.safe_load_file(list_name, filename: list_name, symbolize_names: true)
|
104
|
+
list[options[:tool]]&.each { |macro| add_macro_definition(macro, nil, true) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def add_macro_definition(macro, value, predefined)
|
108
|
+
name = macro.to_sym
|
99
109
|
macros << name unless macros.include?(name)
|
110
|
+
add_macro_argument(name, value) unless predefined
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_macro_argument(name, value)
|
100
114
|
arguments
|
101
115
|
.delete_if { |argument| argument.type == :define && argument.name == name }
|
102
116
|
add_compile_argument(Arguments::Define.new(name, value))
|
data/lib/flgen/file_list.rb
CHANGED
@@ -6,11 +6,11 @@ module FLGen
|
|
6
6
|
@context = context
|
7
7
|
@path = path
|
8
8
|
@root_directories = extract_root
|
9
|
-
@default_search_path =
|
9
|
+
@default_search_path = init_default_search_path
|
10
10
|
end
|
11
11
|
|
12
|
-
def default_search_path(**
|
13
|
-
@default_search_path.update(
|
12
|
+
def default_search_path(**search_paths)
|
13
|
+
@default_search_path.update(search_paths)
|
14
14
|
end
|
15
15
|
|
16
16
|
def reset_default_search_path(*target_types)
|
@@ -18,50 +18,43 @@ module FLGen
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def file_list(path, from: nil, raise_error: true)
|
21
|
-
|
22
|
-
load_file_list(path, from, location, raise_error)
|
21
|
+
load_file_list(path, from, raise_error, caller_location)
|
23
22
|
end
|
24
23
|
|
25
24
|
def source_file(path, from: nil, raise_error: true)
|
26
|
-
|
27
|
-
add_file_entry(path, from, location, raise_error, :source_file)
|
25
|
+
add_entry(path, from, raise_error, __callee__, caller_location)
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
28
|
+
define_method(:library_file, instance_method(:source_file))
|
29
|
+
define_method(:include_directory, instance_method(:source_file))
|
30
|
+
define_method(:library_directory, instance_method(:source_file))
|
34
31
|
|
35
|
-
def
|
36
|
-
|
32
|
+
def find_files(patterns, from: nil, &block)
|
33
|
+
glob_files(patterns, from, __callee__, caller_location)
|
34
|
+
.then { |e| block_given? && (return e.each(&block)) || e.to_a }
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
40
|
-
|
37
|
+
def find_file(patterns, from: nil)
|
38
|
+
glob_files(patterns, from, __callee__, caller_location)
|
39
|
+
.first&.then { |f| block_given? && (return yield f) || f }
|
41
40
|
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
def include_directory(path, from: nil, raise_error: true)
|
46
|
-
location = caller_location
|
47
|
-
add_directory_entry(path, from, location, raise_error, :include_directory)
|
42
|
+
def file?(path, from: :current)
|
43
|
+
!extract_path(path, from, __callee__, caller_location).nil?
|
48
44
|
end
|
49
45
|
|
50
|
-
|
51
|
-
location = caller_location
|
52
|
-
add_directory_entry(path, from, location, raise_error, :library_directory)
|
53
|
-
end
|
46
|
+
define_method(:directory?, instance_method(:file?))
|
54
47
|
|
55
|
-
def
|
56
|
-
|
57
|
-
!extract_file_path(path, from, location, :file).nil?
|
48
|
+
def define_macro(macro, value = nil)
|
49
|
+
@context.define_macro(macro, value)
|
58
50
|
end
|
59
51
|
|
60
|
-
def
|
61
|
-
|
62
|
-
!extract_directory_path(path, from, location, :directory).nil?
|
52
|
+
def macro?(macro)
|
53
|
+
@context.macros.include?(macro.to_sym)
|
63
54
|
end
|
64
55
|
|
56
|
+
alias_method :macro_defined?, :macro?
|
57
|
+
|
65
58
|
def env?(name)
|
66
59
|
ENV.key?(name.to_s)
|
67
60
|
end
|
@@ -89,25 +82,25 @@ module FLGen
|
|
89
82
|
return nil if @path.empty?
|
90
83
|
|
91
84
|
Pathname
|
92
|
-
.new(@path)
|
93
|
-
.dirname
|
94
|
-
.descend
|
95
|
-
.select(&method(:repository_root?))
|
96
|
-
.map(&:to_s)
|
85
|
+
.new(@path).dirname.descend.select(&method(:repository_root?)).map(&:to_s)
|
97
86
|
end
|
98
87
|
|
99
88
|
def repository_root?(path)
|
100
89
|
File.exist?(path.join('.git').to_s)
|
101
90
|
end
|
102
91
|
|
103
|
-
def
|
104
|
-
|
92
|
+
def init_default_search_path
|
93
|
+
Hash.new { |_, key| key == :file_list ? :root : :current }
|
94
|
+
end
|
95
|
+
|
96
|
+
def load_file_list(path, from, raise_error, location)
|
97
|
+
unless (extracted_path = extract_path(path, from, :file_list, location))
|
105
98
|
raise_no_entry_error(path, location, raise_error)
|
106
99
|
return
|
107
100
|
end
|
108
101
|
|
109
102
|
# Need to File.realpath to resolve symblic link
|
110
|
-
list_path = File.realpath(
|
103
|
+
list_path = File.realpath(extracted_path)
|
111
104
|
file_list_already_loaded?(list_path) && return
|
112
105
|
|
113
106
|
@context.loaded_file_lists << list_path
|
@@ -119,59 +112,50 @@ module FLGen
|
|
119
112
|
@context.loaded_file_lists.include?(path)
|
120
113
|
end
|
121
114
|
|
122
|
-
def
|
123
|
-
unless (
|
115
|
+
def add_entry(path, from, raise_error, method_name, location)
|
116
|
+
unless (extracted_path = extract_path(path, from, method_name, location))
|
124
117
|
raise_no_entry_error(path, location, raise_error)
|
125
118
|
return
|
126
119
|
end
|
127
120
|
|
128
|
-
|
129
|
-
@context.__send__(method, file_path)
|
121
|
+
@context.__send__("add_#{method_name}", extracted_path)
|
130
122
|
end
|
131
123
|
|
132
|
-
def
|
133
|
-
unless
|
134
|
-
raise_no_entry_error(path, location, raise_error)
|
135
|
-
return
|
136
|
-
end
|
124
|
+
def raise_no_entry_error(path, location, raise_error)
|
125
|
+
return unless raise_error
|
137
126
|
|
138
|
-
|
139
|
-
@context.__send__(method, directory_path)
|
127
|
+
raise NoEntryError.new(path, location)
|
140
128
|
end
|
141
129
|
|
142
|
-
def
|
143
|
-
|
130
|
+
def glob_files(patterns, from, method_name, location)
|
131
|
+
search_root('', from, method_name, location)
|
132
|
+
.lazy.flat_map { |base| do_glob_files(patterns, base) }
|
144
133
|
end
|
145
134
|
|
146
|
-
def
|
147
|
-
|
135
|
+
def do_glob_files(patterns, base)
|
136
|
+
Dir.glob(Array(patterns), base: base)
|
137
|
+
.map { |path| File.join(base, path) }
|
138
|
+
.select(&File.method(:file?))
|
148
139
|
end
|
149
140
|
|
150
|
-
def
|
151
|
-
|
141
|
+
def caller_location
|
142
|
+
caller_locations(2, 1).first
|
152
143
|
end
|
153
144
|
|
154
|
-
def extract_path(path, from,
|
155
|
-
search_root(path, from,
|
145
|
+
def extract_path(path, from, method_name, location)
|
146
|
+
search_root(path, from, method_name, location)
|
156
147
|
.map { |root| File.expand_path(path, root) }
|
157
|
-
.find { |abs_path|
|
148
|
+
.find { |abs_path| exist_path?(abs_path, method_name) }
|
158
149
|
end
|
159
150
|
|
160
|
-
|
161
|
-
file_list: :root, source_file: :current, library_file: :current, file: :current,
|
162
|
-
include_directory: :current, library_directory: :current, directory: :current
|
163
|
-
}.freeze
|
151
|
+
FROM_KEYWORDS = [:cwd, :current, :local_root, :root].freeze
|
164
152
|
|
165
|
-
def search_root(path, from,
|
166
|
-
search_path = from || @default_search_path[
|
153
|
+
def search_root(path, from, method_name, location)
|
154
|
+
search_path = from || @default_search_path[method_name]
|
167
155
|
if absolute_path?(path)
|
168
156
|
['']
|
169
|
-
elsif search_path
|
170
|
-
|
171
|
-
elsif search_path == :local_root
|
172
|
-
[@root_directories.last]
|
173
|
-
elsif search_path == :root
|
174
|
-
@root_directories
|
157
|
+
elsif FROM_KEYWORDS.include?(search_path)
|
158
|
+
search_root_specified_by_keyword(search_path, location)
|
175
159
|
else
|
176
160
|
[search_path]
|
177
161
|
end
|
@@ -181,6 +165,15 @@ module FLGen
|
|
181
165
|
Pathname.new(path).absolute?
|
182
166
|
end
|
183
167
|
|
168
|
+
def search_root_specified_by_keyword(from_keyword, location)
|
169
|
+
case from_keyword
|
170
|
+
when :cwd then [Dir.pwd]
|
171
|
+
when :current then [current_directory(location)]
|
172
|
+
when :local_root then [@root_directories.last]
|
173
|
+
else @root_directories
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
184
177
|
def current_directory(location)
|
185
178
|
# From Ruby 3.1 Thread::Backtrace::Location#absolute_path returns nil
|
186
179
|
# for code string evaluated by eval methods
|
@@ -189,10 +182,15 @@ module FLGen
|
|
189
182
|
File.dirname(path)
|
190
183
|
end
|
191
184
|
|
192
|
-
|
193
|
-
|
185
|
+
METHODS_TARGETING_DIRECTORY =
|
186
|
+
[:include_directory, :library_directory, :directory?].freeze
|
194
187
|
|
195
|
-
|
188
|
+
def exist_path?(path, method_name)
|
189
|
+
if METHODS_TARGETING_DIRECTORY.include?(method_name)
|
190
|
+
File.directory?(path)
|
191
|
+
else
|
192
|
+
File.file?(path)
|
193
|
+
end
|
196
194
|
end
|
197
195
|
end
|
198
196
|
end
|
data/lib/flgen/version.rb
CHANGED
data/lib/flgen.rb
CHANGED
metadata
CHANGED
@@ -1,113 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taichi Ishitani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bump
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.10.0
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.10.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 3.12.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 3.12.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.40.0
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.40.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.21.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.21.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov-cobertura
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 2.1.0
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 2.1.0
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
111
13
|
description: Filelist generator
|
112
14
|
email:
|
113
15
|
- ishitani@pezy.co.jp
|
@@ -128,6 +30,7 @@ files:
|
|
128
30
|
- lib/flgen/file_list_formatter.rb
|
129
31
|
- lib/flgen/file_list_xsim_formatter.rb
|
130
32
|
- lib/flgen/formatter.rb
|
33
|
+
- lib/flgen/predefined_macros.yaml
|
131
34
|
- lib/flgen/source_file.rb
|
132
35
|
- lib/flgen/version.rb
|
133
36
|
- lib/flgen/vivado_tcl_formatter.rb
|
@@ -162,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
65
|
- !ruby/object:Gem::Version
|
163
66
|
version: '0'
|
164
67
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.5.3
|
166
69
|
signing_key:
|
167
70
|
specification_version: 4
|
168
71
|
summary: Filelist generator
|