Skip to content

Commit

Permalink
Fix Run behavior on Windowses without terminal support. Now opens cmd…
Browse files Browse the repository at this point in the history
….exe with a bat script helper that waits the user to terminate the process after it run.

ProjectBuild and StatusBuildOutputController clean up (unify build and clean).
  • Loading branch information
SpartanJ committed Apr 19, 2024
1 parent e01a03a commit 944d6ee
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 218 deletions.
5 changes: 5 additions & 0 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool s
mPluginsPath = mConfigPath + "plugins";
mLanguagesPath = mConfigPath + "languages";
mThemesPath = mConfigPath + "themes";
mScriptsPath = mConfigPath + "scripts";
mColorSchemesPath = mConfigPath + "editor" + FileSystem::getOSSlash() + "colorschemes" +
FileSystem::getOSSlash();
mTerminalManager = std::make_unique<TerminalManager>( this );
Expand All @@ -525,6 +526,10 @@ bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool s
FileSystem::makeDir( mThemesPath );
FileSystem::dirAddSlashAtEnd( mThemesPath );

if ( !FileSystem::fileExists( mScriptsPath ) )
FileSystem::makeDir( mScriptsPath );
FileSystem::dirAddSlashAtEnd( mScriptsPath );

mLogsPath = mConfigPath + "ecode.log";

