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

View File

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