Port of selflink.py from compat to core.

Bug: 64879
Change-Id: I893d5e4275a2d9fdc695925930dae7589c07d372
Merge "Port of selflink.py from compat to core."