xpidl.py runs error on Mac OS X
I write firefox extension so I want to write it under Mac OS. However, I have trouble in generating the .xpt file from a .idl.
I use typelib.py which included in Gecko SDK to generate the xpt file, when I specify the command looks like this:
../../xulrunner-sdk/sdk/bin/typelib.py --cachedir=./ -I ../../xulrunner-sdk/idl ./components/xxx.idl -o ./components/xxx.xpt
I get error looks like this:
Traceback (most recent call last):
File "../../xulrunner-sdk/sdk/bin/typelib.py", line 317, in
idl = p.parse(text, filename=file)
File "/Users/xx/xulrunner-sdk/sdk/bin/xpidl.py", line 1475, in parse
idl = self.parser.parse(lexer=self)
File "/Users/xx/xulrunner-sdk/sdk/bin/ply/yacc.py", line 265, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/Users/xx/xulrunner-sdk/sdk/bin/ply/yacc.py", line 921, in parseopt_notrack
lookahead = get_token() # Get the next token
File "/Users/xx/xulrunner-sdk/sdk/bin/xpidl.py", line 1464, in token
t = self.lexer.token()
File "/Users/xx/xulrunner-sdk/sdk/bin/ply/lex.py", line 384, in token
newtok = self.lexerrorf(tok)
File "/Users/xx/xulrunner-sdk/sdk/bin/xpidl.py", line 1150, in t_ANY_error
lexpos=self.lexer.lexpos))
xpidl.IDLError: error: unrecognized input, ./components/xxx.idl line 1:26
#include "nsISupports.idl"
^
I searched the web but can't get any hint, so I research it myself, and found out that it is caused the "newline" on Mac is "\r" but the python code used to parse the idl file is using "\n".
So it will be easy to fix this problem:
# xulrunner-sdk/sdk/sdk/bin/xpidl.py
# line: 1475
data = data.replace('\r', '\n') # add this line
self.lexer.input(data)
So the problem is solved :)