Skip to content

Commit

Permalink
Allow for simpler environmental variable creation (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pocketkid2 committed Aug 29, 2022
1 parent 6264fd8 commit 1d18ec2
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions edalize/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
class EdaCommands(object):
class Command(object):
def __init__(self, command, targets, depends, order_only_deps=[]):
def __init__(self, command, targets, depends, order_only_deps=[], variables=[]):
self.command = command
self.targets = targets
self.depends = depends
self.order_only_deps = order_only_deps
self.variables = variables

def __init__(self):
self.commands = []
self.vars = []
self.header = "#Auto generated by Edalize\n\n"

def add(self, command, targets, depends, order_only_deps=[]):
self.commands.append(self.Command(command, targets, depends, order_only_deps))
def add(self, command, targets, depends, order_only_deps=[], variables=[]):
self.commands.append(
self.Command(command, targets, depends, order_only_deps, variables)
)

def add_var(self, var):
self.vars.append(var)

# Allow for portability between the main platforms
def find_env_var_command(self):
from sys import platform

if platform == "linux" or platform == "linux2" or platform == "darwin":
return "export"
elif platform == "win32":
return "set"
return ""

# Simplify the creation of flow environmental variables in the Makefile
def add_env_var(self, key, value):
self.vars.append(f"{self.find_env_var_command()} {key}={value}")

def set_default_target(self, target):
self.default_target = target

Expand All @@ -43,5 +60,14 @@ def write(self, outfile):

f.write("\n")

env_prefix = ""
if c.variables:
var_list = []
for key in c.variables.keys():
var_list += f"{key}={c.variables.get(key)}"
env_prefix = f"env {' '.join(var_list)}"

if c.command:
f.write(f"\t$(EDALIZE_LAUNCHER) {' '.join(c.command)}\n")
f.write(
f"\t$(EDALIZE_LAUNCHER) {env_prefix}{' '.join(c.command)}\n"
)

0 comments on commit 1d18ec2

Please sign in to comment.