Skip to content

Commit

Permalink
A fix for issue: #3551
Browse files Browse the repository at this point in the history
Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Dec 27, 2024
1 parent 22e809a commit a0cdc60
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LiteEditor/BuildTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void BuildTab::OnBuildStarted(clBuildEvent& e)
m_viewStc->ScrollToEnd();
}

m_viewStc->Initialise(m_activeCompiler, m_buildTabSettings.IsSkipWarnings());
m_viewStc->Initialise(m_activeCompiler, m_buildTabSettings.IsSkipWarnings(), e.GetProjectName());

// notify the plugins that the build had started
clBuildEvent build_started_event(wxEVT_BUILD_STARTED);
Expand Down
111 changes: 104 additions & 7 deletions LiteEditor/BuildTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "event_notifier.h"
#include "globals.h"
#include "macros.h"
#include "workspace.h"

#include <wx/app.h>
#include <wx/msgdlg.h>
Expand Down Expand Up @@ -164,8 +165,28 @@ wxString BuildTabView::Add(const wxString& output, bool process_last_line)

// easy path: check for common makefile messages
wxString lcLine = line.Lower();
if (lcLine.Contains("entering directory") || lcLine.Contains("leaving directory") ||
lcLine.Contains(CLEAN_PROJECT_PREFIX)) {
if (lcLine.Contains("entering directory") || lcLine.Contains("leaving directory")) {
StringUtils::StripTerminalColouring(line, line);

wxString directory_name = line.AfterFirst('\'');
directory_name = directory_name.BeforeLast('\'');

// this functions as a stack, so we "push_front"
if (lcLine.Contains("entering directory")) {
m_workingDirectories.push_front(directory_name);

} else { // "Leaving directory"
if (!m_workingDirectories.empty()) {
m_workingDirectories.pop_front();
} else {
clWARNING() << "Leaving directory found, but no matching 'Entering directory'?" << endl;
}
}

line = WrapLineInColour(line, AnsiColours::Gray(), false, is_dark_theme);
textToAppend << line << "\n";

} else if (lcLine.Contains(CLEAN_PROJECT_PREFIX)) {
StringUtils::StripTerminalColouring(line, line);
line = WrapLineInColour(line, AnsiColours::Gray(), false, is_dark_theme);
textToAppend << line << "\n";
Expand Down Expand Up @@ -236,6 +257,8 @@ wxString BuildTabView::Add(const wxString& output, bool process_last_line)
// set the line project name
line_data->toolchain = m_activeCompiler ? m_activeCompiler->GetName() : wxString();
line_data->project_name = m_currentProject;
line_data->match_pattern.file_path = MakeAbsolute(line_data->match_pattern.file_path);

clDEBUG() << "Storing line info for line:" << cur_line_number << endl;
m_lineInfo.insert({ cur_line_number, line_data });
}
Expand All @@ -261,6 +284,9 @@ void BuildTabView::Clear()
m_warnCount = 0;
m_currentProject = wxEmptyString;
m_activeCompiler = nullptr;
m_workingDirectories.clear();
m_isRemoteBuild = false;
m_buildingProject.clear();
ClearLineMarker();
}

Expand Down Expand Up @@ -346,10 +372,10 @@ void BuildTabView::DoPatternClicked(const wxString& pattern, int pattern_line)
file = pattern;
}

clDEBUG() << "Build tab view: firing hostspot event for:" << endl;
clDEBUG() << "Build tab view: file:" << file << endl;
clDEBUG() << "Build tab view: line:" << line << endl;
clDEBUG() << "Build tab view: column:" << col << endl;
clDEBUG() << "(Build Tab View) firing hotspot event for:" << endl;
clDEBUG() << "(Build Tab View) file:" << file << endl;
clDEBUG() << "(Build Tab View) line:" << line << endl;
clDEBUG() << "(Build Tab View) column:" << col << endl;

clBuildEvent event_clicked(wxEVT_BUILD_OUTPUT_HOTSPOT_CLICKED);
event_clicked.SetBuildDir(wxEmptyString); // can be empty
Expand All @@ -369,7 +395,7 @@ void BuildTabView::DoPatternClicked(const wxString& pattern, int pattern_line)
// Default handling for opening files
// change dir to the active workspace directory
DirSaver ds;
clDEBUG() << "Build tab view: using default open file handler" << endl;
clDEBUG() << "(Build Tab View) using default open file handler" << endl;
auto workspace = clWorkspaceManager::Get().GetWorkspace();
if (workspace && !workspace->IsRemote()) {
::wxSetWorkingDirectory(wxFileName(workspace->GetFileName()).GetPath());
Expand Down Expand Up @@ -536,3 +562,74 @@ void BuildTabView::OnContextMenu(wxContextMenuEvent& e)
menu.Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& e) { e.Enable(!IsEmpty()); }, XRCID("buildtabview_clear_all"));
PopupMenu(&menu);
}

