课程代码仓库初始化:Part1 (144) + Part3 (29) 全量生成与验证
把川大 wiki「02.Qt方向」课程代码整理为 CMake 管理的可编译运行项目。
Part1 C/C++ 强化 (p01/, 144 目标, host gcc/g++ 构建, 全绿):
- 修复全部编译失败:补 <cstring>/<fstream>/<iomanip>/<vector> 等缺失头
(common_fix + infer_stl_includes 自动检测注入)、修正 pause() 壳注入
(改检测已转换后的 pause 调用)、namespace 提升出函数体、const 成员函数
正确性、dedupe 不再破坏函数重载集、K&R 隐式 int / 动态异常规范等
C++17 移除特性的可编译等价改写。
- 目录采用深缩写 p01/ch04/s03/ (原 part1_cpp/ch04_class_object/03_ctor_dtor)。
Part3 Qt 桌面 (p03/, 29 目标, 隔离 Qt 5.14.2 构建, 全绿):
- gen_part3.py: Qt 外壳模板 (main+QApplication+show, QTimer 自动退出便于
offscreen 验证)、AUTOMOC + .moc include、rewrite_* 处理散文混入/重载/
资源依赖、生成占位 png/gif + .qrc + rundata 样例数据。
- 修正 QLable 笔误、全角分号、.→->、Windows 路径、QApplication 阻塞事件
循环改为 QCoreApplication 等。
任务1 概念/版本验证:
- tools/std_probe.py: 跨 -std= 编译探针 (--pedantic-errors 让已废除特性硬失败)。
- tools/demo_versions/: K&R 隐式 int、三目左值、void* 转换、enum 赋整、
const 经指针、动态异常规范 共 6 个跨版本演示。
- docs/VERSION_NOTES.md: 每条「原文说法→C17/C++17 是否成立→何版本成立→已验证」。
文档: 顶层 README、docs/SOURCE_PAGES.md (页面→目录映射)、
docs/ERRATA.md (Part1 修正)、docs/ERRATA_part3.md (Part3 修正)。
另修复 tools/run.sh / run_qt.sh 的 ${1:?...} 引号语法 bug。
隔离 Qt 验证: ldd 0 系统 Qt 引用; 173/173 目标全绿; p03 offscreen 运行通过。
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# ==============================================================================
|
||||
# Build-container image for the qt-course repo.
|
||||
#
|
||||
# Usage model (see docker_install_qt.sh / docker_build.sh / docker_run_qt.sh):
|
||||
# 1. Install isolated Qt 5.14.2 INTO THE REPO at .qt514/ (one-off, ~577MB).
|
||||
# The Qt files live on the host filesystem, mounted into the container.
|
||||
# 2. Build the Qt part from a container, writing into the mounted build/.
|
||||
# 3. RUN the compiled Qt apps on the HOST (no container needed) using
|
||||
# LD_LIBRARY_PATH=.qt514/.../lib — host & container share glibc 2.39,
|
||||
# so binaries built in the container run natively on the host. Isolation
|
||||
# from the system Qt 5.15 is by prefix + LD_LIBRARY_PATH, not by the
|
||||
# container boundary.
|
||||
#
|
||||
# This image only needs the build toolchain + aqtinstall. It is small and
|
||||
# stable (no multi-GB Qt layer baked in; Qt is downloaded into the mount).
|
||||
# ------------------------------------------------------------------------------
|
||||
FROM ubuntu:24.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# Build toolchain matching the host (gcc 13.3, cmake 3.28, ninja) + runtime
|
||||
# libs so the container can also run GUI examples with X11 forwarding if needed.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential g++ gcc cmake ninja-build git \
|
||||
ca-certificates python3 python3-pip python3-venv \
|
||||
libgl1 libegl1 libxkbcommon0 libdbus-1-3 \
|
||||
libfontconfig1 libfreetype6 libxcb-cursor0 \
|
||||
fontconfig xauth x11-xserver-utils \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip3 install --break-system-packages aqtinstall
|
||||
|
||||
WORKDIR /workspace
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build-container: run ONE build pass of the repo (CMake configure + compile),
|
||||
# mounting the repo so build artifacts land on the host filesystem.
|
||||
#
|
||||
# Usage: tools/docker/docker_build.sh [extra cmake args...]
|
||||
# It builds BOTH part1 (C/C++) and part3 (Qt) unless you pass args to restrict.
|
||||
# The Qt part is pointed at the isolated .qt514/ toolchain.
|
||||
#
|
||||
# After this, run compiled apps on the HOST with tools/run_qt.sh / tools/run.sh.
|
||||
set -euo pipefail
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
IMAGE_TAG="qt-course:builder"
|
||||
QT_ROOT="/workspace/.qt514/5.14.2/gcc_64"
|
||||
|
||||
if [ ! -x "$REPO_ROOT/.qt514/5.14.2/gcc_64/bin/qmake" ]; then
|
||||
echo ">> Isolated Qt not found at .qt514/. Run tools/docker/docker_install_qt.sh first." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker run --rm \
|
||||
-v "$REPO_ROOT:/workspace" \
|
||||
-w /workspace \
|
||||
"$IMAGE_TAG" \
|
||||
bash -lc "
|
||||
set -e
|
||||
cmake -S . -B build -G Ninja \
|
||||
-DBUILD_QT_PART=ON \
|
||||
-DCMAKE_PREFIX_PATH='${QT_ROOT}' \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
$*
|
||||
cmake --build build --parallel
|
||||
"
|
||||
echo ">> Build done. Run on host: tools/run.sh <target> (Qt targets: tools/run_qt.sh <target>)"
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build the lightweight build-container image (toolchain + aqtinstall, no Qt baked in).
|
||||
# Usage: tools/docker/docker_build_image.sh
|
||||
set -euo pipefail
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
IMAGE_TAG="qt-course:builder"
|
||||
echo ">> Building image ${IMAGE_TAG} ..."
|
||||
docker build -t "$IMAGE_TAG" -f "$REPO_ROOT/tools/docker/Dockerfile" "$REPO_ROOT/tools/docker"
|
||||
echo ">> Done. Next: tools/docker/docker_install_qt.sh (downloads Qt 5.14.2 into .qt514/)"
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install the ISOLATED Qt 5.14.2 toolchain into the repo at .qt514/ using the
|
||||
# build container (keeps the host free of aqtinstall deps; Qt files land on the
|
||||
# host filesystem via the mount so the host can build/run against them later).
|
||||
#
|
||||
# Usage: tools/docker/docker_install_qt.sh
|
||||
# Idempotent: re-running refreshes/repairs the install.
|
||||
set -euo pipefail
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
IMAGE_TAG="qt-course:builder"
|
||||
QT_DEST="/workspace/.qt514"
|
||||
QT_VERSION="5.14.2"
|
||||
|
||||
if ! docker image inspect "$IMAGE_TAG" >/dev/null 2>&1; then
|
||||
echo ">> image ${IMAGE_TAG} not found; building it first." >&2
|
||||
"$REPO_ROOT/tools/docker/docker_build_image.sh"
|
||||
fi
|
||||
|
||||
mkdir -p "$REPO_ROOT/.qt514"
|
||||
echo ">> Installing Qt ${QT_VERSION} gcc_64 into $REPO_ROOT/.qt514/ (via container)..."
|
||||
docker run --rm \
|
||||
-v "$REPO_ROOT:/workspace" \
|
||||
"$IMAGE_TAG" \
|
||||
aqt install-qt linux desktop "${QT_VERSION}" gcc_64 -O "${QT_DEST}"
|
||||
|
||||
# Verify on the host (no container needed for this read).
|
||||
QT_ROOT="$REPO_ROOT/.qt514/${QT_VERSION}/gcc_64"
|
||||
echo ">> Verify (host):"
|
||||
"$QT_ROOT/bin/qmake" -query QT_VERSION
|
||||
echo ">> Qt installed at: $QT_ROOT"
|
||||
echo ">> Now build with: tools/docker/docker_build.sh (or host cmake, see README)"
|
||||
Reference in New Issue
Block a user