2019年10月19日 星期六

AttributeError: 'NoneType' object has no attribute 'rstrip

Full error log:
yulin@WNC:/work/yulin/cat9640$ repo forall -c "pwd"                                 
Traceback (most recent call last):                                                 
  File "/work/yulin/cat9640/.repo/repo/main.py", line 531, in                
    _Main(sys.argv[1:])                                                             
  File "/work/yulin/cat9640/.repo/repo/main.py", line 507, in _Main                 
    result = repo._Run(argv) or 0                                                   
  File "/work/yulin/cat9640/.repo/repo/main.py", line 180, in _Run                 
    result = cmd.Execute(copts, cargs)                                             
  File "/work/yulin/cat9640/.repo/repo/subcmds/forall.py", line 226, in Execute     
    projects = self.GetProjects(args, groups=opt.groups)                           
  File "/work/yulin/cat9640/.repo/repo/command.py", line 140, in GetProjects       
    all_projects_list = manifest.projects                                           
  File "/work/yulin/cat9640/.repo/repo/manifest_xml.py", line 350, in projects     
    self._Load()                                                                   
  File "/work/yulin/cat9640/.repo/repo/manifest_xml.py", line 428, in _Load         
    self._ParseManifest(nodes)                                                     
  File "/work/yulin/cat9640/.repo/repo/manifest_xml.py", line 481, in _ParseManifest
    remote = self._ParseRemote(node)                                               
  File "/work/yulin/cat9640/.repo/repo/manifest_xml.py", line 657, in _ParseRemote 
    return _XmlRemote(name, alias, fetch, pushUrl, manifestUrl, review, revision)   
  File "/work/yulin/cat9640/.repo/repo/manifest_xml.py", line 78, in __init__       
    self.resolvedFetchUrl = self._resolveFetchUrl()                                 
  File "/work/yulin/cat9640/.repo/repo/manifest_xml.py", line 88, in _resolveFetchUrl
    manifestUrl = self.manifestUrl.rstrip('/')                                     
AttributeError: 'NoneType' object has no attribute 'rstrip'                         
yulin@WNC:/work/yulin/cat9640$                                                     

Debug#1
Refer to https://groups.google.com/forum/#!topic/android-building/0QkvGAQJ_Kg.
Adding alias to remotes fails to fix this issue.

Debug#2
 Add debug logs in manifest_xml.py
----------------------------------------------------------------------------------------------------------
class _XmlRemote(object):
  def __init__(self,
               name,
    ...
    self.revision = revision   
+ print('Yulin._XmlRemote.__init__:name=',name,'fetch=',fetch,'pushUrl=',pushUrl,'manifestUrl=',manifestUrl,'alias=',alias,'review=',review,'revision=',revision)
    self.resolvedFetchUrl = self._resolveFetchUrl()

  def _resolveFetchUrl(self):
+    print('Yulin._XmlRemote._resolveFetchUrl:fetchUrl=',self.fetchUrl)
    url = self.fetchUrl.rstrip('/')
    manifestUrl = self.manifestUrl.rstrip('/')
----------------------------------------------------------------------------------------------------------
Yulin._XmlRemote.__init__:name= hal fetch= ssh://wnc-integrator@wnc_hal/home/wnc-i                                                                                      ntegrator/ pushUrl= None manifestUrl= None alias= None review= None revision= None
Yulin._XmlRemote._resolveFetchUrl:fetchUrl= ssh://wnc-integrator@wnc_hal/home/wnc-                                                                                      integrator/
----------------------------------------------------------------------------------------------------------
Inference: "manifestUrl= None" is the problem.

Solution
Comparing 'git config -l' in .repo/manifests/ btwn OK and NG shows remote origin is missing in NG case.
'git remote add origin ....' fixes this issue.