osmith has uploaded this change for review.

View Change

gen_makefile: turn projects_deps into a dict

Let read_projects_deps() return a dictionary instead of a list of
tuples. This allows looking up entries in the dictionary by project
name, which I'm making use of in a future patch.

While using a dictionary here makes more sense, I assume this was
implemented as list of tuples because with earlier (long EOL) python3
versions, the order of entries in the dictionary were not stable. From
https://docs.python.org/3/library/stdtypes.html#dict:
> Changed in version 3.7: Dictionary order is guaranteed to be insertion
> order. This behavior was an implementation detail of CPython from 3.6.

Change-Id: I74c53f4d6dda791c5d9e14f2274260f0e8cbbad2
---
M gen_makefile.py
1 file changed, 9 insertions(+), 9 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-dev refs/changes/37/40837/1
diff --git a/gen_makefile.py b/gen_makefile.py
index e06dbd2..c49a27a 100755
--- a/gen_makefile.py
+++ b/gen_makefile.py
@@ -144,15 +144,15 @@
self.extend(k, v)

def read_projects_deps(path):
- 'Read deps config and return tuples of (project_name, which-other-to-build-first).'
- l = []
+ 'Read deps config and return a dict of {project_name: which-other-to-build-first, …}.'
+ ret = {}
for line in open(path):
line = line.strip()
if not line or line.startswith('#'):
continue
tokens = line.split()
- l.append((tokens[0], tokens[1:]))
- return l
+ ret[tokens[0]] = tokens[1:]
+ return ret

def read_projects_dict(path):
'Read urls/buildsystems config and return dict {project_name: url, …}.'
@@ -170,7 +170,7 @@
'Read config opts file and return tuples of (project_name, config-opts).'
if not path:
return {}
- return dict(read_projects_deps(path))
+ return read_projects_deps(path)

def gen_makefile_clone(proj, src, src_proj, update_src_copy_cmd):
if proj == "osmocom-bb_layer23":
@@ -646,17 +646,17 @@
"""

# convenience target: clone all repositories first
-content += 'clone: \\\n\t' + ' \\\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps ]) + '\n\n'
+content += 'clone: \\\n\t' + ' \\\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps.items() ]) + '\n\n'

# convenience target: clean all
-content += 'clean: \\\n\t' + ' \\\n\t'.join([ '%s-clean' % p for p, d in projects_deps ]) + '\n\n'
+content += 'clean: \\\n\t' + ' \\\n\t'.join([ '%s-clean' % p for p, d in projects_deps.items() ]) + '\n\n'

# now the actual useful build rules
content += 'all: clone all-install\n\n'

-content += 'all-install: \\\n\t' + ' \\\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps ]) + '\n\n'
+content += 'all-install: \\\n\t' + ' \\\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps.items() ]) + '\n\n'

-for proj, deps in projects_deps:
+for proj, deps in projects_deps.items():
all_config_opts = []
all_config_opts.extend(configure_opts.get('ALL') or [])
all_config_opts.extend(configure_opts.get(proj) or [])

To view, visit change 40837. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-dev
Gerrit-Branch: master
Gerrit-Change-Id: I74c53f4d6dda791c5d9e14f2274260f0e8cbbad2
Gerrit-Change-Number: 40837
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith@sysmocom.de>