Skip to content

Commit

Permalink
auto hide the option "force gcc output english info" for nls-disabled…
Browse files Browse the repository at this point in the history
… gcc
  • Loading branch information
royqh1979 committed Dec 27, 2024
1 parent edbaf17 commit f2702a9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion RedPandaIDE/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void Compiler::runCommand(const QString &cmd, const QStringList &arguments, cons
env.insert("PATH",path);
}
#endif
if (compilerSet() && compilerSet()->forceEnglishOutput())
if (compilerSet() && compilerSet()->supportNLS() && compilerSet()->forceEnglishOutput())
env.insert("LANG","en");
//env.insert("LDFLAGS","-Wl,--stack,12582912");
env.insert("LDFLAGS","");
Expand Down
43 changes: 37 additions & 6 deletions RedPandaIDE/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,10 +1666,12 @@ Settings::CompilerSet::CompilerSet():
mCompilationProperSuffix{DEFAULT_COMPILATION_SUFFIX},
mAssemblingSuffix{DEFAULT_ASSEMBLING_SUFFIX},
mExecutableSuffix{DEFAULT_EXECUTABLE_SUFFIX},
mCompilationStage{Settings::CompilerSet::CompilationStage::GenerateExecutable}
mCompilationStage{Settings::CompilerSet::CompilationStage::GenerateExecutable},
mGccSupportNLS{false},
mGccSupportNLSInitialized{false}
#ifdef Q_OS_WINDOWS
, mGccIsUtf8Initialized(false)
, mGccSupportConvertingCharsetInitialized(false)
, mGccIsUtf8Initialized{false}
, mGccSupportConvertingCharsetInitialized{false}
#endif
{

Expand All @@ -1686,7 +1688,9 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder, const QString&
mCompilationProperSuffix{DEFAULT_COMPILATION_SUFFIX},
mAssemblingSuffix{DEFAULT_ASSEMBLING_SUFFIX},
mExecutableSuffix{DEFAULT_EXECUTABLE_SUFFIX},
mCompilationStage{Settings::CompilerSet::CompilationStage::GenerateExecutable}
mCompilationStage{Settings::CompilerSet::CompilationStage::GenerateExecutable},
mGccSupportNLS{false},
mGccSupportNLSInitialized{false}
#ifdef Q_OS_WINDOWS
, mGccIsUtf8Initialized(false)
, mGccSupportConvertingCharsetInitialized(false)
Expand Down Expand Up @@ -1759,7 +1763,9 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set):
mAssemblingSuffix{set.mAssemblingSuffix},
mExecutableSuffix{set.mExecutableSuffix},
mCompilationStage{set.mCompilationStage},
mCompileOptions{set.mCompileOptions}
mCompileOptions{set.mCompileOptions},
mGccSupportNLS{set.mGccSupportNLS},
mGccSupportNLSInitialized{set.mGccSupportNLSInitialized}
#ifdef Q_OS_WINDOWS
, mGccIsUtf8(set.mGccIsUtf8)
, mGccIsUtf8Initialized(set.mGccIsUtf8Initialized)
Expand Down Expand Up @@ -1808,7 +1814,9 @@ Settings::CompilerSet::CompilerSet(const QJsonObject &set) :
mAssemblingSuffix{set["assemblingSuffix"].toString()},
mExecutableSuffix{set["executableSuffix"].toString()},
mCompilationStage{CompilationStage(set["compilationStage"].toInt())},
mCompileOptions{} // handle later
mCompileOptions{}, // handle later
mGccSupportNLS{false},
mGccSupportNLSInitialized{false}
#ifdef Q_OS_WINDOWS
, mGccIsUtf8Initialized(false)
, mGccSupportConvertingCharsetInitialized(false)
Expand Down Expand Up @@ -2982,6 +2990,29 @@ bool Settings::CompilerSet::supportConvertingCharset()
#endif
}

bool Settings::CompilerSet::supportNLS()
{
if (mCompilerType != CompilerType::GCC && mCompilerType != CompilerType::GCC_UTF8)
return false;
if (!mGccSupportNLSInitialized) {
mGccSupportNLS = [this] () {
QByteArray verboseOut = getCompilerOutput(QFileInfo(mCCompiler).dir().path(), mCCompiler, {"-v"});
QByteArray targetStr = "Configured with: ";
int configurationPos = verboseOut.indexOf(targetStr);
if (configurationPos < 0)
return false;
int endPos = verboseOut.indexOf('\n', configurationPos);
if (endPos < 0)
return false;
QByteArray configuration = verboseOut.mid(configurationPos + targetStr.size(), endPos - configurationPos - targetStr.size());
return configuration.contains("--enable-nls") && !configuration.contains("--disable-nls");
} ();
mGccSupportNLSInitialized = true;
}
return mGccSupportNLS;

}

const QString &Settings::CompilerSet::assemblingSuffix() const
{
return mAssemblingSuffix;
Expand Down
3 changes: 3 additions & 0 deletions RedPandaIDE/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ class Settings
#endif

bool supportConvertingCharset();
bool supportNLS();

bool persistInAutoFind() const;
void setPersistInAutoFind(bool newPersistInAutoFind);
Expand Down Expand Up @@ -1557,6 +1558,8 @@ class Settings
// Options
QMap<QString,QString> mCompileOptions;

bool mGccSupportNLS;
bool mGccSupportNLSInitialized;
#ifdef Q_OS_WINDOWS
// GCC ACP detection cache
bool mGccIsUtf8;
Expand Down
4 changes: 4 additions & 0 deletions RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ void CompilerSetOptionWidget::init()

static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSetOptionWidget* ui) {
bool supportCharset = pSet->supportConvertingCharset();
bool supportNLS = pSet->supportNLS();
ui->chkAutoAddCharset->setEnabled(supportCharset);
ui->cbEncoding->setEnabled(supportCharset);
ui->cbEncodingDetails->setEnabled(supportCharset);
ui->panelCharset->setVisible(supportCharset);
ui->chkAutoAddCharset->setEnabled(supportCharset);
ui->chkAutoAddCharset->setVisible(supportCharset);

ui->chkForceEnglishOutput->setEnabled(supportNLS);
ui->chkForceEnglishOutput->setVisible(supportNLS);

bool supportStaticLink = CompilerInfoManager::supportStaticLink(pSet->compilerType());
ui->chkStaticLink->setEnabled(supportStaticLink);
ui->chkStaticLink->setVisible(supportStaticLink);
Expand Down

0 comments on commit f2702a9

Please sign in to comment.