4d77ba6c91
三条链路: - 电脑 → iPhone:扫 QFTSEND2 码下载,流式落盘 + 增量 SHA-256, 支持 Range 断点续传 - iPhone → 电脑:扫 QFTPAIR2 码后 init/chunk/finish 并行分块上传 - iPhone ↔ iPhone:QFTP2P1 扫码握手,Network.framework 开启 includePeerToPeer(AirDrop 同款 BLE 发现 + AWDL 点对点 Wi-Fi), 两台设备不需要连同一个 Wi-Fi,也不需要路由器 P2P 用 TLS-PSK 握手:32 字节预共享密钥由发送端随机生成并写进二维码, 扫码这个动作本身完成带外密钥交换与双向认证,无需证书体系与配对弹窗。 未扫到码的第三方连上来过不了握手。 核心层刻意不 import UIKit,可直接以 macOS 为目标编译测试, 不需要 Xcode 也不需要模拟器,已接入主自检套件,72 项全部通过: - 端点白名单 11 种拒绝用例(域名、公网、172.32 边界、 非规范八位组、IPv6、带凭据/路径/query) - CoreTests/MockPCServer.py 严格复刻 receiver.rs / sender.rs 的线上语义 (路径、header 名、JSON 字段、Range 行为、chunk 长度校验), 构成 Swift 与 Rust 两端的线格式契约测试,任一端改协议即会失败 - 真实 TLS-PSK 握手下的 P2P 端到端传输,含错误密钥必须被拒 iOS 平台限制(已在 ios/README.md 说明): NEHotspotConfiguration 需要付费账号 entitlement,故不实现 Direct AP 流程,与电脑互传要求同一局域网;AWDL 是苹果私有链路,Windows 无法参与。 上传块固定 4 MiB 而非 Android 的 4/8/16 MiB,因为 iOS 上 worker 数 × 块大小即内存峰值。 未验证部分:本机只有 Command Line Tools,无 Xcode 与 iOS SDK, UI 层(SwiftUI/UIKit/AVFoundation)未经编译;.xcodeproj 已通过 plutil 解析与引用完整性校验(42 个对象无悬空引用), 但未在 Xcode 中实际打开过。
372 lines
13 KiB
Python
372 lines
13 KiB
Python
#!/usr/bin/env python3
|
|
"""生成 ios/QFT.xcodeproj,不依赖 XcodeGen 等外部工具。
|
|
|
|
生成结果已提交到仓库,正常情况下双击 QFT.xcodeproj 即可。
|
|
只有在**增删源文件**之后才需要重跑:
|
|
|
|
python3 ios/tools/generate_xcodeproj.py
|
|
|
|
对象 ID 由文件路径哈希得到,因此同样的文件集合总是产出同样的工程,
|
|
diff 干净,不会每次生成都全量变动。
|
|
"""
|
|
|
|
import hashlib
|
|
import os
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
IOS_ROOT = os.path.dirname(HERE)
|
|
|
|
APP_NAME = "QFT"
|
|
BUNDLE_ID = "com.qft.transfer"
|
|
DEPLOYMENT_TARGET = "17.0"
|
|
MARKETING_VERSION = "0.1.0"
|
|
|
|
SOURCES = [
|
|
"QFT/App/QFTApp.swift",
|
|
"QFT/App/HomeView.swift",
|
|
"QFT/App/ScannerView.swift",
|
|
"QFT/App/TransferModel.swift",
|
|
"QFT/Core/Base64URL.swift",
|
|
"QFT/Core/PairingProtocol.swift",
|
|
"QFT/Core/HostDiscovery.swift",
|
|
"QFT/Core/DownloadClient.swift",
|
|
"QFT/Core/UploadClient.swift",
|
|
"QFT/Core/PeerPairing.swift",
|
|
"QFT/Core/PeerLink.swift",
|
|
]
|
|
RESOURCES = ["QFT/Assets.xcassets"]
|
|
OTHER_FILES = ["QFT/Info.plist"]
|
|
|
|
|
|
def oid(*parts):
|
|
"""由稳定字符串派生 24 位十六进制对象 ID。"""
|
|
digest = hashlib.sha1("::".join(parts).encode("utf-8")).hexdigest()
|
|
return digest[:24].upper()
|
|
|
|
|
|
def file_type(path):
|
|
if path.endswith(".swift"):
|
|
return "sourcecode.swift"
|
|
if path.endswith(".xcassets"):
|
|
return "folder.assetcatalog"
|
|
if path.endswith(".plist"):
|
|
return "text.plist.xml"
|
|
return "text"
|
|
|
|
|
|
def build_tree(paths):
|
|
"""把扁平路径列表折成 {目录: {...}} 的嵌套结构。"""
|
|
tree = {}
|
|
for path in paths:
|
|
node = tree
|
|
segments = path.split("/")
|
|
for segment in segments[:-1]:
|
|
node = node.setdefault(segment, {})
|
|
node[segments[-1]] = None
|
|
return tree
|
|
|
|
|
|
def emit_groups(tree, prefix, lines):
|
|
"""深度优先输出 PBXGroup,返回本层 group 的 ID。"""
|
|
children = []
|
|
for name in sorted(tree.keys()):
|
|
path = "%s/%s" % (prefix, name) if prefix else name
|
|
if tree[name] is None:
|
|
children.append((oid("file", path), name))
|
|
else:
|
|
children.append((emit_groups(tree[name], path, lines), name))
|
|
|
|
group_id = oid("group", prefix or "<root>")
|
|
lines.append("\t\t%s /* %s */ = {" % (group_id, prefix.split("/")[-1] if prefix else APP_NAME))
|
|
lines.append("\t\t\tisa = PBXGroup;")
|
|
lines.append("\t\t\tchildren = (")
|
|
for child_id, child_name in children:
|
|
lines.append("\t\t\t\t%s /* %s */," % (child_id, child_name))
|
|
lines.append("\t\t\t);")
|
|
if prefix:
|
|
lines.append("\t\t\tpath = %s;" % prefix.split("/")[-1])
|
|
lines.append("\t\t\tsourceTree = \"<group>\";")
|
|
lines.append("\t\t};")
|
|
return group_id
|
|
|
|
|
|
def generate():
|
|
all_files = SOURCES + RESOURCES + OTHER_FILES
|
|
|
|
project_id = oid("project")
|
|
target_id = oid("target", APP_NAME)
|
|
product_id = oid("product", APP_NAME)
|
|
products_group_id = oid("group", "<products>")
|
|
sources_phase_id = oid("phase", "sources")
|
|
resources_phase_id = oid("phase", "resources")
|
|
frameworks_phase_id = oid("phase", "frameworks")
|
|
project_config_list = oid("configlist", "project")
|
|
target_config_list = oid("configlist", "target")
|
|
|
|
lines = []
|
|
add = lines.append
|
|
|
|
add("// !$*UTF8*$!")
|
|
add("{")
|
|
add("\tarchiveVersion = 1;")
|
|
add("\tclasses = {")
|
|
add("\t};")
|
|
add("\tobjectVersion = 56;")
|
|
add("\tobjects = {")
|
|
|
|
# ---------------- PBXBuildFile
|
|
add("")
|
|
add("/* Begin PBXBuildFile section */")
|
|
for path in SOURCES + RESOURCES:
|
|
name = path.split("/")[-1]
|
|
add("\t\t%s /* %s in %s */ = {isa = PBXBuildFile; fileRef = %s /* %s */; };"
|
|
% (oid("buildfile", path), name,
|
|
"Resources" if path in RESOURCES else "Sources",
|
|
oid("file", path), name))
|
|
add("/* End PBXBuildFile section */")
|
|
|
|
# ---------------- PBXFileReference
|
|
add("")
|
|
add("/* Begin PBXFileReference section */")
|
|
add("\t\t%s /* %s.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; "
|
|
"includeInIndex = 0; path = %s.app; sourceTree = BUILT_PRODUCTS_DIR; };"
|
|
% (product_id, APP_NAME, APP_NAME))
|
|
for path in all_files:
|
|
name = path.split("/")[-1]
|
|
add("\t\t%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = %s; path = %s; "
|
|
"sourceTree = \"<group>\"; };" % (oid("file", path), name, file_type(path), name))
|
|
add("/* End PBXFileReference section */")
|
|
|
|
# ---------------- PBXFrameworksBuildPhase
|
|
add("")
|
|
add("/* Begin PBXFrameworksBuildPhase section */")
|
|
add("\t\t%s /* Frameworks */ = {" % frameworks_phase_id)
|
|
add("\t\t\tisa = PBXFrameworksBuildPhase;")
|
|
add("\t\t\tbuildActionMask = 2147483647;")
|
|
add("\t\t\tfiles = (")
|
|
add("\t\t\t);")
|
|
add("\t\t\trunOnlyForDeploymentPostprocessing = 0;")
|
|
add("\t\t};")
|
|
add("/* End PBXFrameworksBuildPhase section */")
|
|
|
|
# ---------------- PBXGroup
|
|
add("")
|
|
add("/* Begin PBXGroup section */")
|
|
group_lines = []
|
|
app_group_id = emit_groups(build_tree(all_files)[APP_NAME], APP_NAME, group_lines)
|
|
lines.extend(group_lines)
|
|
|
|
root_group_id = oid("group", "<root-main>")
|
|
add("\t\t%s = {" % root_group_id)
|
|
add("\t\t\tisa = PBXGroup;")
|
|
add("\t\t\tchildren = (")
|
|
add("\t\t\t\t%s /* %s */," % (app_group_id, APP_NAME))
|
|
add("\t\t\t\t%s /* Products */," % products_group_id)
|
|
add("\t\t\t);")
|
|
add("\t\t\tsourceTree = \"<group>\";")
|
|
add("\t\t};")
|
|
|
|
add("\t\t%s /* Products */ = {" % products_group_id)
|
|
add("\t\t\tisa = PBXGroup;")
|
|
add("\t\t\tchildren = (")
|
|
add("\t\t\t\t%s /* %s.app */," % (product_id, APP_NAME))
|
|
add("\t\t\t);")
|
|
add("\t\t\tname = Products;")
|
|
add("\t\t\tsourceTree = \"<group>\";")
|
|
add("\t\t};")
|
|
add("/* End PBXGroup section */")
|
|
|
|
# ---------------- PBXNativeTarget
|
|
add("")
|
|
add("/* Begin PBXNativeTarget section */")
|
|
add("\t\t%s /* %s */ = {" % (target_id, APP_NAME))
|
|
add("\t\t\tisa = PBXNativeTarget;")
|
|
add("\t\t\tbuildConfigurationList = %s;" % target_config_list)
|
|
add("\t\t\tbuildPhases = (")
|
|
add("\t\t\t\t%s /* Sources */," % sources_phase_id)
|
|
add("\t\t\t\t%s /* Frameworks */," % frameworks_phase_id)
|
|
add("\t\t\t\t%s /* Resources */," % resources_phase_id)
|
|
add("\t\t\t);")
|
|
add("\t\t\tbuildRules = (")
|
|
add("\t\t\t);")
|
|
add("\t\t\tdependencies = (")
|
|
add("\t\t\t);")
|
|
add("\t\t\tname = %s;" % APP_NAME)
|
|
add("\t\t\tproductName = %s;" % APP_NAME)
|
|
add("\t\t\tproductReference = %s /* %s.app */;" % (product_id, APP_NAME))
|
|
add("\t\t\tproductType = \"com.apple.product-type.application\";")
|
|
add("\t\t};")
|
|
add("/* End PBXNativeTarget section */")
|
|
|
|
# ---------------- PBXProject
|
|
add("")
|
|
add("/* Begin PBXProject section */")
|
|
add("\t\t%s /* Project object */ = {" % project_id)
|
|
add("\t\t\tisa = PBXProject;")
|
|
add("\t\t\tattributes = {")
|
|
add("\t\t\t\tBuildIndependentTargetsInParallel = 1;")
|
|
add("\t\t\t\tLastSwiftUpdateCheck = 1600;")
|
|
add("\t\t\t\tLastUpgradeCheck = 1600;")
|
|
add("\t\t\t\tTargetAttributes = {")
|
|
add("\t\t\t\t\t%s = {" % target_id)
|
|
add("\t\t\t\t\t\tCreatedOnToolsVersion = 16.0;")
|
|
add("\t\t\t\t\t};")
|
|
add("\t\t\t\t};")
|
|
add("\t\t\t};")
|
|
add("\t\t\tbuildConfigurationList = %s;" % project_config_list)
|
|
add("\t\t\tcompatibilityVersion = \"Xcode 14.0\";")
|
|
add("\t\t\tdevelopmentRegion = en;")
|
|
add("\t\t\thasScannedForEncodings = 0;")
|
|
add("\t\t\tknownRegions = (")
|
|
add("\t\t\t\ten,")
|
|
add("\t\t\t\tBase,")
|
|
add("\t\t\t\t\"zh-Hans\",")
|
|
add("\t\t\t);")
|
|
add("\t\t\tmainGroup = %s;" % root_group_id)
|
|
add("\t\t\tproductRefGroup = %s /* Products */;" % products_group_id)
|
|
add("\t\t\tprojectDirPath = \"\";")
|
|
add("\t\t\tprojectRoot = \"\";")
|
|
add("\t\t\ttargets = (")
|
|
add("\t\t\t\t%s /* %s */," % (target_id, APP_NAME))
|
|
add("\t\t\t);")
|
|
add("\t\t};")
|
|
add("/* End PBXProject section */")
|
|
|
|
# ---------------- PBXResourcesBuildPhase
|
|
add("")
|
|
add("/* Begin PBXResourcesBuildPhase section */")
|
|
add("\t\t%s /* Resources */ = {" % resources_phase_id)
|
|
add("\t\t\tisa = PBXResourcesBuildPhase;")
|
|
add("\t\t\tbuildActionMask = 2147483647;")
|
|
add("\t\t\tfiles = (")
|
|
for path in RESOURCES:
|
|
add("\t\t\t\t%s /* %s in Resources */," % (oid("buildfile", path), path.split("/")[-1]))
|
|
add("\t\t\t);")
|
|
add("\t\t\trunOnlyForDeploymentPostprocessing = 0;")
|
|
add("\t\t};")
|
|
add("/* End PBXResourcesBuildPhase section */")
|
|
|
|
# ---------------- PBXSourcesBuildPhase
|
|
add("")
|
|
add("/* Begin PBXSourcesBuildPhase section */")
|
|
add("\t\t%s /* Sources */ = {" % sources_phase_id)
|
|
add("\t\t\tisa = PBXSourcesBuildPhase;")
|
|
add("\t\t\tbuildActionMask = 2147483647;")
|
|
add("\t\t\tfiles = (")
|
|
for path in SOURCES:
|
|
add("\t\t\t\t%s /* %s in Sources */," % (oid("buildfile", path), path.split("/")[-1]))
|
|
add("\t\t\t);")
|
|
add("\t\t\trunOnlyForDeploymentPostprocessing = 0;")
|
|
add("\t\t};")
|
|
add("/* End PBXSourcesBuildPhase section */")
|
|
|
|
# ---------------- XCBuildConfiguration
|
|
shared_project = [
|
|
"ALWAYS_SEARCH_USER_PATHS = NO",
|
|
"CLANG_ANALYZER_NONNULL = YES",
|
|
"CLANG_ENABLE_MODULES = YES",
|
|
"CLANG_ENABLE_OBJC_ARC = YES",
|
|
"CLANG_WARN_DOCUMENTATION_COMMENTS = YES",
|
|
"CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE",
|
|
"COPY_PHASE_STRIP = NO",
|
|
"ENABLE_STRICT_OBJC_MSGSEND = YES",
|
|
"GCC_NO_COMMON_BLOCKS = YES",
|
|
"IPHONEOS_DEPLOYMENT_TARGET = %s" % DEPLOYMENT_TARGET,
|
|
"MTL_FAST_MATH = YES",
|
|
"SDKROOT = iphoneos",
|
|
"SWIFT_VERSION = 5.0",
|
|
]
|
|
shared_target = [
|
|
"ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon",
|
|
"ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor",
|
|
"CODE_SIGN_STYLE = Automatic",
|
|
"CURRENT_PROJECT_VERSION = 1",
|
|
"ENABLE_PREVIEWS = YES",
|
|
"GENERATE_INFOPLIST_FILE = NO",
|
|
"INFOPLIST_FILE = QFT/Info.plist",
|
|
"LD_RUNPATH_SEARCH_PATHS = \"$(inherited) @executable_path/Frameworks\"",
|
|
"MARKETING_VERSION = %s" % MARKETING_VERSION,
|
|
"PRODUCT_BUNDLE_IDENTIFIER = %s" % BUNDLE_ID,
|
|
"PRODUCT_NAME = \"$(TARGET_NAME)\"",
|
|
"SWIFT_EMIT_LOC_STRINGS = NO",
|
|
"TARGETED_DEVICE_FAMILY = \"1,2\"",
|
|
]
|
|
variants = {
|
|
"Debug": {
|
|
"project": ["DEBUG_INFORMATION_FORMAT = dwarf",
|
|
"ENABLE_TESTABILITY = YES",
|
|
"GCC_OPTIMIZATION_LEVEL = 0",
|
|
"GCC_PREPROCESSOR_DEFINITIONS = \"DEBUG=1 $(inherited)\"",
|
|
"MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE",
|
|
"ONLY_ACTIVE_ARCH = YES",
|
|
"SWIFT_ACTIVE_COMPILATION_CONDITIONS = \"DEBUG $(inherited)\"",
|
|
"SWIFT_OPTIMIZATION_LEVEL = \"-Onone\""],
|
|
"target": [],
|
|
},
|
|
"Release": {
|
|
"project": ["DEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\"",
|
|
"ENABLE_NS_ASSERTIONS = NO",
|
|
"MTL_ENABLE_DEBUG_INFO = NO",
|
|
"SWIFT_COMPILATION_MODE = wholemodule",
|
|
"VALIDATE_PRODUCT = YES"],
|
|
"target": [],
|
|
},
|
|
}
|
|
|
|
add("")
|
|
add("/* Begin XCBuildConfiguration section */")
|
|
for name, extra in variants.items():
|
|
for scope, base in (("project", shared_project), ("target", shared_target)):
|
|
config_id = oid("config", scope, name)
|
|
add("\t\t%s /* %s */ = {" % (config_id, name))
|
|
add("\t\t\tisa = XCBuildConfiguration;")
|
|
add("\t\t\tbuildSettings = {")
|
|
for setting in sorted(base + extra[scope]):
|
|
add("\t\t\t\t%s;" % setting)
|
|
add("\t\t\t};")
|
|
add("\t\t\tname = %s;" % name)
|
|
add("\t\t};")
|
|
add("/* End XCBuildConfiguration section */")
|
|
|
|
# ---------------- XCConfigurationList
|
|
add("")
|
|
add("/* Begin XCConfigurationList section */")
|
|
for scope, list_id in (("project", project_config_list), ("target", target_config_list)):
|
|
add("\t\t%s = {" % list_id)
|
|
add("\t\t\tisa = XCConfigurationList;")
|
|
add("\t\t\tbuildConfigurations = (")
|
|
for name in variants:
|
|
add("\t\t\t\t%s /* %s */," % (oid("config", scope, name), name))
|
|
add("\t\t\t);")
|
|
add("\t\t\tdefaultConfigurationIsVisible = 0;")
|
|
add("\t\t\tdefaultConfigurationName = Release;")
|
|
add("\t\t};")
|
|
add("/* End XCConfigurationList section */")
|
|
|
|
add("\t};")
|
|
add("\trootObject = %s /* Project object */;" % project_id)
|
|
add("}")
|
|
return "\n".join(lines) + "\n"
|
|
|
|
|
|
def main():
|
|
project_dir = os.path.join(IOS_ROOT, "%s.xcodeproj" % APP_NAME)
|
|
os.makedirs(project_dir, exist_ok=True)
|
|
target = os.path.join(project_dir, "project.pbxproj")
|
|
with open(target, "w", encoding="utf-8") as fh:
|
|
fh.write(generate())
|
|
print("已生成 %s" % target)
|
|
|
|
missing = [p for p in SOURCES + RESOURCES + OTHER_FILES
|
|
if not os.path.exists(os.path.join(IOS_ROOT, p))]
|
|
if missing:
|
|
print("警告:以下文件在工程里被引用但不存在:")
|
|
for path in missing:
|
|
print(" " + path)
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|