SourceContext improvements

* When loading from multiple files, ensure that the correct filename
  is included in the path (rather than just the last).
* Keep track of the line number where jobs are defined and include it
  in the job representation.  This is used in the inheritance_path
  var to aid in debugging.

Change-Id: Ia3f0d03cd45d6c3b24b3dc7b663d1175cc0a18fc
This commit is contained in:
James E. Blair 2017-09-29 14:24:42 -07:00
parent fceaf41130
commit 167d6cd5ed
2 changed files with 15 additions and 10 deletions

View File

@ -486,6 +486,7 @@ class JobParser(object):
job = model.Job(conf['name']) job = model.Job(conf['name'])
job.source_context = conf.get('_source_context') job.source_context = conf.get('_source_context')
job.source_line = conf.get('_start_mark').line +1
is_variant = layout.hasJob(conf['name']) is_variant = layout.hasJob(conf['name'])
if 'parent' in conf: if 'parent' in conf:
@ -1403,19 +1404,20 @@ class TenantParser(object):
(job.source_context,)) (job.source_context,))
continue continue
loaded = conf_root loaded = conf_root
job.source_context.path = fn source_context = job.source_context.copy()
source_context.path = fn
TenantParser.log.info( TenantParser.log.info(
"Loading configuration from %s" % "Loading configuration from %s" %
(job.source_context,)) (source_context,))
project = job.source_context.project project = source_context.project
branch = job.source_context.branch branch = source_context.branch
if job.source_context.trusted: if source_context.trusted:
incdata = TenantParser._parseConfigProjectLayout( incdata = TenantParser._parseConfigProjectLayout(
job.files[fn], job.source_context) job.files[fn], source_context)
config_projects_config.extend(incdata) config_projects_config.extend(incdata)
else: else:
incdata = TenantParser._parseUntrustedProjectLayout( incdata = TenantParser._parseUntrustedProjectLayout(
job.files[fn], job.source_context) job.files[fn], source_context)
untrusted_projects_config.extend(incdata) untrusted_projects_config.extend(incdata)
new_project_unparsed_config[project].extend(incdata) new_project_unparsed_config[project].extend(incdata)
if branch in new_project_unparsed_branch_config.get( if branch in new_project_unparsed_branch_config.get(

View File

@ -817,6 +817,7 @@ class Job(object):
self.other_attributes = dict( self.other_attributes = dict(
name=None, name=None,
source_context=None, source_context=None,
source_line=None,
inheritance_path=(), inheritance_path=(),
) )
@ -851,9 +852,11 @@ class Job(object):
return self.name return self.name
def __repr__(self): def __repr__(self):
return '<Job %s branches: %s source: %s>' % (self.name, return '<Job %s branches: %s source: %s#%s>' % (
self.branch_matcher, self.name,
self.source_context) self.branch_matcher,
self.source_context,
self.source_line)
def __getattr__(self, name): def __getattr__(self, name):
v = self.__dict__.get(name) v = self.__dict__.get(name)