''' Overwrites the Qt Creator shared project files to customize for the firmware build environment ''' # Imports from os import path from os import getcwd from argparse import ArgumentParser # Create argument parser parser = ArgumentParser(description='Process board targets.') parser.add_argument('--targets', metavar='target_board', nargs='+', help='List of board names') # Parse arguments args = parser.parse_args() targets = args.targets # Check that there are some targets. If not, print help and exit. if not targets: print ("") print ("*******************************") print ("* No --target arguments found *") print ("*******************************") print ("") parser.print_help() exit(1) # Set up paths and file names qt_creator_firmware_project_path = "Project/Qt Creator/" root_directory = getcwd() file_template = path.join(qt_creator_firmware_project_path, "vesc.pro.shared.template") file_out = path.join(qt_creator_firmware_project_path, "vesc.pro.shared") # Template text to be replaced dummy_root_directory = "{ROOT REPOSITORY PATH}" dummy_build_directory = "{BUILD PATH}" dummy_configuration_number_text = "{CONFIGURATION NUMBER}" dummy_target_name_normal = "{TARGET NAME, NORMAL CASE}" dummy_target_name_lowercase = "{TARGET NAME, LOWERCASE}" dummy_number_of_targets = "{NUMBER OF TARGETS}" dummy_build_configuration_targets = "{BUILD CONFIGURATION TARGETS}" # Generic target configuration block reference_target_configuration = """ 1 {BUILD PATH} {BUILD PATH} true {TARGET NAME, NORMAL CASE} make %{sourceDir}/../../ ProjectExplorer.ProcessStep 1 Build Build ProjectExplorer.BuildSteps.Build true {TARGET NAME, NORMAL CASE}_clean make %{sourceDir}/../../ ProjectExplorer.ProcessStep 1 Clean Clean ProjectExplorer.BuildSteps.Clean 2 false false {TARGET NAME, NORMAL CASE} Qt4ProjectManager.Qt4BuildConfiguration 0 1 """ dummy_build_configuration_count = """ {NUMBER OF TARGETS}""" # Creaty empty string output_target_configuration = "" # Loop through all board targets for idx,target_name in enumerate(targets): # Make local copy of reference text target_configuration = reference_target_configuration # Incrementally update local target configuration target_configuration = target_configuration.replace(dummy_configuration_number_text, repr(idx)) target_configuration = target_configuration.replace(dummy_target_name_normal, target_name) target_configuration = target_configuration.replace(dummy_target_name_lowercase, target_name.lower()) # Update output target configuration with local target output_target_configuration = output_target_configuration + target_configuration # Append number of build configurations output_target_configuration = output_target_configuration + dummy_build_configuration_count.replace(dummy_number_of_targets, repr(len(targets))) # Open template file and read into memory print(file_template) f = open(file_template,'r') filedata = f.read() f.close() # Replace template placeholder by target configurations filedata = filedata.replace(dummy_build_configuration_targets, output_target_configuration) # Replace dummy root directory by actual directory. This must follow the target configuration placeholder replacement filedata = filedata.replace(dummy_root_directory, root_directory) # Replace dummy build directory by actual directory. This must follow the target configuration placeholder replacement filedata = filedata.replace(dummy_build_directory, path.join(root_directory, "build")) # Write file f = open(file_out,'w') f.write(filedata) f.close()