Minimize amount of code to rebuild when switching options

This commit is contained in:
Ilya Fedin 2023-09-22 04:24:11 +04:00 committed by John Preston
parent 3db0b11a6b
commit 1bde096417
16 changed files with 82 additions and 51 deletions

View File

@ -281,7 +281,7 @@ int main(int argc, char *argv[])
cout << "Compression start, size: " << resultSize << "\n";
QByteArray compressed, resultCheck;
#if defined Q_OS_WIN && !defined DESKTOP_APP_USE_PACKAGED // use Lzma SDK for win
#if defined Q_OS_WIN && !defined TDESKTOP_USE_PACKAGED // use Lzma SDK for win
const int32 hSigLen = 128, hShaLen = 20, hPropsLen = LZMA_PROPS_SIZE, hOriginalSizeLen = sizeof(int32), hSize = hSigLen + hShaLen + hPropsLen + hOriginalSizeLen; // header
compressed.resize(hSize + resultSize + 1024 * 1024); // rsa signature + sha1 + lzma props + max compressed size

View File

@ -27,7 +27,7 @@ extern "C" {
#include <openssl/evp.h>
} // extern "C"
#if defined Q_OS_WIN && !defined DESKTOP_APP_USE_PACKAGED // use Lzma SDK for win
#if defined Q_OS_WIN && !defined TDESKTOP_USE_PACKAGED // use Lzma SDK for win
#include <LzmaLib.h>
#else
#include <lzma.h>

