0

I want many gyp scripts to have a common target. So I decided to move it to a separate include file. Simplest test-case that produces an error:

foo.gyp

{
    'includes'  : [
        'bar.gypi',
    ],
}

bar.gypi

{
    'targets': [
        {
            'target_name' : 'phony',
            'type' :    'none',
            'actions' : [
                {
                    'action_name' : '_phony_',
                    'inputs' :  ['',],
                    'outputs' : ['',],
                    'action' :  ['_phony_',],
                    'message' : '_phony_',
                },
            ],
        },
    ],
}

Produces error:

IndexError: string index out of range while reading includes of foo.gyp while tr ying to load foo.gyp

Some observations:

  • If I delete actions from target, everything parses well

  • If I move targets (with actions) to foo.gyp, everything parses well

Am I doing something wrong?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Kolyunya
  • 5,973
  • 7
  • 46
  • 81

1 Answers1

2

It looks like the "outputs" list can not be empty or contain an empty string:

# gyp/make.py:893
self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0]))

You may have empty inputs but in this case the phony action will shoot only once. I haven't found any mentions of phony actions in the GYP documentation, but I have the following variant working:

# bar.gypi
{
'targets': [
  {
    'target_name'   :   'phony',
    'type'          :   'none',
    'actions'       :   [
      {
        'action_name'   :   '_phony_',
        'inputs'        :   ['./bar.gypi'], # The action depends on this file
        'outputs'       :   ['test'],       # Some dummy file
        'action'        :   ['echo', 'test'],
        'message'       :   'Running phony target',
      },
    ],
  },
],

}

I could try to find a better way if you tell me more about the task you are trying to solve.

roman-kashitsyn
  • 539
  • 3
  • 14
  • Thank you for an answer. Adding elements to `inputs` and `outputs` fixed the problem. I just want to have a target `clean` which should invoke python script deleting build artifacts. Logically there are no inputs or outputs in this action if I get it right. – Kolyunya Aug 08 '13 at 10:08
  • `You may have empty inputs but in this case the phony action will shoot only once`. Do I get it right that it will shot each time I invoke a target? If `inputs` are empty and `outputs` have one `phony` element which doesn't exist the action must shoot according to the docs. – Kolyunya Aug 08 '13 at 10:15
  • I've tried to leave inputs empty but this makes my `make phony` to run the action only once. So I think that it's good idea to use `*.gypi` file as input (I've also saw that trick in gyp's unit tests). – roman-kashitsyn Aug 08 '13 at 13:08
  • In addition, I've found it convenient to use a separate trivial "proxy" `Makefile` that runs `gyp` with `--generator-output` parameter (so my source tree isn't polluted by generated files) and performs simple actions like `clean`. – roman-kashitsyn Aug 08 '13 at 13:15