---
title: 使用命令行进行源码迁移
description: "在终端环境下分析用户C/C++/ASM/Fortran/Go/解释型语言软件的可迁移性。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevkithistory/devkit_24_rc1/cliuserguide/KunpengDevKitCli_0013.html
sourcePath: /source/zh/kunpengdevkithistory/devkit_24_rc1/cliuserguide/KunpengDevKitCli_0013.html
indexId: 770868863eade40918fa0ee881fff868f2e5202d848ccf1d54a7d04c090afd0385
---
# 使用命令行进行源码迁移

#### 命令功能

在终端环境下分析用户C/C++/ASM/Fortran/Go/解释型语言软件的可迁移性。

如果用户所处的环境Glibc版本低于2.28，则无法使用最新的汇编文件自动翻译功能，如有需要，请按照以下步骤进行操作：

- 可连接外网：在“/DevKit-CLI-24.0.RC1-Linux-Kunpeng/porting/devkitplugins/all_asm/bin”下执行bash addAsmLibraries.sh即可。
- 无法连接外网：需手动创建tmp/rpm目录，把rpm包放至“DevKit/devkitplugins/all_asm/tmp/rpm”目录下，然后在“DevKit/devkitplugins/all_asm/bin”下执行bash addAsmLibraries.sh即可。


#### 命令格式

```
devkit porting src-mig -i,--input path-to-source-code -c,--cmd 'string of compiling command line' [-s,--source-type {c|c++|asm|fortran|go| interpreted}*] [-t,--target-os target-os] [-p,--compiler compiler-version] [-f,--fortran-compiler fortran-compiler-version] [-o,--output path-to-output] [-b,--build-tool {make,cmake,automake,go}] [-r,--report-type {all/json/html/csv}] [-l,--log-level {0,1,2,3} ] [--set-timeout time-limit-for-task] [--ignore path-to ignore-file] [--micro MICRO] [--keep-going {True,False}]
```


#### 参数说明


**表1 参数说明**

| 参数 | 参数选项 | 参数说明 |
| --- | --- | --- |
| \-i/\-\-input\-path | path | 待扫描源码的文件夹或压缩包路径，若存在多个扫描路径需使用英文逗号分隔。 必选参数。 例如：/home/test1,/home/test2。 |
| \-c/\-\-cmd | cmd | 源码的构建命令，需使用单/双引号引起来。若命令包含空格，需使用单引号。 可选参数。 例如：'make all'。 |
| \-s/\-\-source\-type | c,c++,asm,fortran,go,interpreted | 待扫描源码类型。 可选参数。 |
| \-t/\-\-target\-os | target\-os | 迁移的目标操作系统。 可选参数，如果用户不输入则默认为当前操作系统。 例如：bclinux7.7。 |
| \-p/\-\-compiler | gcc,clang | 编译器版本。 可选参数，默认为选定目标操作系统的默认GCC版本。 例如：gcc7.8.5。 |
| \-f/\-\-fortran\-compiler | flang\-ver | fortran代码的编译器版本。 可选参数，默认为flang2.5.0.1。 |
| \-b/\-\-build\-tool | make,cmake,automake,go | 构建工具。 可选参数，默认make，只有在\-\-source\-type中没有c/c++/asm/fortran并且包含go时可以选go。 |
| \-o/\-\-output | path\-to\-output | 扫描报告的存放地址和文件名称。 可选参数，默认存放在当前执行路径下，名称默认为功能名\_时间戳\_uuid(4位)。 |
| \-\-set\-timeout | time | 命令行的超时时间。 可选参数，默认无超时时间。 |
| \-l/\-\-log\-level | 0,1,2,3 | 设置日志级别。 可选参数，0（DEBUG）、1（INFO）、2（WARNING）、3（ERROR），默认为1（INFO）。 |
| \-r/\-\-report\-type | all,json,html,csv | 扫描报告的格式。 可选参数，默认为all，选择all的时候json、csv和html报告都会生成。 |
| \-\-ignore | /opt/ignore.json | 屏蔽扫描规则信息。 可选参数。 |


#### 使用实例

此处以分析TestData工程代码并输出csv格式、json格式、HTML格式的分析报告为例，请根据实际情况将“/home/TestData/”替换成实际需要扫描的代码路径。

```
devkit porting src-mig -i wtdbg2-2.5 -c "make"
```

返回信息如下，在返回信息中输入普通用户密码（新建用户首次使用时需要输入密码）。

