Using a shared subproject.

414 views
Skip to first unread message

Hemmo Nieminen

unread,
Apr 8, 2015, 3:07:20 PM4/8/15
to meson...@googlegroups.com
Hi,

Can this be achieved somehow?

Have three projects A, B and C.

A depends on B and C.
B depends on C.

Fulfill the dependencies by defining the dependency as the dependent's
subproject.

Compile project A.

With my current setting I'm getting an error "Second call to project()"
when the project C is defined as a subproject "for the second time".


--
Hemmo

Jussi Pakkanen

unread,
Apr 8, 2015, 3:16:26 PM4/8/15
to Hemmo Nieminen, meson...@googlegroups.com
That should not be happening. There is code in Meson that detects when you are trying to use a subproject multiple times and just returns the old cached result object. If it does not work then it's a bug. I'll try to look into this soon.

Just to be sure, are you calling into the subprojects with the "subproject" function every time and _not_ with "subdir"?

Hemmo Nieminen

unread,
Apr 8, 2015, 3:38:21 PM4/8/15
to Jussi Pakkanen, meson...@googlegroups.com
On 22:16 Wed 08 Apr, Jussi Pakkanen wrote:
> On Wed, Apr 8, 2015 at 10:07 PM, Hemmo Nieminen <hemmo.n...@iki.fi>
> wrote:
>
>
> > Can this be achieved somehow?
> >
> > Have three projects A, B and C.
> >
> > A depends on B and C.
> > B depends on C.
> >
> > Fulfill the dependencies by defining the dependency as the dependent's
> > subproject.
> >
> > Compile project A.
> >
> > With my current setting I'm getting an error "Second call to project()"
> > when the project C is defined as a subproject "for the second time".
> >
>
> That should not be happening. There is code in Meson that detects when you
> are trying to use a subproject multiple times and just returns the old
> cached result object. If it does not work then it's a bug. I'll try to look
> into this soon.

I made a test that tries to reproduce this. I made it quite hastily
(after reading your reply) so there might be some errors there, but at
least it gave me the same error I'm seeing with my actual project.

> Just to be sure, are you calling into the subprojects with the "subproject"
> function every time and _not_ with "subdir"?

Pretty sure.


--
Hemmo
0001-Add-a-test-case-for-shared-subproject.patch

Hemmo Nieminen

unread,
Apr 8, 2015, 3:59:31 PM4/8/15
to meson...@googlegroups.com, Hemmo Nieminen
Signed-off-by: Hemmo Nieminen <hemmo.n...@iki.fi>
---

Notes:
Forgot to add a source file for the project A.

test cases/common/79 shared subproject/a.c | 13 +++++++++++++
test cases/common/79 shared subproject/meson.build | 9 +++++++++
test cases/common/79 shared subproject/subprojects/B/b.c | 5 +++++
.../common/79 shared subproject/subprojects/B/meson.build | 4 ++++
test cases/common/79 shared subproject/subprojects/C/c.c | 5 +++++
.../common/79 shared subproject/subprojects/C/meson.build | 2 ++
6 files changed, 38 insertions(+)
create mode 100644 test cases/common/79 shared subproject/a.c
create mode 100644 test cases/common/79 shared subproject/meson.build
create mode 100644 test cases/common/79 shared subproject/subprojects/B/b.c
create mode 100644 test cases/common/79 shared subproject/subprojects/B/meson.build
create mode 100644 test cases/common/79 shared subproject/subprojects/C/c.c
create mode 100644 test cases/common/79 shared subproject/subprojects/C/meson.build

