public void Convert(string ProjectPath) { using (ProjectCollection LocalProjColl = new ProjectCollection()) { Project MSBProj = LocalProjColl.LoadProject(PK.Wrapper.ExpandEnvVars(ProjectPath, "")); ARMCCPath = MSBProj.GetPropertyValue("CC").ToLower(); ARMASMPath = MSBProj.GetPropertyValue("AS").ToLower(); ARMLINKPath = MSBProj.GetPropertyValue("LINK").ToLower(); ARMARPath = MSBProj.GetPropertyValue("AR").ToLower(); ARMFROMELFPath = MSBProj.GetPropertyValue("FromELF").ToLower(); } PKParser.Arg.PKArgParser ArgParser = new PKParser.Arg.PKArgParser(); int index = 0; Link Link = new Link("Link", null); Link.LogEvent += new MessagesParsesHelper.Link.LogEventDelegate(Link_LogEvent); OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.START)); foreach (LogQueueItem item in LogQueue.Values) { index++; OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_ANALYSE_LINKS, GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / LogQueue.Values.Count))); string s = ArgParser.GetUtil(item.Message); if (s == null) continue; if (String.Compare(ARMLINKPath, s, StringComparison.InvariantCultureIgnoreCase) == 0) { //ArmLink ARMLink.Add(ARMLink.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir)); } else if (String.Compare(ARMCCPath, s, StringComparison.InvariantCultureIgnoreCase) == 0) { //ArmCC ARMCCandARMASM.Add(ARMCCandARMASM.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir)); } else if (String.Compare(ARMASMPath, s, StringComparison.InvariantCultureIgnoreCase) == 0) { //ArmAsm ARMCCandARMASM.Add(ARMCCandARMASM.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir)); } else if (String.Compare(ARMARPath, s, StringComparison.InvariantCultureIgnoreCase) == 0) { //ArmAr ARMAR.Add(ARMAR.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir)); } else if (String.Compare(ARMFROMELFPath, s, StringComparison.InvariantCultureIgnoreCase) == 0) { //FROMElf FROMELF.Add(FROMELF.Count + 1, new ParCollContainer(ArgParser.Add(item.Message), item.Message, item.ProjectBuildContext, item.CurrentDir)); } } ArgParser.Clear(); //Construct project tree ParCollContainer container = ARMLink.Values[ARMLink.Values.Count - 1]; if (container.ParamCollection == null) throw new MessagesParserException(KeilWizardStrings.IDS_ERROR_CANT_PASRSE_LINK); Link.ParamCollection = container.ParamCollection; string LIB_EXT = string.Empty; string OBJ_EXT = string.Empty; using (ProjectCollection LocalProjColl = new ProjectCollection()) { Project MSBProj = LocalProjColl.LoadProject(container.ProjectBuildContext[container.ProjectBuildContext.Count - 1]); LIB_EXT = MSBProj.GetPropertyValue("LIB_EXT"); OBJ_EXT = MSBProj.GetPropertyValue("OBJ_EXT"); } foreach (ArgCollection arg in container.ParamCollection.Values) { if (arg.Name == "--output") { Link.Name = arg[0]; } } foreach (string file in container.ParamCollection.Files.Values) { RequiredLibrary lib = null; RequiredObject obj = null; if (Path.GetExtension(file).ToLower() == "." + LIB_EXT.ToLower()) { lib = new RequiredLibrary(file, Link); Link.InputLibraries.Add(Link.InputLibraries.Count + 1, lib); } if (Path.GetExtension(file).ToLower() == "." + OBJ_EXT.ToLower()) { obj = new RequiredObject(file, Link); Link.InputObjects.Add(Link.InputObjects.Count + 1, obj); } if (lib != null) Link.AllInputs.Add(Link.AllInputs.Count + 1, lib); if (obj != null) Link.AllInputs.Add(Link.AllInputs.Count + 1, obj); } OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_ANALYSE_LINKS, GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.WORKING, 100)); System.Threading.Thread.Sleep(sleeptime); //using (StreamWriter outfile = // new StreamWriter(Path.GetFileNameWithoutExtension(Link.Name) + ".input")) //{ // outfile.WriteLine(PK.Wrapper.Solution.ProjectPath); // outfile.WriteLine(uVisionProjectPath); // outfile.WriteLine(ProjectPath); // foreach (ArgCollection arg in Link.ParamCollection.Values) // { // if (arg.Name == "--scatter") // outfile.WriteLine(arg[0]); // } // outfile.WriteLine(LogQueue.Values.Count); // foreach (LogQueueItem item in LogQueue.Values) // { // outfile.WriteLine(item.Message); // outfile.WriteLine(item.CurrentDir); // outfile.WriteLine(item.ProjectBuildContext.Count); // foreach (string s in item.ProjectBuildContext) // { // outfile.WriteLine(s); // } // } //} ArgParser.Clear(); //Analysing libraries this.AnalizeInputLibraries(Link.InputLibraries, LogQueue.Values); //Checking Crypto.Lib this.CheckCryptoLib(Link.InputLibraries, LogQueue.Values); //Checking Sockets Libs this.CheckSocketsLibs(Link.InputLibraries, LogQueue.Values); //Analysing Files SortedList<int, RequiredObject> ReqObjs = Link.GetAllRequiredObjects(); this.AnalizeInputObjects(ReqObjs);//, LogQueue.Values); if (!Link.CheckItems()) { throw new MessagesParserException(KeilWizardStrings.IDS_ERROR_FAIL_LINK_ANALYSE); } OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_PROJECT_TREE, GeneratingLogMessage.WORK_STATE.DONE)); OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.START)); index = 0; //Collects required files List<RequiredLibrary> ReqLib = Link.GetAllSubRequiredLibraries(); foreach (RequiredObject obj in ReqObjs.Values) { index++; OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_FILE_LIST, GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / (ReqObjs.Values.Count + ReqLib.Count)))); this.AddObjFile(obj); } foreach (RequiredLibrary lib in ReqLib) { index++; OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_FILE_LIST, GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / (ReqObjs.Values.Count + ReqLib.Count)))); uVisionProject.AddFile(lib.OutputFileuVision, Path.GetFileNameWithoutExtension(lib.Parent.Name)); } //Sorting groups uVisionProject.SortGroups(); foreach (RequiredLibrary lib in Link.InputLibraries.Values) { uVisionProject.AddFile(lib.OutputFileuVision, Path.GetFileNameWithoutExtension(Link.Name)); } OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_FILE_LIST, GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.WORKING, 100)); System.Threading.Thread.Sleep(sleeptime); OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_FILE_LIST, GeneratingLogMessage.WORK_STATE.DONE)); OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.START)); //Create targets index = 0; foreach (RequiredLibrary lib in Link.InputLibraries.Values) { index++; OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_TARGETS, GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.WORKING, (int)((index * 100) / (Link.InputLibraries.Count)))); this.CreateLibraryTartet(lib); } this.CreateLinkTarget(Link);//, LogQueue.Values); OnLog(new GeneratingLogMessage(KeilWizardStrings.IDS_CREATING_TARGETS, GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.WORKING, 100)); System.Threading.Thread.Sleep(sleeptime); OnLog(new GeneratingLogMessage("", GeneratingLogMessage.WORK_TYPE.CREATE_TARGETS, GeneratingLogMessage.WORK_STATE.DONE)); //using (StreamWriter outfile = new StreamWriter(Path.GetFileNameWithoutExtension(Link.Name) + ".result")) //{ // List<string> strs = uVisionProject.GetAllProjectStrings(); // foreach (string s in strs) // { // outfile.WriteLine(s); // } //} }
private void CreateLinkTarget(Link link)//, IList<LogQueueItem> messages) { Target target = new Target(uVisionProject.DefaultOptions); //Setting default options //target.SeTLPC2478DefaultOptions(); target.Name = Path.GetFileNameWithoutExtension(link.Name); target.Options.GenApp = TWO_STATE_BOOL.ENABLED; target.Options.GenLib = TWO_STATE_BOOL.DISABLED; target.Options.ADSFLGA = "226,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"; target.Options.ADSCCFLG.ARM_Thumb_Interworking = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.Optimisation = OPTIMIZATION.Level0; target.Options.ADSCCFLG.Optimize_for_time = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.Split_Load_and_Store_Multiple = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.One_EFL_Section_per_Function = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.Strict_ANSI_C = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.Enum_Container_always_int = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.Plain_Char_is_Signed = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.ReadOnly_Position_Independent = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.ReadWrite_Position_Independent = THREE_STATE_BOOL.DISABLED; target.Options.ADSCCFLG.Thumb_Mode = THREE_STATE_BOOL.DISABLED; target.Options.ADSASFLG = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"; target.Options.ADSLDFG = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"; target.Options.ADSLDTA = ""; target.Options.ADSLDDA = ""; target.Options.Debug = "1"; target.Options.Browse = "1"; //Exclude files from building foreach (PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.File f in uVisionProject.FileList.Values) { //if ((f.Type == uVision.Project.File.FILE_TYPE.C_FILE) || (f.Type == uVision.Project.File.FILE_TYPE.CPP_FILE) || (f.Type == uVision.Project.File.FILE_TYPE.ASM_FILE)) //{ PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.FileOptions fileopt = new PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.FileOptions(f); fileopt.IncBld = THREE_STATE_BOOL.DISABLED; target.FilesOpton.Add(fileopt); //} } target.Options.OutDir = Path.GetDirectoryName(link.OutputFileMSBuild) + "\\"; target.Options.OutName = Path.GetFileNameWithoutExtension(link.OutputFileMSBuild); link.OutputFileuVision = link.OutputFileMSBuild; foreach (RequiredObject obj in link.InputObjects.Values) { this.AddCompileFile(obj, target); } foreach (RequiredLibrary lib in link.InputLibraries.Values) { PKStudio.Tools.uVisionGenerator.Classes.uvProjectClasses.FileOptions fileOpt = target.FindFileOptions(lib.OutputFileuVision); fileOpt.IncBld = THREE_STATE_BOOL.ENABLED; } //string LinkString = ARMLINKPath; foreach (ArgCollection arg in link.ParamCollection.Values) { if (arg.Tag == "options") { switch (arg.Name) { //no need process this because all paths will be contained in file list case "--userlibpath": break; case "--scatter": //target.Options.ADSLDSC = arg[0]; target.Options.ADSLDSC = uVisionProject.ProjectPath + @"\" + Path.GetFileName(arg[0]); string line; using (StreamReader infile = new StreamReader(arg[0])) { while ((line = infile.ReadLine()) != null) { uVisionProject.Scatter.Add(uVisionProject.Scatter.Count + 1, line); } } //uVisionProject break; case "--device": break; case "--output": break; default: if (arg.Count > 0) { foreach (string s in arg) { //LinkString += " " + arg.Name + " " + s; target.Options.ADSLDMC.Add(arg.Name + " " + s); } } //else LinkString += " " + arg.Name; else target.Options.ADSLDMC.Add(arg.Name); break; } } } //foreach (BuildBase bb in link.AllInputs.Values) //{ // LinkString += " " + bb.OutputFileuVision; //} //target.AfterBuild.Add(LinkString); //PKArgParser ArgParser = new PKArgParser(); //Adds fromelf foreach (ParCollContainer container in FROMELF.Values) { if (container.Message.ToLower().Contains(link.OutputFileMSBuild.ToLower())) { target.AfterBuild.Add(container.Message); } } target.Num = uVisionProject.TargetList.Count + 1; uVisionProject.TargetList.Add(target.Num, target); if (target.BeforeBuild.Count > 0) { target.Options.BrunUsr_0.Run = TWO_STATE_BOOL.ENABLED; target.Options.BrunUsr_0.Command = ".\\BatFiles\\Prebuild" + @"\" + target.Name + ".bat"; } if (target.AfterBuild.Count > 0) { target.Options.RunUsr_0.Run = TWO_STATE_BOOL.ENABLED; target.Options.RunUsr_0.Command = ".\\BatFiles\\Postbuild" + @"\" + target.Name + ".bat"; } }