编译报错:Ninja build error. The ninja build system cannot parse the build file?

编译报错:Ninja build error. The ninja build system cannot parse the build file

源码中新建自定义子系统simple,内部含uart_test.c,build.gn,bundle.json文件。
uart_test.c

#include <stdio.h>
#include <stdlib.h>    //goto函数
#include <stdint.h>    //unint8_t
#include <unistd.h>    //sleep()  //s
 
//#include "hdf_log.h"    //路径:    "//drivers/hdf_core/interfaces/inner_api/utils",
#include "uart_if.h"    //路径:    "//drivers/hdf_core/framework/include/platform",
 
// static int32_t UartTestSample(void)
// {
 
// }
 
int main(){
    printf("uart_test begin\r\n");
 
    printf("---------------------------\n");
 
    int32_t ret;
    uint32_t port;
    uint32_t baud;
    DevHandle handle = NULL;
    uint8_t wbuff[5] = { 1, 2, 3, 4, 5 };
    uint8_t rbuff[5] = { 0 };
    struct UartAttribute attribute;
 
    attribute.dataBits = UART_ATTR_DATABIT_8;                  // UART传输数据位宽,一次传输7个bit
    attribute.parity = UART_ATTR_PARITY_NONE;                  // UART传输数据无校检
    attribute.stopBits = UART_ATTR_STOPBIT_1;                  // UART传输数据停止位为1位
    attribute.rts = UART_ATTR_RTS_DIS;                         // UART禁用RTS
    attribute.cts = UART_ATTR_CTS_DIS;                         // UART禁用CTS
    attribute.fifoRxEn = UART_ATTR_RX_FIFO_EN;                 // UART使能RX FIFO
    attribute.fifoTxEn = UART_ATTR_TX_FIFO_EN;                 // UART使能TX FIFO
 
    port = 3;                                                  // UART设备端口号,要填写实际平台上的端口号
 
    handle = UartOpen(port);                                   // 获取UART设备句柄
    if (handle == NULL) {
        printf("UartOpen(port) failed \r\n");
        return HDF_FAILURE;
    }
 
    ret = UartSetBaud(handle, 1500000);                           // 设置UART波特率为1500000
    if (ret != 0) {
        printf("UartSetBaud: set baud failed, ret %d\n", ret);
        goto ERR;
    }
    printf("UartOpen successful and uart port = %d\n",port);
 
    ret = UartGetBaud(handle, &baud);                          // 获取UART波特率
    if (ret != 0) {
        printf("UartGetBaud: get baud failed, ret %d\n", ret);
        goto ERR;
    }
    printf("UartSetBaud successful and uart baudrate = %d\n", baud);
 
    ret = UartSetAttribute(handle, &attribute);                // 设置UART设备属性
    if (ret != 0) {
        printf("UartSetAttribute: set attribute failed, ret %d\n", ret);
        goto ERR;
    }
    printf("UartSetAttribute successful\n");
 
    ret = UartGetAttribute(handle, &attribute);                // 获取UART设备属性
    if (ret != 0) {
        printf("UartGetAttribute: get attribute failed, ret %d\n", ret);
        goto ERR;
    }
    printf("UartGetAttribute successful\n");
 
 
    ret = UartSetTransMode(handle, UART_MODE_RD_BLOCK);     // 设置UART传输模式为非阻塞模式
    if (ret != 0) {
        printf("UartSetTransMode: set trans mode failed, ret %d\n", ret);
        goto ERR;
    }
    printf("UartSetTransMode successful\n");
 
    ret = UartWrite(handle, wbuff, 5);                         // 向UART设备写入5字节的数据
    if (ret != 0) {
        printf("UartWrite: write data failed, ret %d\n", ret);
        goto ERR;
    }
    //printf("UartWrite successful and wbuff:  %u\n",wbuff);       //这里输出的为整型,所以引用符号应为d
    //printf(wbuff);
     for(int i=0;i<5;i++){
        printf("write:%hhu\r\n",wbuff[i]);
     }
 
    // ret = UartRead(handle, rbuff, 5);                          // 从UART设备读取5字节的数据
    // if (ret < 0) {
    //     printf("UartRead: read data failed, ret %d\n", ret);
    //     goto ERR;
    // }
    // //printf("UartRead successful and rbuff:   %u\n",rbuff);
    // //printf(rbuff);
    //  for(int i=0;i<5;i++){
    //     printf("%u",rbuff[i]);
    //  }
    
    int j=1;
     while(1){
        ret=UartRead(handle, rbuff, 5);
        if(ret<0){
            printf("read fail\r\n");
            goto ERR;
        }
        if(ret==-1||ret==0){
            continue;    //如果没读到,那就跳出循环再读
        }
        printf("readlen=:%d\n",ret);
        for(int i=0;i<ret;i++){
            printf("read:%02x\r\n",rbuff[i]); //按十六进制输出
        }
        j++;
        printf("\n");
        usleep(10*1000); //sleep 10ms
        if(j>3)break;
     }
 
 
    printf(" function tests end\r\n");
ERR:
    UartClose(handle);                                         // 销毁UART设备句柄
    return ret;
 
    printf("---------------------------\n");
 
}

