源码迁移命令参考
源码迁移功能分析用户C/C++/ASM/Fortran/Go/解释型语言软件的可迁移性。
命令功能
在终端环境下分析用户C/C++/ASM/Fortran/Go/解释型语言软件的可迁移性。
注意事项
如果用户所处的环境Glibc版本低于2.28,则无法使用最新的汇编文件自动翻译功能,如有需要,请按照以下步骤进行操作:

若使用RPM安装方式,则PATH为/usr/local/devkit;若使用解压压缩包方式安装,则PATH为解压路径。
- 可连接外网:在“PATH/porting/devkitplugins/all_asm/bin”下执行bash addAsmLibraries.sh即可。
- 无法连接外网:需手动创建tmp/rpm目录,把RPM包放至“PATH/porting/devkitplugins/all_asm/tmp/rpm”目录下,然后在“PATH/porting/devkitplugins/all_asm/bin”下执行bash addAsmLibraries.sh即可。
命令格式
1 | devkit porting src-mig {-i INPUT_PATH | --input INPUT_PATH} {-c 'command' | --cmd 'command'} [-s {c|c++|asm|fortran|go| interpreted}* | --source-type {c|c++|asm|fortran|go| interpreted}*] [-t targe_os | --target-os targe_os] [-p compiler_version | --compiler compiler_version] [-f fortran-compiler-version | --fortran-compiler fortran-compiler-version] [-o OUTPUT_PATH | --output OUTPUT_PATH] [-b {make,cmake,automake,go} | --build-tool {make,cmake,automake,go}] [-r {all,json,html,csv} | --report-type {all,json,html,csv}] [-l {0,1,2,3} | --log-level {0,1,2,3}] [--set-timeout TIMEOUT] [--ignore ignore_file] [--ignore-path IGNORE_PATH] [--macro MACRO] [--keep-going {True,False}] |
参数说明
参数 |
参数选项 |
参数说明 |
---|---|---|
-h/--help |
- |
获取帮助信息。 |
-i/--input-path |
- |
待扫描源码的文件夹或压缩包所在路径,若存在多个扫描路径需使用空格分隔。 例如:/home/test1 /home/test2。 |
-c/--cmd |
- |
源码的构建命令,需使用单/双引号引起来。若命令包含空格,需使用单引号。 |
-s/--source-type |
c/c++/asm/fortran/go/interpreted |
待扫描源码类型,默认为'c,c++,asm'。 interpreted为解释型语言,目前支持的解释型语言包括Python、Java和Scala。 |
-t/--target-os |
详见-h帮助信息。 |
迁移的目标操作系统,如果用户不输入则默认为当前操作系统。 |
-p/--compiler |
详见-h帮助信息。 |
编译器版本,c/c++/asm和go语言使用相同的编译器版本。默认为目标操作系统附带的编译器版本。 |
-f/--fortran-compiler |
flang2.1.0/flang2.3.0/flang2.4.0/flang2.5.0/flang2.5.0.1/flang3.0.0/flang3.1.0/flang3.2.0/flang4.0.0/flang4.1.0/gfortran7/gfortran8/gfortran9 |
fortran代码的编译器版本,默认为flang2.5.0.1。 |
-b/--build-tool |
make/cmake/automake/go |
构建工具,默认make。只有在待扫描源码类型中没有c/c++/asm/fortran并且包含go时可以选go。 |
-o/--output |
- |
扫描报告的存放路径,默认存放在当前执行路径下,报告名称为特性名称_时间戳。 |
--set-timeout |
- |
任务超时时间,单位为分钟,若执行时间超过超时时间则退出执行。默认无超时时间,任务将持续执行直到结束。 |
-l/--log-level |
0/1/2/3 |
设置日志级别,默认为1。
|
-r/--report-type |
all/json/html/csv |
扫描报告的格式,默认为all。
|
--ignore |
/opt/ignore_rules.json |
可通过配置屏蔽扫描规则文件,屏蔽不影响扫描结果的信息。默认读取工具路径下的ignore_rules.json文件,具体格式请参见屏蔽扫描规则文件说明(--ignore)。 |
--ignore-path |
- |
指定需要屏蔽扫描的源码文件或源码文件夹所在路径,若存在多个路径需使用空格分隔。 例如:/home/jar /home/ear /home/a.cpp |
--macro |
- |
自定义x86平台宏。输入自定义宏时,多个宏之间请用“;”进行分隔。 |
--keep-going |
True/False |
发现arm/arm64/aarch64关键字是否继续扫描。
|
使用示例
此处以分析TestData工程代码并输出CSV格式、JSON格式、HTML格式的分析报告为例,请根据实际情况将“/home/TestData/”替换成实际需要扫描的代码路径。
1 | devkit porting src-mig -i /home/TestData/wtdbg2-2.5 -c "make" |
返回信息如下,并输出报告。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | Using the local system as target os: openeuler20.03sp1 Scanned time: 2024-12-12 15:37:45 Configuration: Check the related source files according to the build command Scan code path: /home/TestData/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: Need Migrated Summary: Adaptable for Compatibility: 0, To be Modified: 0, Total Dependencies: 0 Total 5 rules and 10 suggestions. 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: /home/DevKit_Software/src-mig_20241119012038_7e6a_zh.json /home/DevKit_Software/src-mig_20241119012038_7e6a_zh.csv /home/DevKit_Software/src-mig_20241119012038_7e6a.html |

不同的目标操作系统支持的SO库不一样,所以分析报告会有差异。
屏蔽扫描规则文件说明(--ignore)
可通过ignore_rules.json文件配置屏蔽扫描规则,配置完成后重新扫描文件,扫描报告中将不会展示该扫描项。配置示例如下:
1 2 3 4 5 6 7 8 9 | { "src_list": [ "-march", "-mpopcnt", ], "lib_list": [ "libz.so.1" ] } |

- lib_list:需要屏蔽的依赖文件列表。
- src_list:需要屏蔽的源码文件关键字列表。
输出报告说明
参数 |
说明 |
---|---|
配置信息 |
显示任务名称、报告生成时间、源码文件存放路径、目标操作系统、目标系统内核版本、编译器版本、构建工具、编译命令和自定义x86宏以及迁移结果。 |
与架构相关的依赖文件 |
显示SO文件。
|
需要迁移的源文件 |
显示需要迁移的源文件总数和需要修改的代码行数,通过单击操作列“查看建议源码”可以快速进入对应的源码迁移建议页面。 文件类型包括C/C++ Source File,Fortran,makefile,Python,Go,Java,Scala以及ASM File,可通过筛选查看具体类型的文件。 文件所在的路径根据Unicode编码排序,需修改的代码行根据行数排序。 |