Using source files from one target into another

25 views
Skip to first unread message

Nikola Janevski

unread,
Jun 16, 2017, 12:40:59 PM6/16/17
to gyp-developer
Hi,

Is it possible to use source files from one target in another in the same file. Here is an example:
{
  'target_name': 'hello',
  'sources': [
    'kitty.cc',
  ],
  'target_name': 'hello_another_compiler',
  'actions': [
{
 'action_name': 'make_hello_another_compiler',
 'inputs': [
'<hello@sources'
 ],
 'outputs': ['hello_another_compiler.exe'],
 'action': [
'compile.bat',
'<(inputs)',
 ],
},
  ]
}

I want to reuse the sources specified in the first target as inputs for the custom action in the second target. That way I don't need to have duplicate copies of the filenames. The line in red is ideally something what I am looking for. I can just say "use the sources from the target hello". If not is there another way to achieve this in gyp? My goal is not to duplicate the files because it makes life harder for people that need to maintain it.


Thanks,
Nikola

Refael Ackermann

unread,
Jun 16, 2017, 12:49:30 PM6/16/17
to gyp-developer
Going on intuition (as in, not tested, but I think I've seen it work somewhere):
Define the list as a variable, then reuse it as much as you want.

Dirk Pranke

unread,
Jun 16, 2017, 1:26:20 PM6/16/17
to Refael Ackermann, gyp-developer
Yup, do that :).

-- Dirk

--

---
You received this message because you are subscribed to the Google Groups "gyp-developer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gyp-developer+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikola Janevski

unread,
Jun 16, 2017, 2:19:43 PM6/16/17
to gyp-developer, ref...@gmail.com
I tried that but I think I am not assigning the variables correctly cause I am getting an error when building.

For my example above let's say I did this:
'variables': {
  'source_files': ['hello.cc, 'kitty.cc']
},
'targets': [
{
  'target_name': 'hello',
  'sources':'<(source_files)',
}
{
  'target_name': 'hello_another_compiler',
  'actions': [
{
  'action_name': 'make_hello_another_compiler',
  'inputs': '<(source_files)'
  'outputs': ['hello_another_compiler.exe'],
  'action': [
'compile.bat',
'<(inputs)',
  ],
},
  ]
}
]

I am getting a problem with my compilation that wasn't there before. I am guessing that either I am not assigning it correctly or maybe not even declaring it correctly.
To unsubscribe from this group and stop receiving emails from it, send an email to gyp-develope...@googlegroups.com.

Nikola Janevski

unread,
Jun 16, 2017, 2:33:16 PM6/16/17
to gyp-developer, ref...@gmail.com
The error I am getting when doing git runhooks is:
TypeError: can only concatenate list (not "str") to list

If I use the original list instead of the variable (in this line  'sources':'<(source_files)',) it works.

Refael Ackermann

unread,
Jun 16, 2017, 2:47:40 PM6/16/17
to Nikola Janevski, gyp-developer

'variables': {
  'source_files': ['hello.cc, 'kitty.cc']
},
'targets': [
{
  'target_name': 'hello',
  'sources':'<@(source_files)',
}

Nikola Janevski

unread,
Jun 16, 2017, 2:50:37 PM6/16/17
to gyp-developer, njan...@google.com
I tried that but I am getting an error:
ValueError: Variable expansion in this context permits str and int only, found list for sources. Any idea why? I even tried using this <!@

Refael Ackermann

unread,
Jun 16, 2017, 2:53:08 PM6/16/17
to Nikola Janevski, gyp-developer
Sorry probably need to be 'sources':['<@(source_files)'],

To unsubscribe from this group and stop receiving emails from it, send an email to gyp-developer+unsubscribe@googlegroups.com.

Nikola Janevski

unread,
Jun 16, 2017, 2:53:45 PM6/16/17
to gyp-developer, njan...@google.com
Placing it in square brackets helped. Like this: ['<@(source_files)']

Refael Ackermann

unread,
Jun 16, 2017, 2:55:10 PM6/16/17
to Nikola Janevski, gyp-developer
🎉

To unsubscribe from this group and stop receiving emails from it, send an email to gyp-developer+unsubscribe@googlegroups.com.

Nikola Janevski

unread,
Jun 16, 2017, 4:34:35 PM6/16/17
to gyp-developer, njan...@google.com, Sébastien Marchand
+1 sebmarchand

Thanks helped me a lot.
Reply all
Reply to author
Forward
0 new messages