@harmonyos-arkts/d2h 0.1.34 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/agents/android-to-hmos-00-orchestrator.md +1 -1
- package/agents/d2h.md +5 -4
- package/assets/agc-apiclient.json +10 -0
- package/dist/bin/install-opencode.js +6 -1
- package/dist/src/metrics-plugin.js +36 -1
- package/package.json +2 -1
- package/schemas/code-stats.schema.json +2 -2
- package/skills/d2h-code-audit/SKILL.md +17 -6
- package/skills/d2h-code-audit/references/code-stats-schema.md +64 -2
- package/skills/d2h-code-audit/scripts/code_stats.py +1 -1
- package/skills/d2h-code-audit/scripts/increment_delta.py +299 -0
- package/skills/d2h-dashboard/app/assets/{Analysis-Dj-4QEJi.js → Analysis-S3iFh2nP.js} +1 -1
- package/skills/d2h-dashboard/app/assets/CodeAudit-BI5iNy2f.css +1 -0
- package/skills/d2h-dashboard/app/assets/CodeAudit-BeZMoO_s.js +1 -0
- package/skills/d2h-dashboard/app/assets/{FeaturesList-C5yGUbRo.js → FeaturesList-CdKAoNw5.js} +1 -1
- package/skills/d2h-dashboard/app/assets/{Overview-CNkA3J9F.js → Overview-C43KVHdP.js} +1 -1
- package/skills/d2h-dashboard/app/assets/Overview-CzysQJHh.css +1 -0
- package/skills/d2h-dashboard/app/assets/{Project-BC9Tz1WY.js → Project-D5loWYjZ.js} +1 -1
- package/skills/d2h-dashboard/app/assets/{SpecDetail-DguVmqAE.js → SpecDetail-XCDyawZ3.js} +1 -1
- package/skills/d2h-dashboard/app/assets/{SpecItemDetail-7s7SaF3O.js → SpecItemDetail-BDl_Qqfx.js} +2 -2
- package/skills/d2h-dashboard/app/assets/datetime-DBOJn2GA.js +1 -0
- package/skills/d2h-dashboard/app/assets/{index-B3nfIPBm.js → index-C1bO3C02.js} +2 -2
- package/skills/d2h-dashboard/app/assets/{navigation-d1Uf6TR4.js → navigation-BGPexEv8.js} +1 -1
- package/skills/d2h-dashboard/app/index.html +1 -1
- package/skills/d2h-spec-generate/SKILL.md +17 -11
- package/skills/language/h5/d2h-h5-analyse/SKILL.md +34 -0
- package/skills/language/h5/d2h-h5-analyse/references/scenarios.md +36 -0
- package/skills/language/h5/d2h-h5-coding/SKILL.md +33 -0
- package/skills/language/h5/d2h-h5-coding/references/bridge-contracts.md +44 -0
- package/skills/language/h5/d2h-h5-coding/references/examples.md +28 -0
- package/skills/language/h5/d2h-h5-coding/references/scenarios.md +40 -0
- package/skills/language/h5/d2h-h5-coding/references/webview-implementation.md +144 -0
- package/skills/language/h5/d2h-webview-analyse/SKILL.md +309 -0
- package/skills/language/h5/d2h-webview-analyse/scripts/analyse_android_webview.py +3625 -0
- package/skills/language/h5/d2h-webview-jsbridge/SKILL.md +140 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/adaptation.md +235 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/containers-and-triage.md +30 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/detection-rules.md +69 -0
- package/skills/language/h5/d2h-webview-jsbridge/references/report-system.md +69 -0
- package/skills/language/h5/d2h-webview-jsbridge/scripts/scan_web_jsbridge.py +2080 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/dsbridge-app/app/build.gradle +3 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/dsbridge-app/app/src/main/assets/dsbridge.js +6 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/dsbridge-app/app/src/main/java/demo/DsActivity.java +19 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/empty-app/app/src/main/kotlin/demo/Screen.kt +5 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/build.gradle +3 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/src/main/assets/www/WebViewJavascriptBridge.js +6 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/src/main/assets/www/index.html +6 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/java-app/app/src/main/java/demo/WebActivity.java +79 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/assets/WebViewJavascriptBridge.js +4 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/assets/page.html +2 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/kotlin/demo/Bridge.kt +23 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/kotlin-app/app/src/main/kotlin/demo/WVJBWebView.kt +27 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/xml-app/app/src/main/java/demo/MainActivity.java +8 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/fixtures/xml-app/app/src/main/res/layout/main.xml +9 -0
- package/skills/language/h5/d2h-webview-jsbridge/tests/run_tests.py +237 -0
- package/skills/preparing-migration-workspace/SKILL.md +0 -1
- package/skills/d2h-dashboard/app/assets/CodeAudit-Ctt3XEec.css +0 -1
- package/skills/d2h-dashboard/app/assets/CodeAudit-TcIcLwQL.js +0 -1
- package/skills/d2h-dashboard/app/assets/Overview-Cmz8yjX-.css +0 -1
- package/skills/d2h-dashboard/app/assets/datetime-CHrzCsjX.js +0 -1
package/agents/d2h.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: d2h
|
|
3
3
|
description: Android 应用到 HarmonyOS 的 AI 驱动迁移主 Agent;按迁移场景加载专项 Skill,完成页面规划、逐页开发、必要验证和最终交付。
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.36
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Android to HarmonyOS Migration Agent
|
|
@@ -35,7 +35,7 @@ version: 0.1.34
|
|
|
35
35
|
| 开始或恢复迁移,定位工程、准备工具链、读取状态、执行 Preflight、检查设备 | `preparing-migration-workspace` |
|
|
36
36
|
| 迁移实时看板(progress.json 就绪后自动启动;阶段进度、功能清单、Spec 执行、耗时/token 总览) | `d2h-dashboard` |
|
|
37
37
|
| 从源码生成可审计功能清单、MVP/core/full 阶段、逐功能技术栈/三方 SDK/SO/权限与跨仓实现状态 | `d2h-app-solution` |
|
|
38
|
-
|
|
|
38
|
+
| 代码静态分析(主流程两次触发:开始时 Android 基线,代码转换完成后双端终检):超大文件(默认 2000 行)、模块数、三方依赖、SO 依赖统计与对比 | `d2h-code-audit` |
|
|
39
39
|
| 从 Android 源码生成或刷新 Facts、UTG、点击路径和 `.migration/utg/page.json` | `d2h-utg-static-generate` |
|
|
40
40
|
| 需要 AI 修复源码派生 UTG,或在 Android 设备上按已有计划采集运行时证据 | `d2h-utg-ai-generate` |
|
|
41
41
|
| 根据 Facts、源码和 UTG 生成页面计划、完整 `spec.md` 及初始账本 | `d2h-spec-generate` |
|
|
@@ -61,6 +61,7 @@ version: 0.1.34
|
|
|
61
61
|
1. 加载 `managing-d2h-toolchain` skill 完成基础工具链预检和安装,仅需要执行一次
|
|
62
62
|
2. 加载 `preparing-migration-workspace`,完成工具链、Android/HarmonyOS 工程、迁移工作区、配置、基线和设备检查。迁移工作区使用 Android 工程父目录下的 `<工程名>-migration/.migration/`,不得写入 Android 工程内部。
|
|
63
63
|
3. `.migration/progress.json` 就绪(`progress init` 首次创建或恢复时已存在)后,立即加载 `d2h-dashboard` 自动启动实时看板并用默认浏览器打开网页;看板启动或打开失败只记录,不阻塞迁移。
|
|
64
|
+
4. 工作区就绪后加载 `d2h-code-audit`,对 Android 工程执行基线扫描(超大文件、模块数、三方依赖、SO 统计),产物写入 `.migration/code-audit/baseline-android/code-stats.json`;HarmonyOS 工程此时已存在(恢复迁移或复用已有工程)时,追加单侧基线 `.migration/code-audit/baseline-harmony/code-stats.json`。恢复时已有基线且对应源码基线未变则沿用,不重复扫描。
|
|
64
65
|
|
|
65
66
|
### 二、功能清单生成
|
|
66
67
|
|
|
@@ -103,7 +104,7 @@ c. 主 Agent 复核本次构建与必要验证结果,不另设逐页测试流
|
|
|
103
104
|
d. 主 Agent 复核作用域提交和工作区,核对 `batch_report.json` 中记录的真实实现文件、来源、本次构建与测试证据、差异及阻塞,原位更新并保留历史。
|
|
104
105
|
e. 当前任务闭环后,重新核对前置并评估上下文与宿主续会话能力,适合时复用同一 worker 继续组内下一项,否则明确调整分组并重新派发剩余任务;本组完成后再按计划派发下一组。受阻时继续修复当前任务或记录外部阻塞,不自动跳过或扩组。里程碑与波次组织交付顺序,不拆分页面闭环或改变验收要求。
|
|
105
106
|
|
|
106
|
-
3.
|
|
107
|
+
3. 本次确认范围的开发任务全部完成、进入完成条件核对前,第二次加载 `d2h-code-audit` 对 Android 与 HarmonyOS 工程执行双端同扫终检(comparison 必须双端同次生成,阶段一单侧基线无 comparison):超大文件(默认 2000 行)、模块数、三方依赖与 SO 依赖统计及对比,产物写入 `.migration/code-audit/code-stats.json`,与阶段一基线分开保留;增量轮重扫前先将上一轮终检产物原样归档到 `.migration/code-audit/history/code-stats-<generated_at>.json`,终检后运行差量脚本生成 `.migration/code-audit/increment-delta.json` 记录本次增量(逐侧行数、依赖与超大文件差量;增量轮以最近归档终检为 previous,首轮以阶段一基线为 previous,已有鸿蒙工程时 harmony 侧有基线,缺 previous 的侧在 notes 如实说明)。HarmonyOS 侧超大文件如实记录,不静默省略,也不阻塞本次范围交付。
|
|
107
108
|
|
|
108
109
|
若当前环境不支持独立 page-worker,必须明确报告该开发模式无法执行,不能静默改成主 Agent 批量开发。
|
|
109
110
|
|
|
@@ -151,7 +152,7 @@ hdc 不在 PATH 或仍悬挂时改用 `cmd /c "… > log 2>&1"` 文件重定向
|
|
|
151
152
|
- 所有 Spec 功能项都有真实、可达的 HarmonyOS 实现。
|
|
152
153
|
- HarmonyOS 工程构建、安装、启动成功,开发阶段必要验证通过;仅在用户明确要求专项测试时核对其实际结果。
|
|
153
154
|
- `batch_report.json` 已记录最终开发复核、必要验证结果、未验证项及实际证据路径,队列、页面明细和汇总一致。
|
|
154
|
-
- 已按 `d2h-code-audit`
|
|
155
|
+
- 已按 `d2h-code-audit` 完成双端静态分析终检,`.migration/code-audit/code-stats.json` 已生成;HarmonyOS 侧超大文件已如实记录并标注。
|
|
155
156
|
- 所有页面、可见控件、状态、导航、Dialog、业务功能、数据效果和错误路径均真实实现。
|
|
156
157
|
- Facts 或 UTG 遗漏、但经源码或运行时发现的行为也已实现并验证。
|
|
157
158
|
- 无法等价的差异已经明确呈现,没有被静默标记为完成。
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "project_client_id",
|
|
3
|
+
"developer_id": "2850086000535724929",
|
|
4
|
+
"project_id": "101653523864996148",
|
|
5
|
+
"client_id": "2057353456825401344",
|
|
6
|
+
"client_secret": "CDDE913EB263B248513BA2B6668B5AEBD4FC58DF2462C6B74F558DD3330412EA",
|
|
7
|
+
"configuration_version": "3.0",
|
|
8
|
+
"region": "CN",
|
|
9
|
+
"bucket_name": "d2h-oekjj"
|
|
10
|
+
}
|
|
@@ -11,7 +11,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import os from 'node:os';
|
|
13
13
|
import { inspectInstallation, installOpenCode } from '../src/install-opencode.js';
|
|
14
|
-
import { findMetricsPluginCacheDirs, metricsPluginCacheRoots } from '../src/metrics-plugin.js';
|
|
14
|
+
import { findMetricsPluginCacheDirs, metricsPluginCacheRoots, ensureAgcCredentials } from '../src/metrics-plugin.js';
|
|
15
15
|
import { inspectToolchain, installToolchain, loadToolchain } from '../src/toolchain.js';
|
|
16
16
|
import fs from 'node:fs';
|
|
17
17
|
import { preparePoc } from '../src/poc.js';
|
|
@@ -51,6 +51,8 @@ Usage: d2h [options]
|
|
|
51
51
|
--poc Enable local rule/event collection in an isolated config
|
|
52
52
|
Combine --remote for Full POC collection and cloud upload
|
|
53
53
|
--remote Use opencode-metrics-plugin instead of the default lite plugin
|
|
54
|
+
(also provisions the bundled AGC credential; other commands
|
|
55
|
+
never touch it)
|
|
54
56
|
--dry-run Print operations without writing files
|
|
55
57
|
--skip-tools Install definitions only (local development)
|
|
56
58
|
-h, --help Show this help
|
|
@@ -176,6 +178,9 @@ try {
|
|
|
176
178
|
if (options.agent === 'vscode' && options.configDir)
|
|
177
179
|
throw new Error('--config-dir is not used for VS Code; use --extension-dir');
|
|
178
180
|
options.configDir ??= isSkillHost(options.agent) ? skillHostConfigRoot(options.agent) : process.env[options.agent === 'deveco' ? 'DEVECO_CONFIG_DIR' : 'OPENCODE_CONFIG_DIR'] || path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), options.agent);
|
|
181
|
+
if (remote && !checkOnly && !options.dryRun) {
|
|
182
|
+
ensureAgcCredentials({ sourceDir: packageRoot, log: console.log });
|
|
183
|
+
}
|
|
179
184
|
if (checkOnly) {
|
|
180
185
|
const installation = options.agent === 'vscode' ? inspectVSCodeInstallation(extensionDir) : isSkillHost(options.agent) ? inspectSkillHostInstallation(options.agent, options.configDir) : inspectInstallation(options.configDir);
|
|
181
186
|
console.log(`definitions ${installation.status}: ${installation.summary}`);
|
|
@@ -10,8 +10,13 @@ export function updateMetricsPlugin(config, remote = false, pocRoot) {
|
|
|
10
10
|
if (!Array.isArray(plugins))
|
|
11
11
|
throw new Error('opencode plugin list must be an array');
|
|
12
12
|
const selected = remote ? remoteMetricsPlugin : liteMetricsPlugin;
|
|
13
|
+
// Plugin entries may appear as a bare string, a [name, options] tuple, or a
|
|
14
|
+
// { package } object (e.g. left by V2-shaped configs); recognize all three.
|
|
13
15
|
const isMetrics = (entry) => {
|
|
14
|
-
const name = Array.isArray(entry) ? entry[0]
|
|
16
|
+
const name = Array.isArray(entry) ? entry[0]
|
|
17
|
+
: typeof entry === 'object' && entry !== null && typeof entry.package === 'string'
|
|
18
|
+
? entry.package
|
|
19
|
+
: entry;
|
|
15
20
|
return typeof name === 'string' && [liteMetricsPlugin, remoteMetricsPlugin].some(base => name === base || name.startsWith(`${base}@`));
|
|
16
21
|
};
|
|
17
22
|
const existing = plugins.findIndex(isMetrics);
|
|
@@ -23,6 +28,36 @@ export function updateMetricsPlugin(config, remote = false, pocRoot) {
|
|
|
23
28
|
filtered[filtered.findIndex(isMetrics)] = selectedEntry;
|
|
24
29
|
config.plugin = filtered;
|
|
25
30
|
}
|
|
31
|
+
export const agcCredentialFileName = 'agc-apiclient.json';
|
|
32
|
+
/** Full-plugin credential paths under the user config convention (~/.config/opencode-metrics). */
|
|
33
|
+
export function agcCredentialPaths(home = os.homedir()) {
|
|
34
|
+
const dir = path.join(home, '.config', 'opencode-metrics');
|
|
35
|
+
return { dir, target: path.join(dir, agcCredentialFileName) };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Provision the full plugin's AGC credential without a separate manual step:
|
|
39
|
+
* copy the bundled assets/agc-apiclient.json to the user config convention
|
|
40
|
+
* path. Only the --remote command path may call this; other commands never
|
|
41
|
+
* touch the credential. An existing credential is never overwritten.
|
|
42
|
+
*/
|
|
43
|
+
export function ensureAgcCredentials({ sourceDir, home, dryRun = false, log = () => { } }) {
|
|
44
|
+
const { dir, target } = agcCredentialPaths(home);
|
|
45
|
+
if (fs.existsSync(target))
|
|
46
|
+
return { status: 'present', target };
|
|
47
|
+
const source = path.join(sourceDir, 'assets', agcCredentialFileName);
|
|
48
|
+
if (!fs.existsSync(source)) {
|
|
49
|
+
log(`warning: AGC credential missing at ${target} and not bundled at ${source}; full plugin upload stays disabled`);
|
|
50
|
+
return { status: 'missing', target };
|
|
51
|
+
}
|
|
52
|
+
if (dryRun) {
|
|
53
|
+
log(`would copy AGC credential ${source} -> ${target}`);
|
|
54
|
+
return { status: 'provisioned', target, source };
|
|
55
|
+
}
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
fs.copyFileSync(source, target);
|
|
58
|
+
log(`AGC credential provisioned: ${target}`);
|
|
59
|
+
return { status: 'provisioned', target, source };
|
|
60
|
+
}
|
|
26
61
|
// OpenCode resolves npm plugins with Bun into XDG-style cache directories on every
|
|
27
62
|
// platform (no ~/Library/Caches on macOS, no %LocalAppData% on Windows).
|
|
28
63
|
export function metricsPluginCacheRoots(agent, home = os.homedir()) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmonyos-arkts/d2h",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"description": "Install Android-to-HarmonyOS migration agents and skills into AI coding tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"d2h": "dist/bin/install-opencode.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
+
"assets/",
|
|
10
11
|
"dist/bin/",
|
|
11
12
|
"dist/src/",
|
|
12
13
|
"skills/",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://chuanqi.dev/schemas/code-stats.schema.json",
|
|
4
4
|
"title": "Dual-Platform Code Stats Report",
|
|
5
|
-
"description": "d2h-code-audit 产出的双端(Android/HarmonyOS
|
|
5
|
+
"description": "d2h-code-audit 产出的双端(Android/HarmonyOS)代码静态分析事实,纯脚本确定性生成;语言已知枚举为 kotlin|java|arkts|typescript|javascript|dart|vue|cpp|xml,未映射文本扩展落入 other。",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"required": [
|
|
8
8
|
"schema_version",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"properties": {
|
|
19
19
|
"schema_version": { "const": "1.0" },
|
|
20
|
-
"title": { "const": "
|
|
20
|
+
"title": { "const": "双端代码静态分析" },
|
|
21
21
|
"language": { "const": "zh-CN" },
|
|
22
22
|
"generated_by": { "const": "d2h-code-audit/scripts/code_stats.py" },
|
|
23
23
|
"generated_at": { "type": "string", "minLength": 1 },
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: d2h-code-audit
|
|
3
|
-
description: 双端(Android + HarmonyOS
|
|
3
|
+
description: 双端(Android + HarmonyOS)代码静态分析:超大文件检测(默认 2000 行)、模块数、三方依赖(gradle/ohpm)、SO/JAR/AAR 原生库统计与双端对比。当用户要求"统计代码行""检查超大文件""大文件检测""盘点模块/SDK/SO 依赖""对比两端代码规模""代码静态分析""代码健康检查"时触发;也是 d2h 迁移主流程的开始基线(Android 单侧;已有鸿蒙工程时含 HarmonyOS 单侧)与代码转换完成后的双端终检环节,并为首轮与增量轮派生 increment-delta.json 差量。只产出确定性 code-stats.json 与 increment-delta.json,不修改代码、不做架构决策。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# 双端代码静态分析
|
|
7
7
|
|
|
8
8
|
从确定性脚本事实出发统计 Android 与 HarmonyOS 工程的代码规模、超大文件、模块与依赖。本 Skill 不评估架构优劣、不修复超大文件、不替代构建或测试。
|
|
9
9
|
|
|
10
10
|
## 输入与默认值
|
|
11
11
|
|
|
12
12
|
- Android 工程根目录(可选)与 HarmonyOS 工程根目录(可选),至少其一;独立调用时由用户提供。
|
|
13
|
-
- 由 `d2h`
|
|
13
|
+
- 由 `d2h` 完整迁移流程调用时产物分三类:基线(阶段一工作区就绪后;Android 始终扫描,输出 `.migration/code-audit/baseline-android/`;HarmonyOS 工程已存在时追加单侧基线,输出 `.migration/code-audit/baseline-harmony/`;单侧基线无 comparison)、双端终检(代码转换完成后同扫,输出 `.migration/code-audit/`,同次生成 comparison;增量轮重扫前先将上一轮终检产物原样归档到 `.migration/code-audit/history/code-stats-<generated_at>.json`)与增量差量(终检后运行 `increment_delta.py` 输出 `.migration/code-audit/increment-delta.json`;增量轮以最近归档终检为 previous,首轮以阶段一基线为 previous)。Android 取当前迁移工程,HarmonyOS 取 `.migration/config.json` 的 `harmonyProject`。恢复时已有基线且对应源码基线未变则沿用,不重复扫描。
|
|
14
14
|
- 超大文件阈值默认 2000 行(`--threshold` 可调),未映射扩展的白名单与识别规则见 [metrics.md](references/metrics.md)。
|
|
15
15
|
|
|
16
16
|
## 核心约束
|
|
@@ -50,14 +50,25 @@ python3 <skill-dir>/scripts/validate_code_stats.py \
|
|
|
50
50
|
|
|
51
51
|
校验器会复核超大文件的实际物理行数、依赖声明位置存在性与全部计数一致性;error 必须修复(重新扫描,不是手改 JSON)。
|
|
52
52
|
|
|
53
|
-
### 3.
|
|
53
|
+
### 3. 生成增量差量(迁移流程终检后)
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
```bash
|
|
56
|
+
python3 <skill-dir>/scripts/increment_delta.py \
|
|
57
|
+
--previous /abs/.migration/code-audit/history/code-stats-<generated_at>.json \
|
|
58
|
+
--current /abs/.migration/code-audit/code-stats.json \
|
|
59
|
+
--output /abs/.migration/code-audit
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`--previous` 可传 1~2 份(按 repositories id 识别各侧来源;增量轮传最近归档终检一份,首轮传阶段一基线)。产物 `increment-delta.json` 是两份快照的确定性差量:逐侧 code/by_language 差量、模块与依赖/原生库 added/removed、依赖 version_changed、超大文件 added/removed/persisted,以及双端同源时的 comparison_delta;口径漂移与缺失 previous 在 notes 说明。不重扫源码,不回写 code-stats.json。
|
|
63
|
+
|
|
64
|
+
### 4. 返回
|
|
65
|
+
|
|
66
|
+
返回 `code-stats.json` 路径、超大纲要和注意事项(`notes`);迁移流程终检后另返回 `increment-delta.json` 路径与本次增量摘要;不展开修复动作。
|
|
56
67
|
|
|
57
68
|
## 最终质量门槛
|
|
58
69
|
|
|
59
70
|
- 校验器零 error;`--strict` 下零 warning 或每条 warning 已说明。
|
|
60
|
-
- 每个数字都能回溯到 `code-stats.json
|
|
71
|
+
- 每个数字都能回溯到 `code-stats.json`,无凭印象补充的统计;差量产物(如有)的每个数字可回溯到 inputs 中两份快照的 sha256。
|
|
61
72
|
- 鸿蒙侧超大文件全部列出且带模块归属;`module: unknown` 的条目已复核解释。
|
|
62
73
|
- 未识别扩展的大体量文件没有被忽略,`notes` 逐条有说明。
|
|
63
74
|
|
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
8. comparison
|
|
15
15
|
9. notes
|
|
16
16
|
10. 最小示例
|
|
17
|
+
11. 迁移流程产物目录约定
|
|
18
|
+
12. 增量差量产物(increment-delta.json)
|
|
17
19
|
|
|
18
20
|
## 1. 顶层结构
|
|
19
21
|
|
|
20
22
|
```json
|
|
21
23
|
{
|
|
22
24
|
"schema_version": "1.0",
|
|
23
|
-
"title": "
|
|
25
|
+
"title": "双端代码静态分析",
|
|
24
26
|
"language": "zh-CN",
|
|
25
27
|
"generated_by": "d2h-code-audit/scripts/code_stats.py",
|
|
26
28
|
"generated_at": "2026-11-05T10:00:00+08:00",
|
|
@@ -161,7 +163,7 @@
|
|
|
161
163
|
```json
|
|
162
164
|
{
|
|
163
165
|
"schema_version": "1.0",
|
|
164
|
-
"title": "
|
|
166
|
+
"title": "双端代码静态分析",
|
|
165
167
|
"language": "zh-CN",
|
|
166
168
|
"generated_by": "d2h-code-audit/scripts/code_stats.py",
|
|
167
169
|
"generated_at": "2026-11-05T10:00:00+08:00",
|
|
@@ -258,3 +260,63 @@
|
|
|
258
260
|
"notes": []
|
|
259
261
|
}
|
|
260
262
|
```
|
|
263
|
+
|
|
264
|
+
## 11. 迁移流程产物目录约定
|
|
265
|
+
|
|
266
|
+
由 `d2h` 完整迁移流程调用时,迁移工作区的产物靠目录区分:
|
|
267
|
+
|
|
268
|
+
| 产物 | 触发环节 | 扫描范围 | 路径 |
|
|
269
|
+
|---|---|---|---|
|
|
270
|
+
| Android 基线 | 阶段一「启动或恢复」工作区就绪后 | 仅 `--android` 单侧,无 `comparison`,`notes` 含"仅统计 Android 侧"说明 | `.migration/code-audit/baseline-android/code-stats.json` |
|
|
271
|
+
| HarmonyOS 基线 | 阶段一,且 HarmonyOS 工程已存在(恢复迁移或复用已有工程) | 仅 `--harmony` 单侧,无 `comparison` | `.migration/code-audit/baseline-harmony/code-stats.json` |
|
|
272
|
+
| 双端终检 | 代码转换完成、进入完成条件核对前 | `--android --harmony` 双端同扫,同次生成 `comparison` | `.migration/code-audit/code-stats.json` |
|
|
273
|
+
| 归档终检 | 增量轮重扫前,上一轮终检原样移入 | 不重扫,仅归档 | `.migration/code-audit/history/code-stats-<generated_at>.json` |
|
|
274
|
+
| 增量差量 | 每轮终检后 | 不重扫,两份快照的确定性派生(见第 12 节) | `.migration/code-audit/increment-delta.json` |
|
|
275
|
+
|
|
276
|
+
- 基线与归档历史永久保留,不被终检覆盖;当轮终检产物是完成条件引用的唯一版本。
|
|
277
|
+
- 恢复会话时,基线已存在且对应源码基线(git revision)未变则沿用,不重复扫描。
|
|
278
|
+
- `comparison` 只能由双端同次扫描生成(见第 8 节),单侧基线产物中必须缺席。
|
|
279
|
+
|
|
280
|
+
## 12. 增量差量产物(increment-delta.json)
|
|
281
|
+
|
|
282
|
+
`increment_delta.py --previous <旧快照>... --current <新快照> --output <目录>` 的产物,是两份 code-stats.json 的纯函数差量:不重扫源码、不回写任何 code-stats.json。`--previous` 可传 1~2 份,按 `repositories[].id` 识别各侧来源;同侧出现在多份 previous 中时报错。previous 选取约定:增量轮用最近归档终检,首轮用阶段一基线。
|
|
283
|
+
|
|
284
|
+
```json
|
|
285
|
+
{
|
|
286
|
+
"schema_version": "1.0",
|
|
287
|
+
"title": "增量开发差量",
|
|
288
|
+
"generated_by": "d2h-code-audit/scripts/increment_delta.py",
|
|
289
|
+
"generated_at": "...",
|
|
290
|
+
"inputs": {
|
|
291
|
+
"current": { "path": "...", "sha256": "...", "generated_at": "...", "repositories": [ { "id": "harmony", "revision": "1a2b3c4" } ] },
|
|
292
|
+
"previous_by_side": {
|
|
293
|
+
"android": { "path": "...", "sha256": "...", "generated_at": "...", "source_kind": "baseline-android", "revision": "..." },
|
|
294
|
+
"harmony": { "path": "...", "sha256": "...", "generated_at": "...", "source_kind": "history-final", "revision": "..." }
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
"sides": {
|
|
298
|
+
"harmony": {
|
|
299
|
+
"code": { "total_files_delta": 3, "total_lines_delta": 4200, "by_language_delta": [ { "language": "arkts", "files_delta": 3, "lines_delta": 4200 } ] },
|
|
300
|
+
"modules": { "added": [ { "name": "feature:profile", "path": "feature/profile", "kind": "library" } ], "removed": [] },
|
|
301
|
+
"third_party_dependencies": { "added": [ { "name": "@ohos/axios", "version": "^2.2.0" } ], "removed": [], "version_changed": [ { "name": "libx", "from": "1.0.0", "to": "1.2.0" } ] },
|
|
302
|
+
"native_libraries": { "added": [], "removed": [] },
|
|
303
|
+
"oversized_files": { "added": [ { "path": "entry/src/main/ets/pages/Profile.ets", "lines": 2300, "language": "arkts", "module": "entry" } ], "removed": [], "persisted": [ { "path": "entry/src/main/ets/pages/Index.ets", "lines_delta": 320, "module": "entry" } ] }
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
"comparison_delta": {
|
|
307
|
+
"oversized": { "android_count": 0, "harmony_count": 1 },
|
|
308
|
+
"modules": { "android": 0, "harmony": 1 },
|
|
309
|
+
"third_party_dependencies": { "android": 0, "harmony": 2 },
|
|
310
|
+
"native_libraries": { "android": 0, "harmony": 0 },
|
|
311
|
+
"total_lines": { "android": 0, "harmony": 4200 }
|
|
312
|
+
},
|
|
313
|
+
"notes": []
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
- 差量一律为 current − previous;`by_language_delta` 与 `oversized_files.persisted` 只列非零项,其余 added/removed 全量列出。
|
|
318
|
+
- `previous_by_side.<id>` 为 null 表示该侧无可用 previous(如全新迁移首轮 harmony 无基线),该侧不进 `sides`,notes 如实说明。
|
|
319
|
+
- `source_kind` 由 previous 路径确定性推导:`baseline-android` / `baseline-harmony` / `history-final`(路径含 history 目录)/ `external`。
|
|
320
|
+
- `version_changed` 对比依赖级 `version`;同名多版本冲突仍以声明级字段为准(见第 4 节)。
|
|
321
|
+
- `comparison_delta` 仅当两侧 previous 为同一份双端终检快照(增量轮)时生成;首轮以基线为 previous(两侧不同源)时不生成,notes 说明。
|
|
322
|
+
- notes 暴露口径漂移:快照间 `thresholds`、`scanned_extensions`、`excluded_patterns` 不一致时逐条提示,差量解读需结合说明。
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic increment delta between two code-stats.json snapshots.
|
|
3
|
+
|
|
4
|
+
Produces increment-delta.json per skills/d2h-code-audit/references/code-stats-schema.md §12.
|
|
5
|
+
Pure function of the two input files; never rescans source trees.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import hashlib
|
|
12
|
+
import json
|
|
13
|
+
import sys
|
|
14
|
+
from collections import OrderedDict
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
SCHEMA_VERSION = "1.0"
|
|
19
|
+
TITLE = "增量开发差量"
|
|
20
|
+
GENERATED_BY = "d2h-code-audit/scripts/increment_delta.py"
|
|
21
|
+
|
|
22
|
+
SOURCE_KIND_DIRS = {
|
|
23
|
+
"baseline-android": "baseline-android",
|
|
24
|
+
"baseline-harmony": "baseline-harmony",
|
|
25
|
+
"history": "history-final",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def load_stats(path: Path) -> dict:
|
|
30
|
+
try:
|
|
31
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
32
|
+
except (OSError, ValueError) as error:
|
|
33
|
+
raise SystemExit("无法读取 code-stats.json:{}({})".format(path, error))
|
|
34
|
+
if (
|
|
35
|
+
not isinstance(data, dict)
|
|
36
|
+
or data.get("schema_version") != "1.0"
|
|
37
|
+
or not isinstance(data.get("sides"), dict)
|
|
38
|
+
or not data["sides"]
|
|
39
|
+
or not isinstance(data.get("repositories"), list)
|
|
40
|
+
):
|
|
41
|
+
raise SystemExit("无效的 code-stats.json:{}".format(path))
|
|
42
|
+
return data
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def file_sha256(path: Path) -> str:
|
|
46
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def source_kind(path: Path) -> str:
|
|
50
|
+
for part in path.parts:
|
|
51
|
+
if part in SOURCE_KIND_DIRS:
|
|
52
|
+
return SOURCE_KIND_DIRS[part]
|
|
53
|
+
return "external"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def revision_of(data: dict, side_id: str):
|
|
57
|
+
for repo in data["repositories"]:
|
|
58
|
+
if repo.get("id") == side_id:
|
|
59
|
+
return repo.get("revision")
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def by_language_delta(previous: dict, current: dict) -> list:
|
|
64
|
+
previous_map = {row["language"]: row for row in previous.get("by_language", [])}
|
|
65
|
+
current_map = {row["language"]: row for row in current.get("by_language", [])}
|
|
66
|
+
rows = []
|
|
67
|
+
for language in sorted(set(previous_map) | set(current_map)):
|
|
68
|
+
old = previous_map.get(language, {})
|
|
69
|
+
new = current_map.get(language, {})
|
|
70
|
+
files_delta = new.get("files", 0) - old.get("files", 0)
|
|
71
|
+
lines_delta = new.get("lines", 0) - old.get("lines", 0)
|
|
72
|
+
if files_delta or lines_delta:
|
|
73
|
+
rows.append(OrderedDict([
|
|
74
|
+
("language", language),
|
|
75
|
+
("files_delta", files_delta),
|
|
76
|
+
("lines_delta", lines_delta),
|
|
77
|
+
]))
|
|
78
|
+
return rows
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def delta_side(previous: dict, current: dict) -> "OrderedDict":
|
|
82
|
+
previous_code = previous.get("code", {})
|
|
83
|
+
current_code = current.get("code", {})
|
|
84
|
+
code = OrderedDict([
|
|
85
|
+
("total_files_delta", current_code.get("total_files", 0) - previous_code.get("total_files", 0)),
|
|
86
|
+
("total_lines_delta", current_code.get("total_lines", 0) - previous_code.get("total_lines", 0)),
|
|
87
|
+
("by_language_delta", by_language_delta(previous_code, current_code)),
|
|
88
|
+
])
|
|
89
|
+
|
|
90
|
+
previous_modules = {item["name"]: item for item in previous.get("modules", [])}
|
|
91
|
+
current_modules = {item["name"]: item for item in current.get("modules", [])}
|
|
92
|
+
modules = OrderedDict([
|
|
93
|
+
("added", [current_modules[name] for name in sorted(set(current_modules) - set(previous_modules))]),
|
|
94
|
+
("removed", sorted(set(previous_modules) - set(current_modules))),
|
|
95
|
+
])
|
|
96
|
+
|
|
97
|
+
previous_deps = {item["name"]: item for item in previous.get("third_party_dependencies", [])}
|
|
98
|
+
current_deps = {item["name"]: item for item in current.get("third_party_dependencies", [])}
|
|
99
|
+
version_changed = []
|
|
100
|
+
for name in sorted(set(previous_deps) & set(current_deps)):
|
|
101
|
+
old_version = previous_deps[name].get("version")
|
|
102
|
+
new_version = current_deps[name].get("version")
|
|
103
|
+
if old_version != new_version:
|
|
104
|
+
version_changed.append(OrderedDict([
|
|
105
|
+
("name", name),
|
|
106
|
+
("from", old_version),
|
|
107
|
+
("to", new_version),
|
|
108
|
+
]))
|
|
109
|
+
deps = OrderedDict([
|
|
110
|
+
("added", [OrderedDict([("name", name), ("version", current_deps[name].get("version"))])
|
|
111
|
+
for name in sorted(set(current_deps) - set(previous_deps))]),
|
|
112
|
+
("removed", sorted(set(previous_deps) - set(current_deps))),
|
|
113
|
+
("version_changed", version_changed),
|
|
114
|
+
])
|
|
115
|
+
|
|
116
|
+
previous_native = {item["name"] for item in previous.get("native_libraries", [])}
|
|
117
|
+
current_native = {item["name"] for item in current.get("native_libraries", [])}
|
|
118
|
+
native = OrderedDict([
|
|
119
|
+
("added", sorted(current_native - previous_native)),
|
|
120
|
+
("removed", sorted(previous_native - current_native)),
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
previous_oversized = {item["path"]: item for item in previous.get("oversized_files", [])}
|
|
124
|
+
current_oversized = {item["path"]: item for item in current.get("oversized_files", [])}
|
|
125
|
+
persisted = []
|
|
126
|
+
for path in sorted(set(previous_oversized) & set(current_oversized)):
|
|
127
|
+
lines_delta = current_oversized[path]["lines"] - previous_oversized[path]["lines"]
|
|
128
|
+
if lines_delta:
|
|
129
|
+
persisted.append(OrderedDict([
|
|
130
|
+
("path", path),
|
|
131
|
+
("lines_delta", lines_delta),
|
|
132
|
+
("module", current_oversized[path].get("module")),
|
|
133
|
+
]))
|
|
134
|
+
oversized = OrderedDict([
|
|
135
|
+
("added", [current_oversized[path] for path in sorted(set(current_oversized) - set(previous_oversized))]),
|
|
136
|
+
("removed", sorted(set(previous_oversized) - set(current_oversized))),
|
|
137
|
+
("persisted", persisted),
|
|
138
|
+
])
|
|
139
|
+
|
|
140
|
+
return OrderedDict([
|
|
141
|
+
("code", code),
|
|
142
|
+
("modules", modules),
|
|
143
|
+
("third_party_dependencies", deps),
|
|
144
|
+
("native_libraries", native),
|
|
145
|
+
("oversized_files", oversized),
|
|
146
|
+
])
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def comparison_delta(previous: dict, current: dict) -> "OrderedDict":
|
|
150
|
+
previous_comparison = previous["comparison"]
|
|
151
|
+
current_comparison = current["comparison"]
|
|
152
|
+
result = OrderedDict()
|
|
153
|
+
for key in ("modules", "third_party_dependencies", "native_libraries", "total_lines"):
|
|
154
|
+
result[key] = OrderedDict([
|
|
155
|
+
("android", current_comparison[key]["android"] - previous_comparison[key]["android"]),
|
|
156
|
+
("harmony", current_comparison[key]["harmony"] - previous_comparison[key]["harmony"]),
|
|
157
|
+
])
|
|
158
|
+
result["oversized"] = OrderedDict([
|
|
159
|
+
("android_count", current_comparison["oversized"]["android_count"] - previous_comparison["oversized"]["android_count"]),
|
|
160
|
+
("harmony_count", current_comparison["oversized"]["harmony_count"] - previous_comparison["oversized"]["harmony_count"]),
|
|
161
|
+
])
|
|
162
|
+
return result
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def main() -> int:
|
|
166
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
167
|
+
parser.add_argument("--previous", action="append", required=True, type=Path,
|
|
168
|
+
metavar="CODE_STATS_JSON", help="上一份 code-stats.json,可重复传入 1~2 份")
|
|
169
|
+
parser.add_argument("--current", required=True, type=Path, help="当前 code-stats.json")
|
|
170
|
+
parser.add_argument("--output", type=Path, default=Path("."), help="输出目录(默认当前目录)")
|
|
171
|
+
args = parser.parse_args()
|
|
172
|
+
|
|
173
|
+
current_path = args.current.expanduser().resolve()
|
|
174
|
+
current = load_stats(current_path)
|
|
175
|
+
previous_files = OrderedDict()
|
|
176
|
+
for raw in args.previous:
|
|
177
|
+
path = raw.expanduser().resolve()
|
|
178
|
+
if str(path) in previous_files:
|
|
179
|
+
parser.error("重复传入同一份 previous:{}".format(path))
|
|
180
|
+
previous_files[str(path)] = (path, load_stats(path))
|
|
181
|
+
|
|
182
|
+
previous_by_side = OrderedDict()
|
|
183
|
+
for side_id in current["sides"]:
|
|
184
|
+
matches = [(path, data) for path, data in previous_files.values() if side_id in data["sides"]]
|
|
185
|
+
if len(matches) > 1:
|
|
186
|
+
parser.error("多份 previous 包含 {} 侧:{}".format(side_id, ", ".join(str(p) for p, _ in matches)))
|
|
187
|
+
if matches:
|
|
188
|
+
path, data = matches[0]
|
|
189
|
+
previous_by_side[side_id] = OrderedDict([
|
|
190
|
+
("path", str(path)),
|
|
191
|
+
("sha256", file_sha256(path)),
|
|
192
|
+
("generated_at", data.get("generated_at")),
|
|
193
|
+
("source_kind", source_kind(path)),
|
|
194
|
+
("revision", revision_of(data, side_id)),
|
|
195
|
+
])
|
|
196
|
+
else:
|
|
197
|
+
previous_by_side[side_id] = None
|
|
198
|
+
|
|
199
|
+
notes = []
|
|
200
|
+
for side_id, entry in previous_by_side.items():
|
|
201
|
+
if entry is None:
|
|
202
|
+
notes.append("{} 侧无可用 previous 快照,未计算该侧差量".format(side_id))
|
|
203
|
+
for path, (path_obj, data) in previous_files.items():
|
|
204
|
+
for side_id in data["sides"]:
|
|
205
|
+
if side_id not in current["sides"]:
|
|
206
|
+
notes.append("previous({})中 {} 侧在 current 缺席,未使用".format(path_obj.name, side_id))
|
|
207
|
+
|
|
208
|
+
used_thresholds = {current.get("thresholds", {}).get("oversized_file_lines")}
|
|
209
|
+
used_previous_data = {}
|
|
210
|
+
for side_id, entry in previous_by_side.items():
|
|
211
|
+
if entry is not None:
|
|
212
|
+
used_previous_data[side_id] = load_stats(Path(entry["path"]))
|
|
213
|
+
used_thresholds.add(used_previous_data[side_id].get("thresholds", {}).get("oversized_file_lines"))
|
|
214
|
+
if len(used_thresholds) > 1:
|
|
215
|
+
notes.append("thresholds 在快照间不一致({}),超大文件差量口径可能漂移".format(
|
|
216
|
+
"、".join(str(value) for value in sorted(used_thresholds, key=lambda v: (v is None, v)))))
|
|
217
|
+
for side_id, previous_data in used_previous_data.items():
|
|
218
|
+
for field in ("scanned_extensions", "excluded_patterns"):
|
|
219
|
+
if previous_data["sides"][side_id].get("code", {}).get(field) != \
|
|
220
|
+
current["sides"][side_id].get("code", {}).get(field):
|
|
221
|
+
notes.append("{} 侧 {} 在快照间不一致,行数差量口径可能漂移".format(side_id, field))
|
|
222
|
+
|
|
223
|
+
sides = OrderedDict()
|
|
224
|
+
for side_id in current["sides"]:
|
|
225
|
+
if previous_by_side[side_id] is not None:
|
|
226
|
+
sides[side_id] = delta_side(
|
|
227
|
+
used_previous_data[side_id]["sides"][side_id],
|
|
228
|
+
current["sides"][side_id],
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
comparison_section = None
|
|
232
|
+
if "comparison" in current:
|
|
233
|
+
entries = [entry for entry in previous_by_side.values() if entry is not None]
|
|
234
|
+
same_source = (
|
|
235
|
+
len(current["sides"]) == 2
|
|
236
|
+
and len(entries) == 2
|
|
237
|
+
and len({entry["path"] for entry in entries}) == 1
|
|
238
|
+
)
|
|
239
|
+
if same_source:
|
|
240
|
+
previous_data = used_previous_data[next(iter(used_previous_data))]
|
|
241
|
+
if "comparison" in previous_data:
|
|
242
|
+
comparison_section = comparison_delta(previous_data, current)
|
|
243
|
+
else:
|
|
244
|
+
notes.append("previous 终检快照缺少 comparison,未生成 comparison_delta")
|
|
245
|
+
else:
|
|
246
|
+
notes.append("各侧 previous 非同一份双端终检快照,未生成 comparison_delta")
|
|
247
|
+
|
|
248
|
+
report = OrderedDict([
|
|
249
|
+
("schema_version", SCHEMA_VERSION),
|
|
250
|
+
("title", TITLE),
|
|
251
|
+
("language", "zh-CN"),
|
|
252
|
+
("generated_by", GENERATED_BY),
|
|
253
|
+
("generated_at", datetime.now().astimezone().isoformat(timespec="seconds")),
|
|
254
|
+
("inputs", OrderedDict([
|
|
255
|
+
("current", OrderedDict([
|
|
256
|
+
("path", str(current_path)),
|
|
257
|
+
("sha256", file_sha256(current_path)),
|
|
258
|
+
("generated_at", current.get("generated_at")),
|
|
259
|
+
("repositories", [OrderedDict([("id", repo.get("id")), ("revision", repo.get("revision"))])
|
|
260
|
+
for repo in current["repositories"]]),
|
|
261
|
+
])),
|
|
262
|
+
("previous_by_side", previous_by_side),
|
|
263
|
+
])),
|
|
264
|
+
("sides", sides),
|
|
265
|
+
])
|
|
266
|
+
if comparison_section is not None:
|
|
267
|
+
report["comparison_delta"] = comparison_section
|
|
268
|
+
report["notes"] = notes
|
|
269
|
+
|
|
270
|
+
args.output.mkdir(parents=True, exist_ok=True)
|
|
271
|
+
out_path = args.output / "increment-delta.json"
|
|
272
|
+
out_path.write_text(
|
|
273
|
+
json.dumps(report, ensure_ascii=False, indent=2) + "\n",
|
|
274
|
+
encoding="utf-8",
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
print("increment-delta.json: {}".format(out_path))
|
|
278
|
+
for side_id, delta in sides.items():
|
|
279
|
+
code = delta["code"]
|
|
280
|
+
deps = delta["third_party_dependencies"]
|
|
281
|
+
oversized = delta["oversized_files"]
|
|
282
|
+
print("[{}] lines_delta={} deps +{}/-{} (changed {}) oversized +{}/-{} persisted={}".format(
|
|
283
|
+
side_id,
|
|
284
|
+
code["total_lines_delta"],
|
|
285
|
+
len(deps["added"]), len(deps["removed"]), len(deps["version_changed"]),
|
|
286
|
+
len(oversized["added"]), len(oversized["removed"]), len(oversized["persisted"]),
|
|
287
|
+
))
|
|
288
|
+
if comparison_section is not None:
|
|
289
|
+
print("[comparison_delta] lines android={} harmony={} oversized android={} harmony={}".format(
|
|
290
|
+
comparison_section["total_lines"]["android"], comparison_section["total_lines"]["harmony"],
|
|
291
|
+
comparison_section["oversized"]["android_count"], comparison_section["oversized"]["harmony_count"],
|
|
292
|
+
))
|
|
293
|
+
for note in notes:
|
|
294
|
+
print("[note] {}".format(note))
|
|
295
|
+
return 0
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if __name__ == "__main__":
|
|
299
|
+
sys.exit(main())
|