void BatchBuildDlg::DoInitialize() { // load the previously saved batch build file wxFileName fn(WorkspaceST::Get()->GetWorkspaceFileName()); fn.SetExt(wxT("batch_build")); wxString content; wxArrayString arr; if (ReadFileWithConversion(fn.GetFullPath(), content)) { arr = wxStringTokenize(content, wxT("\n"), wxTOKEN_STRTOK); for (size_t i=0; i<arr.GetCount(); i++) { int idx = m_checkListConfigurations->Append(arr.Item(i)); m_checkListConfigurations->Check((unsigned int)idx); } } // loop over all projects, for each project collect all available // build configurations and add them to the check list control wxArrayString projects; WorkspaceST::Get()->GetProjectList(projects); for (size_t i=0; i<projects.GetCount(); i++) { ProjectPtr p = ManagerST::Get()->GetProject(projects.Item(i)); if (p) { ProjectSettingsPtr settings = p->GetSettings(); if (settings) { ProjectSettingsCookie cookie; BuildConfigPtr bldConf = settings->GetFirstBuildConfiguration(cookie); while (bldConf) { wxString item(p->GetName() + wxT(" | ") + bldConf->GetName()); int where = arr.Index(item); if (where == wxNOT_FOUND) { // append this item m_checkListConfigurations->Append(item); } else { // this item already been added, // remove it from the arr and continue arr.RemoveAt((size_t)where); } bldConf = settings->GetNextBuildConfiguration(cookie); } } } } // check to see which configuration was left in 'arr' // and remove them from the checklistbox for (size_t i=0; i<arr.GetCount(); i++) { int where = m_checkListConfigurations->FindString(arr.Item(i)); if (where != wxNOT_FOUND) { m_checkListConfigurations->Delete((unsigned int)where); } } arr.clear(); if (m_checkListConfigurations->GetCount()>0) { m_checkListConfigurations->Select(0); } }
BuildConfigPtr clCxxWorkspace::GetProjBuildConf(const wxString& projectName, const wxString& confName) const { BuildMatrixPtr matrix = GetBuildMatrix(); if(!matrix) { return NULL; } wxString projConf(confName); if(projConf.IsEmpty()) { wxString workspaceConfig = matrix->GetSelectedConfigurationName(); projConf = matrix->GetProjectSelectedConf(workspaceConfig, projectName); } // Get the project setting and retrieve the selected configuration wxString errMsg; ProjectPtr proj = FindProjectByName(projectName, errMsg); if(proj) { ProjectSettingsPtr settings = proj->GetSettings(); if(settings) { return settings->GetBuildConfiguration(projConf, true); } } return NULL; }
void MacBundler::showSettingsDialogFor(ProjectPtr project) { // project->GetSettings()->GetGlobalSettings(); // project->GetSettings()->GetBuildConfiguration(name); ProjectSettingsCookie cookie; ProjectSettingsPtr settings = project->GetSettings(); if(not settings) { wxMessageBox(_("Cannot continue, impossible to access project settings.")); return; } std::map<wxString, BuildConfigPtr> configs; wxArrayString choices; // TODO: allow putting the rules in the config root and not in every target BuildConfigPtr buildConfig = settings->GetFirstBuildConfiguration(cookie); while(buildConfig) { configs[buildConfig->GetName()] = buildConfig; choices.Add(buildConfig->GetName()); buildConfig = settings->GetNextBuildConfiguration(cookie); } bool accepted = false; bool generateInfoPlistFile = false; bool generateIcon = false; wxArrayString targetsToSet; wxString iconName(wxT("icon.icns")); { BundleConfigDialog configDlg(project, m_mgr->GetTheApp()->GetTopWindow(), choices, m_mgr); configDlg.ShowModal(); accepted = configDlg.getResults(targetsToSet, &generateInfoPlistFile, &generateIcon); iconName = configDlg.getIconDestName(); if(accepted and generateInfoPlistFile) { wxFileName projPath = project->GetFileName(); projPath.SetFullName(wxT("")); const wxString projectDirName = projPath.GetFullPath(); const wxString infoPlistFile = projectDirName + wxT("/Info.plist"); if(wxFileExists(infoPlistFile)) { int out = wxMessageBox(wxString::Format(_("The following file:\n%s\nalready exists, overwrite it?\n"), infoPlistFile.c_str()), _("Warning"), wxYES_NO); if(out == wxYES) { wxTextFile file; file.Open(infoPlistFile); file.Clear(); configDlg.writeInfoPlistFile(file); file.Close(); } } else { wxTextFile file; if(not file.Create(infoPlistFile)) { wxMessageBox(_("Could not create Info.plist file\n") + infoPlistFile); } else { configDlg.writeInfoPlistFile(file); file.Close(); } } if(wxFileExists(infoPlistFile)) { // FIXME: if the file was already present, it will be added again and appear twice in the file tree wxArrayString paths; paths.Add(infoPlistFile); m_mgr->CreateVirtualDirectory(project->GetName(), wxT("osx")); m_mgr->AddFilesToVirtualFolder(project->GetName() + wxT(":osx"), paths); } } // nend if create info.plist if(accepted and generateIcon) { wxString iconSourcePath = configDlg.getIconSource(); if(not iconSourcePath.IsEmpty()) { // sips doesn't like double slashes in path names iconSourcePath.Replace(wxT("//"), wxT("/")); wxFileName projPath = project->GetFileName(); projPath.SetFullName(wxT("")); const wxString projectDirName = projPath.GetFullPath(); wxString iconFileDest = projectDirName + wxT("/") + configDlg.getIconDestName(); // sips doesn't like double slashes in path names iconFileDest.Replace(wxT("//"), wxT("/")); std::cout << "Copying icon '" << iconSourcePath.mb_str() << "' to project\n"; if(iconSourcePath.EndsWith(wxT(".icns"))) { if(not wxCopyFile(iconSourcePath, iconFileDest)) { wxMessageBox(_("Sorry, could not copy icon")); } } else { wxString cmd = wxT("sips -s format icns '") + iconSourcePath + wxT("' --out '") + iconFileDest + wxT("'"); std::cout << cmd.mb_str() << std::endl; wxExecute(cmd, wxEXEC_SYNC); if(not wxFileExists(iconFileDest)) { wxMessageBox(_("Sorry, could not convert selected icon to icns format")); } } // FIXME: if the file was already present, it will be added again and appear twice in the file tree if(wxFileExists(iconFileDest)) { wxArrayString paths; paths.Add(iconFileDest); m_mgr->CreateVirtualDirectory(project->GetName(), wxT("osx")); m_mgr->AddFilesToVirtualFolder(project->GetName() + wxT(":osx"), paths); } } // end if icon not null } // end if generate icon } if(!accepted) return; for(int n = 0; n < targetsToSet.GetCount(); n++) { BuildConfigPtr buildConfig = configs[targetsToSet[n]]; wxString outputFileName = buildConfig->GetOutputFileName(); wxString output = wxT("$(ProjectName).app/Contents/MacOS/$(ProjectName)"); buildConfig->SetOutputFileName(wxT("$(IntermediateDirectory)/") + output); buildConfig->SetCommand(wxT("./") + output); if(generateInfoPlistFile or generateIcon) { // get existing custom makefile targets, if any wxString customPreBuild = buildConfig->GetPreBuildCustom(); wxString deps, rules; deps = customPreBuild.BeforeFirst(wxT('\n')); rules = customPreBuild.AfterFirst(wxT('\n')); rules = rules.Trim(); rules = rules.Trim(false); deps = deps.Trim(); deps = deps.Trim(false); if(generateInfoPlistFile) { // augment existing rules with new rules to manage Info.plist file deps.Append(wxT(" $(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist")); rules.Append(wxString(wxT("\n## rule to copy the Info.plist file into the bundle\n")) + wxT("$(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist: Info.plist\n") + wxT("\tmkdir -p '$(IntermediateDirectory)/$(ProjectName).app/Contents' && cp -f " "Info.plist '$(IntermediateDirectory)/$(ProjectName).app/Contents/Info.plist'")); } if(generateIcon) { // augment existing rules with new rules to manage Info.plist file deps.Append(wxT(" $(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName); rules.Append( wxT("\n## rule to copy the icon file into the " "bundle\n$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName + wxT(": ") + iconName + wxT("\n\tmkdir -p '$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/' && cp -f ") + iconName + wxT(" '$(IntermediateDirectory)/$(ProjectName).app/Contents/Resources/") + iconName + wxT("'")); } // set the new rules rules = rules.Trim(); rules = rules.Trim(false); deps = deps.Trim(); deps = deps.Trim(false); wxString prebuilstep; prebuilstep << deps << wxT("\n"); prebuilstep << rules; prebuilstep << wxT("\n"); // Set the content only if there is real content to add wxString tmpPreBuildStep(prebuilstep); tmpPreBuildStep.Trim().Trim(false); buildConfig->SetPreBuildCustom(prebuilstep); } // end if settings->SetBuildConfiguration(buildConfig); } // end for project->SetSettings(settings); }
bool clCxxWorkspace::RemoveProject(const wxString& name, wxString& errMsg) { ProjectPtr proj = FindProjectByName(name, errMsg); if(!proj) { return false; } // remove the associated build configuration with this // project RemoveProjectFromBuildMatrix(proj); // remove the project from the internal map std::map<wxString, ProjectPtr>::iterator iter = m_projects.find(proj->GetName()); if(iter != m_projects.end()) { m_projects.erase(iter); } // update the xml file wxXmlNode* root = m_doc.GetRoot(); wxXmlNode* child = root->GetChildren(); while(child) { if(child->GetName() == wxT("Project") && child->GetPropVal(wxT("Name"), wxEmptyString) == name) { if(child->GetPropVal(wxT("Active"), wxEmptyString).CmpNoCase(wxT("Yes")) == 0) { // the removed project was active, // select new project to be active if(!m_projects.empty()) { std::map<wxString, ProjectPtr>::iterator iter = m_projects.begin(); SetActiveProject(iter->first, true); } } root->RemoveChild(child); delete child; break; } child = child->GetNext(); } // go over the dependencies list of each project and remove the project iter = m_projects.begin(); for(; iter != m_projects.end(); iter++) { ProjectPtr p = iter->second; if(p) { wxArrayString configs; // populate the choice control with the list of available configurations for this project ProjectSettingsPtr settings = p->GetSettings(); if(settings) { ProjectSettingsCookie cookie; BuildConfigPtr bldConf = settings->GetFirstBuildConfiguration(cookie); while(bldConf) { configs.Add(bldConf->GetName()); bldConf = settings->GetNextBuildConfiguration(cookie); } } // update each configuration of this project for(size_t i = 0; i < configs.GetCount(); i++) { wxArrayString deps = p->GetDependencies(configs.Item(i)); int where = deps.Index(name); if(where != wxNOT_FOUND) { deps.RemoveAt((size_t)where); } // update the configuration p->SetDependencies(deps, configs.Item(i)); } } } return SaveXmlFile(); }
void clCxxWorkspace::AddProjectToBuildMatrix(ProjectPtr prj) { if(!prj) { wxMessageBox(_("AddProjectToBuildMatrix was called with NULL project"), _("CodeLite"), wxICON_WARNING | wxOK); return; } BuildMatrixPtr matrix = GetBuildMatrix(); wxString selConfName = matrix->GetSelectedConfigurationName(); std::list<WorkspaceConfigurationPtr> wspList = matrix->GetConfigurations(); std::list<WorkspaceConfigurationPtr>::iterator iter = wspList.begin(); for(; iter != wspList.end(); iter++) { WorkspaceConfigurationPtr workspaceConfig = (*iter); WorkspaceConfiguration::ConfigMappingList prjList = workspaceConfig->GetMapping(); wxString wspCnfName = workspaceConfig->GetName(); ProjectSettingsCookie cookie; // getSettings is a bit misleading, since it actually create new instance which represents the layout // of the XML ProjectSettingsPtr settings = prj->GetSettings(); BuildConfigPtr prjBldConf = settings->GetFirstBuildConfiguration(cookie); BuildConfigPtr matchConf; if(!prjBldConf) { // the project does not have any settings, create new one and add it prj->SetSettings(settings); settings = prj->GetSettings(); prjBldConf = settings->GetFirstBuildConfiguration(cookie); matchConf = prjBldConf; } else { matchConf = prjBldConf; // try to locate the best match to add to the workspace while(prjBldConf) { wxString projBldConfName = prjBldConf->GetName(); if(wspCnfName == projBldConfName) { // we found a suitable match use it instead of the default one matchConf = prjBldConf; break; } prjBldConf = settings->GetNextBuildConfiguration(cookie); } } ConfigMappingEntry entry(prj->GetName(), matchConf->GetName()); prjList.push_back(entry); (*iter)->SetConfigMappingList(prjList); matrix->SetConfiguration((*iter)); } // and set the configuration name matrix->SetSelectedConfigurationName(selConfName); // this will also reset the build matrix pointer SetBuildMatrix(matrix); }