@@ -99,46 +99,98 @@ def _create_meson_script(configureParameters):
99
99
root = detect_root (ctx .attr .lib_source )
100
100
data = ctx .attr .data + ctx .attr .build_data
101
101
102
- # Generate a list of arguments for meson
103
- options_str = " " .join ([
104
- "-D{}=\" {}\" " .format (key , ctx .attr .options [key ])
105
- for key in ctx .attr .options
106
- ])
102
+ if attrs .tool_prefix :
103
+ tool_prefix = "{} " .format (
104
+ expand_locations_and_make_variables (ctx , attrs .tool_prefix , "tool_prefix" , data ),
105
+ )
106
+ else :
107
+ tool_prefix = ""
108
+
109
+ meson_path = "{tool_prefix}{meson_path}" .format (
110
+ tool_prefix = tool_prefix ,
111
+ meson_path = attrs .meson_path ,
112
+ )
107
113
108
- prefix = "{} " . format ( expand_locations_and_make_variables ( ctx , attrs . tool_prefix , "tool_prefix" , data )) if attrs . tool_prefix else ""
114
+ target_args = dict ( ctx . attr . target_args )
109
115
110
- setup_args_str = " " .join (expand_locations_and_make_variables (ctx , ctx .attr .setup_args , "setup_args" , data ))
116
+ # --- TODO: DEPRECATED, delete on a future release ------------------------
117
+ # Convert the deprecated arguments into the new target_args argument. Fail
118
+ # if there's a deprecated argument being used together with its new
119
+ # target_args (e.g. setup_args and a "setup" target_args).
111
120
112
- script .append ("{prefix}{meson} setup --prefix={install_dir} {setup_args} {options} {source_dir}" .format (
113
- prefix = prefix ,
114
- meson = attrs .meson_path ,
115
- install_dir = "$$INSTALLDIR$$" ,
116
- setup_args = setup_args_str ,
117
- options = options_str ,
118
- source_dir = "$$EXT_BUILD_ROOT$$/" + root ,
119
- ))
121
+ deprecated = [
122
+ ("setup" , ctx .attr .setup_args ),
123
+ ("compile" , ctx .attr .build_args ),
124
+ ("install" , ctx .attr .install_args ),
125
+ ]
126
+
127
+ for target_name , args_ in deprecated :
128
+ if args_ and target_name in target_args :
129
+ fail ("Please migrate '{t}_args' to 'target_args[\" {t}\" ]'" .format (t = target_name ))
130
+
131
+ target_args [target_name ] = args_
132
+
133
+ # --- TODO: DEPRECATED, delete on a future release ------------------------
120
134
121
- build_args = [] + ctx .attr .build_args
122
- build_args_str = " " .join ([
123
- ctx .expand_location (arg , data )
124
- for arg in build_args
125
- ])
135
+ # Expand target args
136
+ for target_name , args_ in target_args .items ():
137
+ if target_name == "setup" :
138
+ args = expand_locations_and_make_variables (ctx , args_ , "setup_args" , data )
139
+ else :
140
+ args = [ctx .expand_location (arg , data ) for arg in args_ ]
126
141
127
- script .append ("{prefix}{meson} compile {args}" .format (
128
- prefix = prefix ,
129
- meson = attrs .meson_path ,
130
- args = build_args_str ,
142
+ target_args [target_name ] = args
143
+
144
+ script .append ("{meson} setup --prefix={install_dir} {setup_args} {options} {source_dir}" .format (
145
+ meson = meson_path ,
146
+ install_dir = "$$INSTALLDIR$$" ,
147
+ setup_args = " " .join (target_args .get ("setup" , [])),
148
+ options = " " .join ([
149
+ "-D{}=\" {}\" " .format (key , ctx .attr .options [key ])
150
+ for key in ctx .attr .options
151
+ ]),
152
+ source_dir = "$$EXT_BUILD_ROOT$$/" + root ,
131
153
))
132
154
133
- if ctx .attr .install :
134
- install_args = " " .join ([
135
- ctx .expand_location (arg , data )
136
- for arg in ctx .attr .install_args
137
- ])
138
- script .append ("{prefix}{meson} install {args}" .format (
139
- prefix = prefix ,
140
- meson = attrs .meson_path ,
141
- args = install_args ,
155
+ targets = ctx .attr .targets
156
+
157
+ # --- TODO: DEPRECATED, delete on a future release ------------------------
158
+ targets = [
159
+ t
160
+ for t in targets
161
+ if t != "install" or ctx .attr .install
162
+ ]
163
+ # --- TODO: DEPRECATED, delete on a future release ------------------------
164
+
165
+ # NOTE:
166
+ # introspect has an "old API" and doesn't work like other commands.
167
+ # It requires a builddir argument and it doesn't have a flag to output to a
168
+ # file, so it requires a redirect. And, most probably, it will remain like
169
+ # this for the foreseable future (see
170
+ # https://github.com/mesonbuild/meson/issues/8182#issuecomment-758183324).
171
+ #
172
+ # To keep things simple, we provide a basic API: users must supply the
173
+ # introspection JSON file in `out_data_files`, and we offer a sensible
174
+ # default for the introspect command that users can override if needed.
175
+ if "introspect" in targets :
176
+ if len (ctx .attr .out_data_files ) != 1 :
177
+ msg = "Meson introspect expects a single JSON filename via "
178
+ msg += "out_data_files; only one filename should be provided."
179
+ fail (msg )
180
+
181
+ introspect_file = ctx .attr .out_data_files [0 ]
182
+
183
+ introspect_args = ["$$BUILD_TMPDIR$$" ]
184
+ introspect_args += target_args .get ("introspect" , ["--all" , "--indent" ])
185
+ introspect_args += [">" , "$$INSTALLDIR$$/{}" .format (introspect_file )]
186
+
187
+ target_args ["introspect" ] = introspect_args
188
+
189
+ for target_name in targets :
190
+ script .append ("{meson} {target} {args}" .format (
191
+ meson = meson_path ,
192
+ target = target_name ,
193
+ args = " " .join (target_args .get (target_name , [])),
142
194
))
143
195
144
196
return script
@@ -153,26 +205,34 @@ def _attrs():
153
205
154
206
attrs .update ({
155
207
"build_args" : attr .string_list (
156
- doc = "Arguments for the Meson build command " ,
208
+ doc = "__deprecated__: please use `target_args` with `' build'` target key. " ,
157
209
mandatory = False ,
158
210
),
159
211
"install" : attr .bool (
160
- doc = "If True, the `meson install` comand will be performed after a build " ,
212
+ doc = "__deprecated__: please use `targets` if you want to skip install. " ,
161
213
default = True ,
162
214
),
163
215
"install_args" : attr .string_list (
164
- doc = "Arguments for the meson install command " ,
216
+ doc = "__deprecated__: please use `target_args` with `' install'` target key. " ,
165
217
mandatory = False ,
166
218
),
167
219
"options" : attr .string_dict (
168
- doc = (
169
- "Meson option entries to initialize (they will be passed with `-Dkey=value`)"
170
- ),
220
+ doc = "Meson `setup` options (converted to `-Dkey=value`)" ,
171
221
mandatory = False ,
172
222
default = {},
173
223
),
174
224
"setup_args" : attr .string_list (
175
- doc = "Arguments for the Meson setup command" ,
225
+ doc = "__deprecated__: please use `target_args` with `'setup'` target key." ,
226
+ mandatory = False ,
227
+ ),
228
+ "target_args" : attr .string_list_dict (
229
+ doc = "Dict of arguments for each of the Meson targets. The " +
230
+ "target name is the key and the list of args is the value." ,
231
+ mandatory = False ,
232
+ ),
233
+ "targets" : attr .string_list (
234
+ doc = "A list of targets to run. Defaults to ['compile', 'install']" ,
235
+ default = ["compile" , "install" ],
176
236
mandatory = False ,
177
237
),
178
238
})
0 commit comments