BUILD.gn

import("//build/ohos.gni")
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
 
print("samples: compile rk3568_uart_test")
ohos_executable("A2_gcwuart") {
  sources = [ "src/uart_test.c" ]
  include_dirs = [
    "//drivers/hdf_core/framework/include/platform",
    "//third_party/bounds_checking_function/include",
  ]
 
  deps = []
 
  external_deps = [
    "c_utils:utils",
    "hdf_core:libhdf_utils",
    "hdf_core:libhdf_platform",
  ]
 
  cflags = [
    "-Wall",
    "-Wextra",
    "-Werror",
    "-Wno-format",
    "-Wno-format-extra-args",
  ]
 
  part_name = "A2_uart"
  install_enable = true
}

bundle.json

{
    "name": "@ohos/A2_uart",
    "description": "gcw uart test",
    "version": "3.1",
    "license": "Apache License 2.0",
    "publishAs": "code-segment",
    "segment": {
        "destPath": "gcw/A2_uart"
    },
    "dirs": {},
    "scripts": {},
    "component": {
        "name": "A2_uart",
        "subsystem": "gcw",
        "syscap": [],
        "features": [],
        "adapted_system_type": ["standard"],
        "rom": "100KB",
        "ram": "100KB",
        "deps": {
            "components": [
                "c_utils",
                "hdf_core"
            ],
            "third_party": []
        },
        "build": {
            "sub_component": [
                "//gcw/A2_uart:A2_gcwuart"
            ],
            "inner_kits": [],
            "test": []
        }
    }
}

按照以上方式添加,并在config.json和subsystem_config.json进行了修改。
subsystem_config.json

"uart": {

"path": "uart",
"name": "uart"
}

config.json

{

      "component": "A1_helloworld",
      "features": []
    },
    {
      "component": "B1_helloworld",
      "features": []
    },
    {
      "component": "A2_uart",
      "features": []
    },
    {
      "component": "A3_gpio",
      "features": []
    }
  ]
}

尝试按照以上步骤进行操作,使用./build.sh --product-name rk3568 --build-target A2_uart编译,

!!!!
编译uart失败报错,报错日志如下:

[OHOS INFO] Excuting ninja command: /home/forlinx/forlinx-4.1-release/openharmony-4.1-release/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/forlinx/forlinx-4.1-release/openharmony-4.1-release/out/ok3568 A2_uart

[OHOS ERROR] ninja: error: unknown target 'A2_uart'

[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] return func(args, *kwargs)
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] raise exception
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/modules/ohos_build_module.py", line 65, in run
[OHOS ERROR] super().run()
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/modules/interface/build_module_interface.py", line 72, in run
[OHOS ERROR] raise exception
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/modules/interface/build_module_interface.py", line 70, in run
[OHOS ERROR] self._target_compilation()
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/modules/ohos_build_module.py", line 103, in _target_compilation
[OHOS ERROR] self.target_compiler.run()
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/services/ninja.py", line 38, in run
[OHOS ERROR] self._execute_ninja_cmd()
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/services/ninja.py", line 69, in _execute_ninja_cmd
[OHOS ERROR] SystemUtil.exec_command(
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/util/system_util.py", line 64, in exec_command
[OHOS ERROR] LogUtil.get_failed_log(log_path)
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/util/log_util.py", line 192, in get_failed_log
[OHOS ERROR] LogUtil.get_ninja_failed_log(log_path)
[OHOS ERROR] File "/home/forlinx/forlinx-4.1-release/openharmony-4.1-release/build/hb/util/log_util.py", line 157, in get_ninja_failed_log
[OHOS ERROR] raise OHOSException(
[OHOS ERROR] exceptions.ohos_exception.OHOSException: NINJA Failed! Please check error in /home/forlinx/forlinx-4.1-release/openharmony-4.1-release/out/ok3568/error.log, and for more build information in /home/forlinx/forlinx-4.1-release/openharmony-4.1-release/out/ok3568/build.log
[OHOS ERROR]

[OHOS ERROR] Code: 4015
[OHOS ERROR]
[OHOS ERROR] Reason: NINJA Failed! Please check error in /home/forlinx/forlinx-4.1-release/openharmony-4.1-release/out/ok3568/error.log, and for more build information in /home/forlinx/forlinx-4.1-release/openharmony-4.1-release/out/ok3568/build.log
[OHOS ERROR]
[OHOS ERROR] Error Type: ninja build error: unknown target
[OHOS ERROR]
[OHOS ERROR] Description: Ninja build error. The ninja build system cannot parse the build file.
[OHOS ERROR]
[OHOS ERROR] Solution: Please check that the target name is correct.
[OHOS ERROR] Please check that the BUILD.gn file including the target, is exists and valid.
[OHOS ERROR] Please check that the target belongs to a component and that component is in the product configuration.
[OHOS ERROR]
=====build error=====
阅读 1.4k
1 个回答

这是openharmony开发场景吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进