Skip to content

Commit

Permalink
Merge pull request #65 from naveedkhan8067/configUpdate
Browse files Browse the repository at this point in the history
Updated config process
  • Loading branch information
naveedkhan8067 authored Jun 8, 2024
2 parents 73330ed + 6141dd9 commit 4c39a7e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
19 changes: 19 additions & 0 deletions VariantsInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"hello-world": [
{
"variant": "LINUX",
"configFile": "LinuxConfig.js",
"configPath": "components/hello-world/configs"
},
{
"variant": "MAC",
"configFile": "MacConfig.js",
"configPath": "components/hello-world/configs"
},
{
"variant": "WINDOWS",
"configFile": "WindowsConfig.js",
"configPath": "components/hello-world/configs"
}
]
}
File renamed without changes.
47 changes: 32 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,17 @@ 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")

#verify the existence of variant config file
if(not os.path.exists(src)):
print("Config file not found: " + src)
sys.exit(1)

#clean destination file if already exist
if(os.path.exists(dst)):
Expand All @@ -30,24 +30,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 +56,23 @@ 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

if not (configFile) or not (configPath):
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 4c39a7e

Please sign in to comment.