Skip to content

Commit

Permalink
Add iconv detection for GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoHao committed Dec 11, 2024
1 parent 57c521f commit d121c97
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion RedPandaIDE/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ QStringList Compiler::getCharsetArgument(const QByteArray& encoding,FileType fil
}
}
if ((forceExecUTF8 || compilerSet()->autoAddCharsetParams()) && encoding != ENCODING_ASCII
&& compilerSet()->compilerType()!=CompilerType::Clang) {
&& compilerSet()->supportConvertingCharset()) {
QString encodingName;
QString execEncodingName;
QString compilerSetExecCharset = compilerSet()->execCharset();
Expand Down
28 changes: 0 additions & 28 deletions RedPandaIDE/compiler/compilerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,6 @@ QList<PCompilerOption> CompilerInfoManager::getCompilerOptions(CompilerType comp
return pInfo->compilerOptions();
}

bool CompilerInfoManager::supportCovertingCharset(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->supportConvertingCharset();
}

bool CompilerInfoManager::supportStaticLink(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
Expand Down Expand Up @@ -330,11 +322,6 @@ ClangCompilerInfo::ClangCompilerInfo():CompilerInfo(COMPILER_CLANG)
{
}

bool ClangCompilerInfo::supportConvertingCharset()
{
return false;
}

bool ClangCompilerInfo::forceUTF8InDebugger()
{
return true;
Expand All @@ -354,11 +341,6 @@ GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC)
{
}

bool GCCCompilerInfo::supportConvertingCharset()
{
return true;
}

bool GCCCompilerInfo::forceUTF8InDebugger()
{
return false;
Expand All @@ -378,11 +360,6 @@ GCCUTF8CompilerInfo::GCCUTF8CompilerInfo():CompilerInfo(COMPILER_GCC_UTF8)
{
}

bool GCCUTF8CompilerInfo::supportConvertingCharset()
{
return true;
}

bool GCCUTF8CompilerInfo::forceUTF8InDebugger()
{
return true;
Expand All @@ -404,11 +381,6 @@ SDCCCompilerInfo::SDCCCompilerInfo():CompilerInfo(COMPILER_SDCC)

}

bool SDCCCompilerInfo::supportConvertingCharset()
{
return false;
}

bool SDCCCompilerInfo::forceUTF8InDebugger()
{
return false;
Expand Down
6 changes: 0 additions & 6 deletions RedPandaIDE/compiler/compilerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class CompilerInfo
bool hasCompilerOption(const QString& key) const;
void init();

virtual bool supportConvertingCharset()=0;
virtual bool forceUTF8InDebugger()=0;
virtual bool forceUTF8InMakefile()=0;
virtual bool supportStaticLink()=0;
Expand Down Expand Up @@ -173,7 +172,6 @@ class CompilerInfoManager {
static bool hasCompilerOption(CompilerType compilerType, const QString& optKey);
static PCompilerOption getCompilerOption(CompilerType compilerType, const QString& optKey);
static QList<PCompilerOption> getCompilerOptions(CompilerType compilerType);
static bool supportCovertingCharset(CompilerType compilerType);
static bool supportStaticLink(CompilerType compilerType);
static bool supportSyntaxCheck(CompilerType compilerType);
static bool forceUTF8InDebugger(CompilerType compilerType);
Expand All @@ -187,7 +185,6 @@ class CompilerInfoManager {
class ClangCompilerInfo: public CompilerInfo{
public:
ClangCompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
Expand All @@ -196,7 +193,6 @@ class ClangCompilerInfo: public CompilerInfo{
class GCCCompilerInfo: public CompilerInfo{
public:
GCCCompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
Expand All @@ -205,7 +201,6 @@ class GCCCompilerInfo: public CompilerInfo{
class GCCUTF8CompilerInfo: public CompilerInfo{
public:
GCCUTF8CompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
Expand All @@ -215,7 +210,6 @@ class GCCUTF8CompilerInfo: public CompilerInfo{
class SDCCCompilerInfo: public CompilerInfo{
public:
SDCCCompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
bool supportStaticLink() override;
Expand Down
2 changes: 1 addition & 1 deletion RedPandaIDE/compiler/projectcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
// Or roll our own
} else {
QString encodingStr;
if (compilerSet()->compilerType() != CompilerType::Clang && mProject->options().addCharset) {
if (compilerSet()->supportConvertingCharset() && mProject->options().addCharset) {
QByteArray defaultSystemEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
QByteArray encoding = mProject->options().execEncoding;
QByteArray targetEncoding;
Expand Down
32 changes: 32 additions & 0 deletions RedPandaIDE/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ Settings::CompilerSet::CompilerSet():
mCompilationStage{Settings::CompilerSet::CompilationStage::GenerateExecutable}
#ifdef Q_OS_WINDOWS
, mGccIsUtf8Initialized(false)
, mGccSupportConvertingCharsetInitialized(false)
#endif
{

Expand All @@ -1675,6 +1676,7 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder, const QString&
mCompilationStage{Settings::CompilerSet::CompilationStage::GenerateExecutable}
#ifdef Q_OS_WINDOWS
, mGccIsUtf8Initialized(false)
, mGccSupportConvertingCharsetInitialized(false)
#endif
{
QDir dir(compilerFolder);
Expand Down Expand Up @@ -1748,6 +1750,8 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set):
#ifdef Q_OS_WINDOWS
, mGccIsUtf8(set.mGccIsUtf8)
, mGccIsUtf8Initialized(set.mGccIsUtf8Initialized)
, mGccSupportConvertingCharset(set.mGccSupportConvertingCharset)
, mGccSupportConvertingCharsetInitialized(set.mGccSupportConvertingCharsetInitialized)
#endif
{

Expand Down Expand Up @@ -1794,6 +1798,7 @@ Settings::CompilerSet::CompilerSet(const QJsonObject &set) :
mCompileOptions{} // handle later
#ifdef Q_OS_WINDOWS
, mGccIsUtf8Initialized(false)
, mGccSupportConvertingCharsetInitialized(false)
#endif
{
foreach (const QJsonValue &dir, set["binDirs"].toArray())
Expand Down Expand Up @@ -2928,6 +2933,33 @@ bool Settings::CompilerSet::isCompilerInfoUsingUTF8()
}
#endif

bool Settings::CompilerSet::supportConvertingCharset()
{
#ifdef Q_OS_WIN
if (mCompilerType != CompilerType::GCC && mCompilerType != CompilerType::GCC_UTF8)
return false;
if (!mGccSupportConvertingCharsetInitialized) {
mGccSupportConvertingCharset = [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("--with-libiconv") && !configuration.contains("--with-libiconv=no");
} ();
mGccSupportConvertingCharsetInitialized = true;
}
return mGccSupportConvertingCharset;
#else
// Unix: iconv is a part of POSIX standard.
return mCompilerType == CompilerType::GCC || mCompilerType == CompilerType::GCC_UTF8;
#endif
}

const QString &Settings::CompilerSet::assemblingSuffix() const
{
return mAssemblingSuffix;
Expand Down
4 changes: 4 additions & 0 deletions RedPandaIDE/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,8 @@ class Settings
constexpr bool isCompilerInfoUsingUTF8() const { return true; }
#endif

bool supportConvertingCharset();

bool persistInAutoFind() const;
void setPersistInAutoFind(bool newPersistInAutoFind);

Expand Down Expand Up @@ -1549,6 +1551,8 @@ class Settings
// GCC ACP detection cache
bool mGccIsUtf8;
bool mGccIsUtf8Initialized;
bool mGccSupportConvertingCharset;
bool mGccSupportConvertingCharsetInitialized;
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void CompilerSetOptionWidget::init()


static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSetOptionWidget* ui) {
bool supportCharset = CompilerInfoManager::supportCovertingCharset(pSet->compilerType());
bool supportCharset = pSet->supportConvertingCharset();
ui->chkAutoAddCharset->setEnabled(supportCharset);
ui->cbEncoding->setEnabled(supportCharset);
ui->cbEncodingDetails->setEnabled(supportCharset);
Expand Down

0 comments on commit d121c97

Please sign in to comment.