```
Using the local system as target os: openeuler20.03sp1
Scanned time: 20240229094159
Configuration:
Check the related source files according to the build command
Scan code path: /opt/DevKit-CLI-24.0.RC1-Linux-Kunpeng/wtdbg2-2.5/
Compiler: GCC 4.8.5
Interpreted(Python, Java, Scala): False
Go: False
Target OS: openeuler20.03sp1, kernel: 4.19.90
Software make command: make
Source Need Migrated: YES
Summary:
Compatible: 0, To be Verified: 0, Total Dependencies: 0
Scanned 32 C/C++ files, 1 Makefile/CMakeLists.txt/Automake related files, total 3 files need to be migrated.
Total 13 lines C/C++/Makefile/CMakeLists.txt/Automake code need to be migrated.
Scanned 0 pure assembly files, no pure assembly files to be migrated.
Scanned 0 Go files, no Go files to be migrated.
Scanned 0 python files, no python files to be migrated.
Scanned 0 java files, no java files to be migrated.
Scanned 0 scala files, no scala files to be migrated.
For the detailed information, please check:
/opt/DevKit-CLI-24.0.RC1-Linux-Kunpeng/src-mig_20240229014159_918c.json
/opt/DevKit-CLI-24.0.RC1-Linux-Kunpeng/src-mig_20240229014159_918c.csv
/opt/DevKit-CLI-24.0.RC1-Linux-Kunpeng/src-mig_20240229014159_918c.html
```

不同的目标操作系统支持的SO库不一样，所以分析报告会有差异。


#### 输出说明


**表2 输出说明**

| 参数 | 参数 | 说明 |
| --- | --- | --- |
| Scanned time | Scanned time | 扫描时间。 |
| Configuration | Source Code File Path | 扫描的源码文件存放路径。 |
| Configuration | Target OS | 目标操作系统。 |
| Configuration | Target OS Kernel Version | 内核版本。 |
| Configuration | Compiler Version | 编译器版本。 |
| Configuration | Build Tool | 构建工具。 |
| Configuration | Software make command | 编译命令。 |
| Configuration | Interpreted(Python,Java,Scala) | 分析对象是否包括解释型语言文件。 True：是 False：否 |
| Configuration | Go | 分析对象是否包括Go语言文件。 True：是 False：否 |
| Configuration | Custom x86 Macros | 自定义x86宏。 |
| Summary | Compatible: x, To be Verified: x, Total Dependencies: x | 显示兼容鲲鹏平台的文件数，待验证文件数以及依赖库文件总数。 |
| Summary | Source Need Migrated | 源码是否需要迁移。 Yes No |
| Summary | Scanned xx C/C++/Fortran files, xx Makefile /CMakeLists.txt/Automake related files, total xx files need to be migrated. | 显示需要迁移的C/C++/Fortran文件和Makefile/CMakeLists.txt/Automake related文件总数以及文件个数。 |
| Summary | Total xx lines C/C++/Makefile/CMakeLists.txt/Automake code and xx lines embedding ASM code need to be migrated. | 显示源码总行数以及需要迁移的内联汇编代码行数。 |
| Summary | Scanned xx pure assembly files, xx pure assembly files to be migrated. | 显示全汇编文件总数以及需要迁移的汇编文件个数和汇编代码行数。 |
| Summary | Scanned x Go files, total x Go files xx lines need to be migrated. | 显示Go文件总数以及需要迁移的Go文件个数和Go代码行数。 |
| Summary | Scanned xx python files, total xx files xx lines need to be migrated. | 显示Python文件总数以及需要迁移的Python文件个数和Python代码行数。 |
| Summary | Scanned xx java files, total xx files xx lines need to be migrated. | 显示Java文件总数以及需要迁移的Java文件个数和Java代码行数。 |
| Summary | Scanned xx scala files, total xx files xx lines need to be migrated. | 显示Scala文件总数以及需要迁移的Scala文件个数和Scala代码行数。 |
| Summary | Estimated transplant workload: xx person/months.(C/C++/Fortran/Go, 500 Line/PM; ASM, 250Line/PM) | 显示源码迁移预估人力（x/人月）。 预估标准：1人月迁移工作量=500行C/C++/Fortran/Go源代码，或250行汇编代码。 |
| Architecture\-related Dependencies | Architecture\-related Dependencies | 显示依赖库文件扫描的详细信息： File Name：文件名称。 File Type：文件类型。 Analysis Results：分析结果。 Handling Suggestions：处理建议。 URL：下载地址。 |
| Source files scan details are as follows: | Source files scan details are as follows: | 显示源文件分析报告的详细信息： filename：扫描文件全路径。 filetype：扫描文件的类型。 line number：函数在文件中的行号。 rows：函数在文件中的总行数。 category：关键字所属类型。 keyword：关键字名称。 suggestion：迁移建议或者提示建议。 description：关键字用法描述。 |