void BuildTabView::Initialise(CompilerPtr compiler, bool only_erros, const wxString& project)
{
Clear();
m_activeCompiler = compiler; // maybe null
m_onlyErrors = only_erros;
m_isRemoteBuild = false;
m_buildingProject = project;

auto workspace = clWorkspaceManager::Get().GetWorkspace();
if (workspace) {
m_isRemoteBuild = workspace->IsRemote();
wxString workspace_file = workspace->GetFileName();
workspace_file.Replace("\\", "/");
wxString workspace_dir = workspace_file.BeforeLast('/');

if (clCxxWorkspaceST::Get()) {
auto project = clCxxWorkspaceST::Get()->GetProject(m_buildingProject);
if (project) {
auto build_conf = project->GetBuildConfiguration(wxEmptyString);
if (build_conf && build_conf->IsCustomBuild() && !build_conf->GetCustomBuildWorkingDir().empty()) {
// use the custom build's working directory
wxFileName custom_wd(build_conf->GetCustomBuildWorkingDir(), wxEmptyString);
if (custom_wd.IsRelative()) {
custom_wd.MakeAbsolute(project->GetProjectPath());
}
m_workingDirectories.push_front(custom_wd.GetPath());
} else {
// use the project path
m_workingDirectories.push_front(project->GetProjectPath());
}
} else {
clWARNING() << "Could not locate project:" << m_buildingProject << endl;
}
} else {
m_workingDirectories.push_front(workspace_dir);
}
}
}

wxString BuildTabView::MakeAbsolute(const wxString& filepath)
{
if (!filepath.StartsWith("..")) {
return filepath; // already absolute path
}

if (m_isRemoteBuild) {
if (!m_workingDirectories.empty()) {
wxFileName fn(filepath, wxPATH_UNIX);
if (fn.MakeAbsolute(m_workingDirectories.front(), wxPATH_UNIX)) {
clDEBUG() << "(Build Tab View) File path modified from:" << filepath << "->"
<< fn.GetFullPath(wxPATH_UNIX) << endl;
return fn.GetFullPath(wxPATH_UNIX);
}
}
} else {
for (const auto& path : m_workingDirectories) {
wxFileName fn(filepath);
clDEBUG() << "(Build Tab View) Trying to convert file:" << filepath << "into abs path using wd:" << path
<< endl;
if (fn.MakeAbsolute(path) && fn.FileExists()) {
clDEBUG() << "(Build Tab View) File path modified from:" << filepath << "->" << fn.GetFullPath()
<< endl;
return fn.GetFullPath();
}
}
}

// default: do not modify the path
return filepath;
}
14 changes: 8 additions & 6 deletions LiteEditor/BuildTabView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "clEditorEditEventsHandler.h"
#include "compiler.h"

#include <deque>
#include <map>
#include <memory>
#include <optional>
Expand Down Expand Up @@ -38,12 +39,7 @@ class BuildTabView : public wxStyledTextCtrl

/// Initialise the view, preparing it for the next build process. This method should be called when a new build
/// is starting
void Initialise(CompilerPtr compiler, bool only_erros)
{
Clear();
m_activeCompiler = compiler; // maybe null
m_onlyErrors = only_erros;
}
void Initialise(CompilerPtr compiler, bool only_erros, const wxString& project);

size_t GetErrorCount() const { return m_errorCount; }
size_t GetWarnCount() const { return m_warnCount; }
Expand All @@ -67,6 +63,9 @@ class BuildTabView : public wxStyledTextCtrl
void InitialiseView();
void OnThemeChanged(wxCommandEvent& e);

/// Attempt to convert 'filepath' into absolute path
wxString MakeAbsolute(const wxString& filepath);

private:
std::map<size_t, std::shared_ptr<LineClientData>> m_lineInfo;
CompilerPtr m_activeCompiler;
Expand All @@ -77,4 +76,7 @@ class BuildTabView : public wxStyledTextCtrl
int m_indicatorStartPos = wxNOT_FOUND;
int m_indicatorEndPos = wxNOT_FOUND;
clEditEventsHandler::Ptr_t m_editEvents;
std::deque<wxString> m_workingDirectories;
bool m_isRemoteBuild = false;
wxString m_buildingProject; // only relevant for C++ workspace
};

0 comments on commit a0cdc60

Please sign in to comment.