Skip to content

Commit

Permalink
add meson.project() for modules to get proj info
Browse files Browse the repository at this point in the history
  • Loading branch information
annacrombie committed Jan 8, 2024
1 parent 9d64d54 commit 70fcd6a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/functions/meson.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
#include "functions/common.h"

extern const struct func_impl impl_tbl_meson[];
extern const struct func_impl impl_tbl_meson_internal[];
#endif
2 changes: 1 addition & 1 deletion src/functions/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ const struct func_impl *kernel_func_tbl[language_mode_count] = {
};

const struct func_impl *func_tbl[obj_type_count][language_mode_count] = {
[obj_meson] = { impl_tbl_meson, },
[obj_meson] = { impl_tbl_meson, impl_tbl_meson_internal, },
[obj_subproject] = { impl_tbl_subproject },
[obj_number] = { impl_tbl_number, impl_tbl_number, },
[obj_dependency] = { impl_tbl_dependency },
Expand Down
39 changes: 39 additions & 0 deletions src/functions/meson.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,42 @@ const struct func_impl impl_tbl_meson[] = {
{ "version", func_meson_version, tc_string },
{ NULL, NULL },
};

static enum iteration_result
compiler_dict_to_str_dict_iter(struct workspace *wk, void *_ctx, obj k, obj v)
{
obj_dict_set(wk, *(obj *)_ctx, make_str(wk, compiler_language_to_s(k)), v);
return ir_cont;
}

static obj
compiler_dict_to_str_dict(struct workspace *wk, obj d)
{
obj r;
make_obj(wk, &r, obj_dict);
obj_dict_foreach(wk, d, &r, compiler_dict_to_str_dict_iter);

return r;
}

static bool
func_meson_project(struct workspace *wk, obj _, uint32_t args_node, obj *res)
{
if (!interp_args(wk, args_node, NULL, NULL, NULL)) {
return false;
}

struct project *proj = current_project(wk);

make_obj(wk, res, obj_dict);
obj_dict_set(wk, *res, make_str(wk, "opts"), proj->opts);
obj_dict_set(wk, *res, make_str(wk, "compilers"), compiler_dict_to_str_dict(wk, proj->compilers));
obj_dict_set(wk, *res, make_str(wk, "args"), compiler_dict_to_str_dict(wk, proj->args));
obj_dict_set(wk, *res, make_str(wk, "link_args"), compiler_dict_to_str_dict(wk, proj->link_args));
return true;
}

const struct func_impl impl_tbl_meson_internal[] = {
{ "project", func_meson_project, tc_dict, true },
{ NULL, NULL },
};
5 changes: 5 additions & 0 deletions src/script/modules/_test.meson
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func multi_return(k str) -> int
return d[k]
endfunc

func project() -> dict[any]
return meson.project()
endfunc

return {
'identity': identity,
'append_global': append_global,
Expand All @@ -116,4 +120,5 @@ return {
'glob_arg': glob_arg,
'typed_list': typed_list,
'multi_return': multi_return,
'project': project,
}
5 changes: 5 additions & 0 deletions tests/project/muon/script_module/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ m.typed_list(['1', '2'])
assert(m.multi_return('a') == 1)
assert(m.multi_return('b') == 2)
assert(m.multi_return('c') == 0)

# test meson.project()
assert('c' not in m.project()['compilers'])
add_languages('c')
assert('c' in m.project()['compilers'])

0 comments on commit 70fcd6a

Please sign in to comment.