summaryrefslogtreecommitdiffstats
path: root/src/target/firmware/solve_envs.py
blob: d4cee805cbdb7c8665a1292002d5586bc14f7185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python2

import sys

def parse(s):
	return set([x.strip() for x in s.split() if x.strip()])


def solve(board_envs, app_envs):
	if not app_envs:
		return board_envs

	envs = set()

	if '*' in app_envs:
		envs.update(board_envs)
		app_envs.discard('*')

	for e in app_envs:
		if e.startswith('-'):
			envs.discard(e[1:])
		elif e in board_envs:
			envs.add(e)

	return envs


def main(name, board_envs, app_envs):
	# Parse args
	board_envs = parse(board_envs)
	app_envs   = parse(app_envs)

	# Solve
	envs = solve(board_envs, app_envs)

	# Result
	print(' '.join(envs))


if __name__ == '__main__':
	main(*sys.argv)