Sunday, March 25, 2012

Update ctags with brew

Update ctags with brew

The "ctags" coming with Mac OS is really a very old one (1993). We can update it with brew, and I think this Article is very useful.

The point is:

  • Install latest ctags with brew: brew install ctags. This should be OK
  • Replace "ctags" with:
    1. alias ctags="`brew --prefix`/bin/ctags"
    2. alias ctags >> ~/.bash_profile
    3. Please note that the original post uses ~/.bashrc but it won't work in Mac OS. So use ~/.bash_profile instead

`brew --prefix` will display the install path of brew, and append it with /bin/ctags will get the new ctags pathname. Please note that "`" is the character with the key "~" on your keyboard.

Friday, March 23, 2012

xpidl.py runs error on Mac OS

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 :)