View File

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <new>
#include <mutex>
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
#ifdef Q_OS_WIN
#include <new.h>
@ -48,7 +48,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#endif // Q_OS_MAC
#endif // Q_OS_WIN
#endif // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
namespace CrashReports {
namespace {
@ -59,7 +59,7 @@ using AnnotationRefs = std::map<std::string, const QString*>;
Annotations ProcessAnnotations;
AnnotationRefs ProcessAnnotationRefs;
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
QString ReportPath;
FILE *ReportFile = nullptr;
@ -290,7 +290,7 @@ bool DumpCallback(const google_breakpad::MinidumpDescriptor &md, void *context,
}
#endif // !Q_OS_MAC || MAC_USE_BREAKPAD
#endif // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
} // namespace
@ -314,7 +314,7 @@ QString PlatformString() {
}
void StartCatching() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
ProcessAnnotations["Binary"] = cExeName().toUtf8().constData();
ProcessAnnotations["ApiId"] = QString::number(ApiId).toUtf8().constData();
ProcessAnnotations["Version"] = (cAlphaVersion()
@ -380,21 +380,21 @@ void StartCatching() {
-1
);
#endif // else for Q_OS_WIN || Q_OS_MAC
#endif // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
}
void FinishCatching() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
#if !defined Q_OS_MAC || defined MAC_USE_BREAKPAD
delete base::take(BreakpadExceptionHandler);
#endif // !Q_OS_MAC || MAC_USE_BREAKPAD
#endif // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
}
StartResult Start() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
ReportPath = cWorkingDir() + u"tdata/working"_q;
#ifdef Q_OS_WIN
@ -420,12 +420,12 @@ StartResult Start() {
return lastdump;
}
#endif // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
return Restart();
}
Status Restart() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
if (ReportFile) {
return Started;
}
@ -470,13 +470,13 @@ Status Restart() {
LOG(("FATAL: Could not open '%1' for writing!").arg(ReportPath));
return CantOpen;
#else // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#else // !TDESKTOP_DISABLE_CRASH_REPORTS
return Started;
#endif // else for !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // else for !TDESKTOP_DISABLE_CRASH_REPORTS
}
void Finish() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
FinishCatching();
if (ReportFile) {
@ -489,7 +489,7 @@ void Finish() {
unlink(ReportPath.toUtf8().constData());
#endif // else for Q_OS_WIN
}
#endif // !DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
}
void SetAnnotation(const std::string &key, const QString &value) {
@ -539,7 +539,7 @@ void SetAnnotationRef(const std::string &key, const QString *valuePtr) {
}
}
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
dump::~dump() {
if (ReportFile) {
@ -604,6 +604,6 @@ const dump &operator<<(const dump &stream, double num) {
return stream;
}
#endif // DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // TDESKTOP_DISABLE_CRASH_REPORTS
} // namespace CrashReports

View File

@ -11,7 +11,7 @@ namespace CrashReports {
QString PlatformString();
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
struct dump {
~dump();
@ -24,7 +24,7 @@ const dump &operator<<(const dump &stream, unsigned long num);
const dump &operator<<(const dump &stream, unsigned long long num);
const dump &operator<<(const dump &stream, double num);
#endif // DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // TDESKTOP_DISABLE_CRASH_REPORTS
enum Status {
CantOpen,

View File

@ -42,11 +42,11 @@ extern "C" {
} // extern "C"
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
#if defined Q_OS_WIN && !defined DESKTOP_APP_USE_PACKAGED // use Lzma SDK for win
#if defined Q_OS_WIN && !defined TDESKTOP_USE_PACKAGED // use Lzma SDK for win
#include <LzmaLib.h>
#else // Q_OS_WIN && !DESKTOP_APP_USE_PACKAGED
#else // Q_OS_WIN && !TDESKTOP_USE_PACKAGED
#include <lzma.h>
#endif // else of Q_OS_WIN && !DESKTOP_APP_USE_PACKAGED
#endif // else of Q_OS_WIN && !TDESKTOP_USE_PACKAGED
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
#ifndef Q_OS_WIN
@ -275,11 +275,11 @@ bool UnpackUpdate(const QString &filepath) {
return false;
}
#if defined Q_OS_WIN && !defined DESKTOP_APP_USE_PACKAGED // use Lzma SDK for win
#if defined Q_OS_WIN && !defined TDESKTOP_USE_PACKAGED // use Lzma SDK for win
const int32 hSigLen = 128, hShaLen = 20, hPropsLen = LZMA_PROPS_SIZE, hOriginalSizeLen = sizeof(int32), hSize = hSigLen + hShaLen + hPropsLen + hOriginalSizeLen; // header
#else // Q_OS_WIN && !DESKTOP_APP_USE_PACKAGED
#else // Q_OS_WIN && !TDESKTOP_USE_PACKAGED
const int32 hSigLen = 128, hShaLen = 20, hPropsLen = 0, hOriginalSizeLen = sizeof(int32), hSize = hSigLen + hShaLen + hOriginalSizeLen; // header
#endif // Q_OS_WIN && !DESKTOP_APP_USE_PACKAGED
#endif // Q_OS_WIN && !TDESKTOP_USE_PACKAGED
QByteArray compressed = input.readAll();
int32 compressedLen = compressed.size() - hSize;
@ -350,14 +350,14 @@ bool UnpackUpdate(const QString &filepath) {
uncompressed.resize(uncompressedLen);
size_t resultLen = uncompressed.size();
#if defined Q_OS_WIN && !defined DESKTOP_APP_USE_PACKAGED // use Lzma SDK for win
#if defined Q_OS_WIN && !defined TDESKTOP_USE_PACKAGED // use Lzma SDK for win
SizeT srcLen = compressedLen;
int uncompressRes = LzmaUncompress((uchar*)uncompressed.data(), &resultLen, (const uchar*)(compressed.constData() + hSize), &srcLen, (const uchar*)(compressed.constData() + hSigLen + hShaLen), LZMA_PROPS_SIZE);
if (uncompressRes != SZ_OK) {
LOG(("Update Error: could not uncompress lzma, code: %1").arg(uncompressRes));
return false;
}
#else // Q_OS_WIN && !DESKTOP_APP_USE_PACKAGED
#else // Q_OS_WIN && !TDESKTOP_USE_PACKAGED
lzma_stream stream = LZMA_STREAM_INIT;
lzma_ret ret = lzma_stream_decoder(&stream, UINT64_MAX, LZMA_CONCATENATED);
@ -400,7 +400,7 @@ bool UnpackUpdate(const QString &filepath) {
LOG(("Error in decompression: %1 (error code %2)").arg(msg).arg(res));
return false;
}
#endif // Q_OS_WIN && !DESKTOP_APP_USE_PACKAGED
#endif // Q_OS_WIN && !TDESKTOP_USE_PACKAGED
tempDir.mkdir(tempDir.absolutePath());

View File

@ -10,10 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/algorithm.h"
#include "logs.h"
#if !defined DESKTOP_APP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
#if !defined TDESKTOP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
#include "base/platform/linux/base_linux_library.h"
#include <deque>
#endif // !DESKTOP_APP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
#endif // !TDESKTOP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
#include <QImage>
@ -90,7 +90,7 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
#endif // LIB_FFMPEG_USE_QT_PRIVATE_API
}
#if !defined DESKTOP_APP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
#if !defined TDESKTOP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
[[nodiscard]] auto CheckHwLibs() {
auto list = std::deque{
AV_PIX_FMT_CUDA,
@ -116,7 +116,7 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
}
return list;
}
#endif // !DESKTOP_APP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
#endif // !TDESKTOP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
[[nodiscard]] bool InitHw(AVCodecContext *context, AVHWDeviceType type) {
AVCodecContext *parent = static_cast<AVCodecContext*>(context->opaque);
@ -158,9 +158,9 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
}
return false;
};
#if !defined DESKTOP_APP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
#if !defined TDESKTOP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
static const auto list = CheckHwLibs();
#else // !DESKTOP_APP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
#else // !TDESKTOP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
const auto list = std::array{
#ifdef Q_OS_WIN
AV_PIX_FMT_D3D11,
@ -174,7 +174,7 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
AV_PIX_FMT_CUDA,
#endif // Q_OS_WIN || Q_OS_MAC
};
#endif // DESKTOP_APP_USE_PACKAGED || Q_OS_WIN || Q_OS_MAC
#endif // TDESKTOP_USE_PACKAGED || Q_OS_WIN || Q_OS_MAC
for (const auto format : list) {
if (!has(format)) {
continue;

View File

@ -155,10 +155,10 @@ std::optional<bool> IsDarkMode() {
#endif // Qt < 6.5.0
void WriteCrashDumpDetails() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
double v = objc_appkitVersion();
CrashReports::dump() << "OS-Version: " << v;
#endif // DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // TDESKTOP_DISABLE_CRASH_REPORTS
}
// I do check for availability, just not in the exact way clang is content with

View File

@ -482,7 +482,7 @@ bool AutostartSkip() {
}
void WriteCrashDumpDetails() {
#ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
PROCESS_MEMORY_COUNTERS data = { 0 };
if (Dlls::GetProcessMemoryInfo
&& Dlls::GetProcessMemoryInfo(
@ -503,7 +503,7 @@ void WriteCrashDumpDetails() {
<< (data.PagefileUsage / mb)
<< " MB (current)\n";
}
#endif // DESKTOP_APP_DISABLE_CRASH_REPORTS
#endif // TDESKTOP_DISABLE_CRASH_REPORTS
}
void SetWindowPriority(not_null<QWidget*> window, uint32 priority) {

View File

@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
namespace {
#ifdef DESKTOP_APP_SPECIAL_TARGET
constexpr auto kMinimalSkip = 7;
constexpr auto kSoonSkip = 30;
constexpr auto kNowSkip = 90;
@ -148,14 +147,12 @@ void Closed(const QString &workingDir) {
reinterpret_cast<const char*>(&value),
sizeof(qint32)));
}
#endif // DESKTOP_APP_SPECIAL_TARGET
} // namespace
object_ptr<RpWidget> CreateOutdatedBar(
not_null<QWidget*> parent,
const QString &workingPath) {
#ifdef DESKTOP_APP_SPECIAL_TARGET
const auto date = Platform::WhenSystemBecomesOutdated();
if (date.isNull()) {
return { nullptr };
@ -178,9 +175,6 @@ object_ptr<RpWidget> CreateOutdatedBar(
wrap->show(anim::type::instant);
return result;
#else // DESKTOP_APP_SPECIAL_TARGET
return { nullptr };
#endif // DESKTOP_APP_SPECIAL_TARGET
}
} // namespace Ui

View File

@ -0,0 +1,18 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/controls/window_outdated_bar.h"
namespace Ui {
object_ptr<RpWidget> CreateOutdatedBar(
not_null<QWidget*> parent,
const QString &workingPath) {
return { nullptr };
}
} // namespace Ui

View File

@ -261,6 +261,7 @@ PRIVATE
ui/controls/who_reacted_context_action.cpp
ui/controls/who_reacted_context_action.h
ui/controls/window_outdated_bar.cpp
ui/controls/window_outdated_bar_dummy.cpp
ui/controls/window_outdated_bar.h
ui/effects/fireworks_animation.cpp
ui/effects/fireworks_animation.h
@ -331,6 +332,16 @@ PRIVATE
ui/ui_pch.h
)
if (DESKTOP_APP_SPECIAL_TARGET)
remove_target_sources(td_ui ${src_loc}
ui/controls/window_outdated_bar_dummy.cpp
)
else()
remove_target_sources(td_ui ${src_loc}
ui/controls/window_outdated_bar.cpp
)
endif()
target_include_directories(td_ui
PUBLIC
${src_loc}

View File

@ -40,6 +40,14 @@ if (DESKTOP_APP_DISABLE_AUTOUPDATE)
target_compile_definitions(Telegram PRIVATE TDESKTOP_DISABLE_AUTOUPDATE)
endif()
if (DESKTOP_APP_DISABLE_CRASH_REPORTS)
target_compile_definitions(Telegram PRIVATE TDESKTOP_DISABLE_CRASH_REPORTS)
endif()
if (DESKTOP_APP_USE_PACKAGED)
target_compile_definitions(Telegram PRIVATE TDESKTOP_USE_PACKAGED)
endif()
if (DESKTOP_APP_SPECIAL_TARGET)
target_compile_definitions(Telegram PRIVATE TDESKTOP_ALLOW_CLOSED_ALPHA)
endif()

@ -1 +1 @@
Subproject commit 28db382a7471854fea4d41133becdcc6c161d907
Subproject commit 6de11e6ab705f27158f338e3e17c8b0767750721

@ -1 +1 @@
Subproject commit e240a2de8e67c806894caf04ee32797e75c6ea38
Subproject commit 1a700e5a0d7c3e2f617530354ff2a47c5c72bb4a

@ -1 +1 @@
Subproject commit a33bd4e0a590fb08f0055b6e859ce84db11eb843
Subproject commit d3ac9dcf97494aa1acfbfd8b6c0a3f57950e4962

2
cmake

@ -1 +1 @@
Subproject commit 18d4aae269c51d5b24e96957abbdb389a1270122
Subproject commit 0ae4e78a12d7fdea687ca52647465b9cf9ef95ee