diff --git a/test cases/common/79 shared subproject/a.c b/test cases/common/79 shared subproject/a.c
new file mode 100644
index 0000000..bc0b97a
--- /dev/null
+++ b/test cases/common/79 shared subproject/a.c
@@ -0,0 +1,13 @@
+char func_b(void);
+char func_c(void);
+
+int
+main()
+{
+ char b = func_b(), c = func_c();
+
+ if (b == 'b' && c == 'c')
+ return 0;
+
+ return -1;
+}
diff --git a/test cases/common/79 shared subproject/meson.build b/test cases/common/79 shared subproject/meson.build
new file mode 100644
index 0000000..370eb13
--- /dev/null
+++ b/test cases/common/79 shared subproject/meson.build
@@ -0,0 +1,9 @@
+project('A', 'c')
+
+B = subproject('B')
+b = B.get_variable('b')
+
+C = subproject('C')
+c = C.get_variable('c')
+
+a = executable('a', 'a.c', link_with : [ b, c ])
diff --git a/test cases/common/79 shared subproject/subprojects/B/b.c b/test cases/common/79 shared subproject/subprojects/B/b.c
new file mode 100644
index 0000000..2ee5a42
--- /dev/null
+++ b/test cases/common/79 shared subproject/subprojects/B/b.c
@@ -0,0 +1,5 @@
+char
+func_b()
+{
+ return 'b';
+}
diff --git a/test cases/common/79 shared subproject/subprojects/B/meson.build b/test cases/common/79 shared subproject/subprojects/B/meson.build
new file mode 100644
index 0000000..280c60c
--- /dev/null
+++ b/test cases/common/79 shared subproject/subprojects/B/meson.build
@@ -0,0 +1,4 @@
+project('B', 'c')
+C = subproject('C')
+c = C.get_variable('c')
+b = shared_library('b', 'b.c', link_with : c)
diff --git a/test cases/common/79 shared subproject/subprojects/C/c.c b/test cases/common/79 shared subproject/subprojects/C/c.c
new file mode 100644
index 0000000..ff47251
--- /dev/null
+++ b/test cases/common/79 shared subproject/subprojects/C/c.c
@@ -0,0 +1,5 @@
+char
+func_c()
+{
+ return 'c';
+}
diff --git a/test cases/common/79 shared subproject/subprojects/C/meson.build b/test cases/common/79 shared subproject/subprojects/C/meson.build
new file mode 100644
index 0000000..abf0b1e
--- /dev/null
+++ b/test cases/common/79 shared subproject/subprojects/C/meson.build
@@ -0,0 +1,2 @@
+project('C', 'c')
+c = shared_library('c', 'c.c')
--
2.3.5

Jussi Pakkanen

unread,
Apr 8, 2015, 4:35:01 PM4/8/15
to Hemmo Nieminen, meson...@googlegroups.com
On Wed, Apr 8, 2015 at 10:38 PM, Hemmo Nieminen <hemmo.n...@iki.fi> wrote:
 
I made a test that tries to reproduce this. I made it quite hastily
(after reading your reply) so there might be some errors there, but at
least it gave me the same error I'm seeing with my actual project.

Thanks, this is fixed now in trunk. Just a few minor niggles, you seemed to forget to add a.c so I whipped one up. The code was also indented with tabs, whereas Meson uses only spaces. Fixed that too.
 

Hemmo Nieminen

unread,
Apr 8, 2015, 5:19:03 PM4/8/15
to Jussi Pakkanen, meson...@googlegroups.com
Not so fast. :)

This now seems to work only if the subprojects are processed in the order
they were in the test 79. If you reverse the order of the subprojects it
seems to fall apart again.

Attaching patches...


--
Hemmo
0001-Fix-a-typo-in-test-79-shared-subproject.patch
0002-Add-a-second-shared-subproject-test.patch

Jussi Pakkanen

unread,
Apr 8, 2015, 5:52:35 PM4/8/15
to Hemmo Nieminen, meson...@googlegroups.com
On Thu, Apr 9, 2015 at 12:18 AM, Hemmo Nieminen <hemmo.n...@iki.fi> wrote:
 
Not so fast. :)

This now seems to work only if the subprojects are processed in the order
they were in the test 79. If you reverse the order of the subprojects it
seems to fall apart again.

Thanks for the tests, now fixed in trunk.
 
Reply all
Reply to author
Forward
0 new messages