#ifndef EE_DEBUG
Expand Down
3 changes: 3 additions & 0 deletions src/tools/ecode/ecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ class App : public UICodeEditorSplitter::Client {

std::pair<bool, std::string> generateConfigPath();

const std::string getScriptsPath() const { return mScriptsPath; }

protected:
std::vector<std::string> mArgs;
EE::Window::Window* mWindow{ nullptr };
Expand Down Expand Up @@ -479,6 +481,7 @@ class App : public UICodeEditorSplitter::Client {
std::string mThemesPath;
std::string mLogsPath;
std::string mi18nPath;
std::string mScriptsPath;
Float mDisplayDPI{ 96 };
std::shared_ptr<ThreadPool> mThreadPool;
std::shared_ptr<ProjectDirectoryTree> mDirTree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fuzzyMatchSymbols( const std::vector<const AutoCompletePlugin::SymbolsList*>& sy
const std::string& match, const size_t& max ) {
AutoCompletePlugin::SymbolsList matches;
matches.reserve( max );
int score;
int score = 0;
for ( const auto& symbols : symbolsVec ) {
for ( const auto& symbol : *symbols ) {
if ( symbol.kind == LSPCompletionItemKind::Snippet ||
Expand Down
87 changes: 12 additions & 75 deletions src/tools/ecode/projectbuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ ProjectBuildManager::~ProjectBuildManager() {

ProjectBuildCommandsRes ProjectBuildManager::generateBuildCommands( const std::string& buildName,
const ProjectBuildi18nFn& i18n,
const std::string& buildType ) {
const std::string& buildType,
bool isClean ) {
const auto& buildIt = mBuilds.find( buildName );

if ( buildIt == mBuilds.end() )
Expand All @@ -337,7 +338,7 @@ ProjectBuildCommandsRes ProjectBuildManager::generateBuildCommands( const std::s
FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( curDoc ) );
ProjectBuildCommandsRes res;

auto finalBuild( build.replaceVars( build.mBuild ) );
auto finalBuild( build.replaceVars( isClean ? build.mClean : build.mBuild ) );

for ( const auto& step : finalBuild ) {
ProjectBuildCommand buildCmd( step );
Expand All @@ -358,76 +359,11 @@ ProjectBuildCommandsRes ProjectBuildManager::generateBuildCommands( const std::s
return res;
}

ProjectBuildCommandsRes ProjectBuildManager::build( const std::string& buildName,
const ProjectBuildi18nFn& i18n,
const std::string& buildType,
const ProjectBuildProgressFn& progressFn,
const ProjectBuildDoneFn& doneFn ) {
ProjectBuildCommandsRes res = generateBuildCommands( buildName, i18n, buildType );
if ( !res.isValid() )
return res;
if ( !mThreadPool ) {
res.errorMsg = i18n( "no_threads", "Threaded ecode required to compile builds." );
return res;
}

mThreadPool->run( [this, res, progressFn, doneFn, i18n, buildName, buildType]() {
runBuild( buildName, buildType, i18n, res, progressFn, doneFn );
} );

return res;
};

ProjectBuildCommandsRes ProjectBuildManager::generateCleanCommands( const std::string& buildName,
const ProjectBuildi18nFn& i18n,
const std::string& buildType ) {
const auto& buildIt = mBuilds.find( buildName );

if ( buildIt == mBuilds.end() )
return { i18n( "build_name_not_found", "Build name not found!" ) };

const auto& build = buildIt->second;

if ( !build.mBuildTypes.empty() && buildType.empty() )
return { i18n( "build_type_required", "Build type must be set!" ) };

std::string currentOS = String::toLower( Sys::getPlatform() );

if ( !build.isOSSupported( currentOS ) )
return {
i18n( "build_os_not_supported", "Operating System not supported for this build!" ) };

std::string nproc = String::format( "%d", Sys::getCPUCount() );
std::string curDoc = getCurrentDocument();
std::string curDocName =
FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( curDoc ) );
ProjectBuildCommandsRes res;

auto finalBuild( build.replaceVars( build.mClean ) );

for ( const auto& step : finalBuild ) {
ProjectBuildCommand buildCmd( step );
replaceVar( buildCmd, VAR_OS, currentOS );
replaceVar( buildCmd, VAR_NPROC, nproc );
replaceVar( buildCmd, VAR_CURRENT_DOC, curDoc );
replaceVar( buildCmd, VAR_CURRENT_DOC_NAME, curDocName );
if ( !buildType.empty() )
replaceVar( buildCmd, VAR_BUILD_TYPE, buildType );
buildCmd.config = build.mConfig;
res.cmds.emplace_back( std::move( buildCmd ) );
}

res.envs = build.mEnvs;

return res;
}

ProjectBuildCommandsRes ProjectBuildManager::clean( const std::string& buildName,
const ProjectBuildi18nFn& i18n,
const std::string& buildType,
const ProjectBuildProgressFn& progressFn,
const ProjectBuildDoneFn& doneFn ) {
ProjectBuildCommandsRes res = generateCleanCommands( buildName, i18n, buildType );
ProjectBuildCommandsRes
ProjectBuildManager::build( const std::string& buildName, const ProjectBuildi18nFn& i18n,
const std::string& buildType, const ProjectBuildProgressFn& progressFn,
const ProjectBuildDoneFn& doneFn, bool isClean ) {
ProjectBuildCommandsRes res = generateBuildCommands( buildName, i18n, buildType, isClean );
if ( !res.isValid() )
return res;
if ( !mThreadPool ) {
Expand Down Expand Up @@ -725,8 +661,8 @@ void ProjectBuildManager::cleanCurrentConfig( StatusBuildOutputController* sboc
build = &buildIt.second;

if ( build )
sboc->runClean( build->getName(), mConfig.buildType,
getOutputParser( build->getName() ) );
sboc->runBuild( build->getName(), mConfig.buildType,
getOutputParser( build->getName() ), true );
}
}

Expand Down Expand Up @@ -756,7 +692,8 @@ void ProjectBuildManager::runCurrentConfig( StatusBuildOutputController* /* not
UITerminal* term = mApp->getTerminalManager()->createTerminalInSplitter(
finalBuild.workingDir, false );
if ( term == nullptr || term->getTerm() == nullptr ) {
mApp->getTerminalManager()->openInExternalTerminal( cmd );
mApp->getTerminalManager()->openInExternalTerminal( cmd,
finalBuild.workingDir );
} else {
term->executeFile( cmd );
}
Expand Down
14 changes: 3 additions & 11 deletions src/tools/ecode/projectbuild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,12 @@ class ProjectBuildManager {
ProjectBuildCommandsRes build( const std::string& buildName, const ProjectBuildi18nFn& i18n,
const std::string& buildType = "",
const ProjectBuildProgressFn& progressFn = {},
const ProjectBuildDoneFn& doneFn = {} );
const ProjectBuildDoneFn& doneFn = {}, bool isClean = false );

ProjectBuildCommandsRes generateBuildCommands( const std::string& buildName,
const ProjectBuildi18nFn& i18n,
const std::string& buildType = "" );

ProjectBuildCommandsRes clean( const std::string& buildName, const ProjectBuildi18nFn& i18n,
const std::string& buildType = "",
const ProjectBuildProgressFn& progressFn = {},
const ProjectBuildDoneFn& doneFn = {} );

ProjectBuildCommandsRes generateCleanCommands( const std::string& buildName,
const ProjectBuildi18nFn& i18n,
const std::string& buildType = "" );
const std::string& buildType = "",
bool isClean = false );

ProjectBuildOutputParser getOutputParser( const std::string& buildName );

Expand Down
146 changes: 40 additions & 106 deletions src/tools/ecode/statusbuildoutputcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ static void safeInsertBuffer( TextDocument& doc, const std::string& buffer ) {

void StatusBuildOutputController::runBuild( const std::string& buildName,
const std::string& buildType,
const ProjectBuildOutputParser& outputParser ) {
const ProjectBuildOutputParser& outputParser,
bool isClean ) {
if ( nullptr == mApp->getProjectBuildManager() )
return;

Expand All @@ -111,7 +112,7 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
showBuildOutput();

mStatusResults.clear();
if ( mTableIssues )
if ( !isClean && mTableIssues )
mTableIssues->getSelection().clear();
mBuildOutput->getDocument().reset();
mBuildOutput->invalidateLongestLineWidth();
Expand Down Expand Up @@ -149,28 +150,48 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
mScrollLocked = true;

UIPushButton* buildButton = getBuildButton( mApp );
if ( buildButton )
buildButton->setText( mApp->i18n( "cancel_build", "Cancel Build" ) );
UIPushButton* cleanButton = getCleanButton( mApp );

bool enableBuildButton = false;
bool enableCleanButton = false;
if ( cleanButton && cleanButton->isEnabled() ) {

if ( isClean && buildButton && buildButton->isEnabled() ) {
buildButton->setEnabled( false );
enableBuildButton = true;
}

if ( !isClean && cleanButton && cleanButton->isEnabled() ) {
cleanButton->setEnabled( false );
enableCleanButton = true;
}

const auto updateBuildButton = [this, enableCleanButton]() {
if ( isClean ) {
if ( cleanButton )
cleanButton->setText( mApp->i18n( "cancel_clean", "Cancel Clean" ) );
} else {
if ( buildButton )
buildButton->setText( mApp->i18n( "cancel_build", "Cancel Build" ) );
}

const auto updateBuildButton = [this, isClean, enableBuildButton, enableCleanButton]() {
UIPushButton* buildButton = getBuildButton( mApp );
if ( buildButton ) {
UIPushButton* cleanButton = getCleanButton( mApp );

if ( !isClean && buildButton ) {
buildButton->runOnMainThread(
[this, buildButton] { buildButton->setText( mApp->i18n( "build", "Build" ) ); } );
}

if ( enableCleanButton ) {
UIPushButton* cleanButton = getCleanButton( mApp );
if ( cleanButton ) {
cleanButton->runOnMainThread( [cleanButton] { cleanButton->setEnabled( true ); } );
}
if ( isClean && cleanButton ) {
cleanButton->runOnMainThread(
[this, cleanButton] { cleanButton->setText( mApp->i18n( "clean", "Clean" ) ); } );
}

if ( enableBuildButton && buildButton )
buildButton->setEnabled( true );

if ( enableCleanButton && cleanButton )
cleanButton->runOnMainThread( [cleanButton] { cleanButton->setEnabled( true ); } );
};

auto res = pbm->build(
Expand Down Expand Up @@ -199,17 +220,19 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,
}
} while ( !buffer.empty() );
},
[this, updateBuildButton]( auto exitCode, const ProjectBuildCommand* cmd ) {
[this, updateBuildButton, isClean]( auto exitCode, const ProjectBuildCommand* cmd ) {
if ( !mCurLineBuffer.empty() && nullptr != cmd )
searchFindAndAddStatusResult( mPatternHolder, mCurLineBuffer, cmd );
String buffer;

if ( EXIT_SUCCESS == exitCode ) {
buffer = Sys::getDateTimeStr() + ": " +
mApp->i18n( "build_successful", "Build run successfully\n" );
( isClean ? mApp->i18n( "clean_successful", "Clean run successfully\n" )
: mApp->i18n( "build_successful", "Build run successfully\n" ) );
} else {
buffer = Sys::getDateTimeStr() + ": " +
mApp->i18n( "build_failed", "Build run with errors\n" );
( isClean ? mApp->i18n( "clean_failed", "Clean run with errors\n" )
: mApp->i18n( "build_failed", "Build run with errors\n" ) );
}

mBuildOutput->runOnMainThread( [this, buffer]() {
Expand All @@ -222,101 +245,12 @@ void StatusBuildOutputController::runBuild( const std::string& buildName,

if ( !mApp->getWindow()->hasFocus() )
mApp->getWindow()->flash( WindowFlashOperation::UntilFocused );
} );

if ( !res.isValid() ) {
mApp->getNotificationCenter()->addNotification( res.errorMsg );
updateBuildButton();
}
}

void StatusBuildOutputController::runClean( const std::string& buildName,
const std::string& buildType,
const ProjectBuildOutputParser& outputParser ) {
if ( nullptr == mApp->getProjectBuildManager() )
return;

auto pbm = mApp->getProjectBuildManager();

show();

mBuildOutput->getDocument().reset();
mBuildOutput->invalidateLongestLineWidth();
mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y );

std::vector<SyntaxPattern> patterns;

for ( const auto& parser : outputParser.getConfig() ) {
SyntaxPattern ptn( { parser.pattern }, getProjectOutputParserTypeToString( parser.type ) );
patterns.emplace_back( std::move( ptn ) );
}

patterns.emplace_back(
SyntaxPattern( { "%d%d%d%d%-%d%d%-%d%d%s%d%d%:%d%d%:%d%d%:.*error.*[^\n]+" }, "error" ) );
patterns.emplace_back( SyntaxPattern(
{ "%d%d%d%d%-%d%d%-%d%d%s%d%d%:%d%d%:%d%d%:.*warning.*[^\n]+" }, "warning" ) );
patterns.emplace_back(
SyntaxPattern( { "%d%d%d%d%-%d%d%-%d%d%s%d%d%:%d%d%:%d%d%:[^\n]+" }, "notice" ) );

SyntaxDefinition synDef( "custom_build", {}, std::move( patterns ) );

mBuildOutput->getDocument().setSyntaxDefinition( synDef );
mBuildOutput->getVScrollBar()->setValue( 1.f );
mScrollLocked = true;

UIPushButton* buildButton = getBuildButton( mApp );
bool enableBuildButton = false;
if ( buildButton && buildButton->isEnabled() ) {
buildButton->setEnabled( false );
enableBuildButton = true;
}
UIPushButton* cleanButton = getCleanButton( mApp );
if ( cleanButton )
cleanButton->setText( mApp->i18n( "cancel_clean", "Cancel Clean" ) );

auto res = pbm->clean(
buildName, [this]( const auto& key, const auto& def ) { return mApp->i18n( key, def ); },
buildType,
[this]( auto, auto buffer, auto ) {
mBuildOutput->runOnMainThread( [this, buffer]() {
safeInsertBuffer( mBuildOutput->getDocument(), buffer );
if ( mScrollLocked )
mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y );
} );
},
[this, enableBuildButton]( auto exitCode, auto ) {
String buffer;

if ( EXIT_SUCCESS == exitCode ) {
buffer = Sys::getDateTimeStr() + ": " +
mApp->i18n( "clean_successful", "Clean run successfully\n" );
} else {
buffer = Sys::getDateTimeStr() + ": " +
mApp->i18n( "clean_failed", "Clean run with errors\n" );
}

mBuildOutput->runOnMainThread( [this, buffer]() {
safeInsertBuffer( mBuildOutput->getDocument(), buffer );
if ( mScrollLocked )
mBuildOutput->setScrollY( mBuildOutput->getMaxScroll().y );
} );

UIPushButton* cleanButton = getCleanButton( mApp );
if ( cleanButton )
cleanButton->setText( mApp->i18n( "clean", "Clean" ) );

if ( enableBuildButton ) {
UIPushButton* buildButton = getBuildButton( mApp );
if ( buildButton )
buildButton->setEnabled( true );
}

if ( !mApp->getWindow()->hasFocus() )
mApp->getWindow()->flash( WindowFlashOperation::UntilFocused );
} );
isClean );

if ( !res.isValid() ) {
mApp->getNotificationCenter()->addNotification( res.errorMsg );
updateBuildButton();
}
}

Expand Down
Loading

0 comments on commit 944d6ee

Please sign in to comment.