Skip to content

Commit

Permalink
consume json to get variant config file
Browse files Browse the repository at this point in the history
  • Loading branch information
naveedkhan8067 committed Jun 8, 2024
1 parent 1f025f4 commit b181588
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions prepareExecutePreprocessor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os;
import sys;
import shutil
import json;
import shutil;

def main():
component = os.environ['COMPONENT']
Expand All @@ -9,18 +10,12 @@ def main():
variant = os.environ['VARIANT_TYPE']
print("Selected variant: " + str(variant))

configFile = ""
if (variant == "LINUX"):
configFile = "Linux_Config.js"
elif (variant == "MAC"):
configFile = "Mac_Config.js"
else:
configFile = "Windows_Config.js"
configFile, configPath = getConfigInfo(component, variant)

print("-> Current working directory: " + str(os.getcwd()))
componetPath = os.path.join(os.getcwd(), "components", component)
src = os.path.join(componetPath, "configs", configFile)
dst = os.path.join(componetPath, "VariantConfig.js")
componentPath = os.path.join(os.getcwd(), "components", component)
src = os.path.normpath(os.path.join(os.getcwd(), configPath, configFile))
dst = os.path.join(componentPath, "VariantConfig.js")

#clean destination file if already exist
if(os.path.exists(dst)):
Expand All @@ -30,24 +25,24 @@ def main():
print("-> Variant config is successfully prepared")

print("-> Executing C-Preprocessor")
processPaths = getPathsToProcess(component, componetPath)
processPaths = getPathsToProcess(component, componentPath)

for file in processPaths:
os.system("c-preprocessor " + str(file) + " " + str(file))

print("-> Cleanup successfully performed")
os.remove(dst)

def getPathsToProcess(component, componetPath):
def getPathsToProcess(component, componentPath):
pathsList = []
excludesDirs = ["node_modules", "configs", "lib"]
excludeFiles = ["README.md", "VariantConfig.js"]

#Get list of paths
for root, dirs, files in os.walk(componetPath):
for root, dirs, files in os.walk(componentPath):
dirs[:] = [d for d in dirs if d not in excludesDirs]
for fileName in files:
if fileName not in excludeFiles: pathsList.append( os.path.join( root[len(componetPath):], fileName ))
if fileName not in excludeFiles: pathsList.append( os.path.join( root[len(componentPath):], fileName ))

#prepare paths in the required format
for index in range(len(pathsList)):
Expand All @@ -56,6 +51,22 @@ def getPathsToProcess(component, componetPath):
pathsList[index] = os.path.join("components", component, pathsList[index]).replace("\\","/")

return pathsList

def getConfigInfo(component, variant):
configFile = ""
configPath = ""
data = json.load(open("VariantsInfo.json"))

for component in data[component]:
if component["variant"] == variant:
configFile = component["configFile"]
configPath = component["configPath"]
break
else:
print("Variant information not found in VariantsInfo.json.")
sys.exit(1)

return configFile, configPath

# call main
if __name__=="__main__":
Expand Down

0 comments on commit b181588

Please sign in to comment.