想了解更多关于开源的内容,请访问:51CTO 开源基础软件社区https://ost.51cto.commaster,结果发现编译竟然出错了,错误提示如下:
显示的是在链接阶段没有找到如opendir,closedir等符号,这显然就是kv_store库编译有问题。
这个参数一加,我们kv的编译就会使用posix相关的接口去实现,而在3861里面应该是没有实现posix相关的文件接口,所以导致链接的时候出现opendir等等通不过,那么将这个参数置false再编译试试看:
不出意外的编译成功了,说明问题出在这里。一句话概括就是,你的代码需要依赖框架的代码,如果把框架拿掉或者换一个框架,就需要重新修改代码。也就是说:kv是openharmony里面的一个组件,我们使用openharmony的代码框架的时候如果碰到问题,是不能通过侵入式修改达到目的的,因为这样会破坏原有的代码逻辑,假如后面如果有其他项目要使用这个代码的话,就可能会出现问题,有时候甚至会是灾难性的后果.
比如我们现在是在编译bearpi_hm_nano,那么我们只需要在vendor/bearpi/bearpi_hm_nano/config.json里面编辑,把kv_store库添加对应的参数即可,这里不知道是bug还是gn的原理就是这样,我们不需要找到kv_store真正的库声明位置,而是随便一个地方加上"enable_ohos_utils_native_lite_kv_store_use_posix_kv_api=false"就可以正常编译通过了,比如:
这样再编译就成功了。探究一下原理,在gn进行build的时候,会在out目录下生成一个args.gn文件,这个文件里保存了所有需要用到的args,如:
这里的args都是顺序排列的,在gn进行构建的时候会读取里面所有的参数。{
"product_name": "bearpi_hm_nano",
"type": "mini",
"version": "3.0",
"ohos_version": "OpenHarmony 1.1.0",
"device_company": "bearpi",
"device_build_path": "device/board/bearpi/bearpi_hm_nano",
"board": "bearpi_hm_nano",
"kernel_type": "liteos_m",
"kernel_is_prebuilt": true,
"kernel_version": "",
"subsystems": [
{
"subsystem": "iothardware",
"components": [
{ "component": "peripheral", "features":[] }
]
},
{
"subsystem": "hiviewdfx",
"components": [
{ "component": "hilog_lite", "features":[] },
{ "component": "hievent_lite", "features":[] },
{ "component": "blackbox", "features":[] },
{ "component": "hidumper_mini", "features":[] }
]
},
{
"subsystem": "systemabilitymgr",
"components": [
{ "component": "samgr_lite", "features":[] }
]
},
{
"subsystem": "security",
"components": [
{ "component": "device_auth", "features":[] },
{ "component": "huks", "features":
[
"disable_huks_binary = false",
"disable_authenticate = false",
"huks_use_lite_storage = true",
"huks_use_hardware_root_key = true",
"huks_config_file = \"hks_config_lite.h\"",
"ohos_security_huks_mbedtls_porting_path = \"//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party/mbedtls\""
]
}
]
},
{
"subsystem": "startup",
"components": [
{ "component": "bootstrap_lite", "features":[] },
{ "component": "init_lite", "features":
[
"enable_ohos_startup_init_feature_begetctl_liteos=true",
"enable_ohos_startup_init_lite_use_thirdparty_mbedtls = false"
]
}
]
},
{
"subsystem": "communication",
"components": [
{ "component": "wifi_lite", "features":[] },
{ "component": "dsoftbus", "features":[] },
{ "component": "wifi_aware", "features":[]}
]
},
{
"subsystem": "updater",
"components": [
{ "component": "ota_lite", "features":[] }
]
},
{
"subsystem": "commonlibrary",
"components": [
{ "component": "file", "features":[] }
]
},
{
"subsystem": "xts",
"components": [
{ "component": "xts_acts", "features":
[
"enable_ohos_test_xts_acts_use_thirdparty_lwip = false"
]
},
{ "component": "xts_tools", "features":[] }
]
}
],
"third_party_dir": "//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party",
"product_adapter_dir": "//vendor/bearpi/bearpi_hm_nano/hals"
}
如果还不明白,建议找几篇gn相关的文章看看就懂了。现在的办法就是一层一层的找到是谁调用的kv_store库,回到之前编译出错的地方:
可以看到有一个名为utils_kv_store的lib文件,先找一下:
然后再去找由谁依赖了utils_kv_store。现在问题出来了,openharmony里面这么多代码,如果每一个库都要这样不停的搜索相关字才能找到最终依赖的地方,效率低不说,还容易出错,而且很容易跟着就跟丢了,这是因为人的记忆力毕竟有限,函数调用太多层就会丢失路径,这也就是为什么人类下棋永远下不过电脑。//out/bearpi_hm_nano/bearpi_hm_nano/build_configs/device_bearpi_hm_nano/device_bearpi_hm_nano:device_bearpi_hm_nano_info
//device/soc/hisilicon/hi3861v100:hi3861v100
//device/soc/hisilicon/hi3861v100/sdk_liteos:run_wifiiot_scons
//base/security/device_auth/frameworks/deviceauth_lite:hichainsdk
//base/security/device_auth/frameworks/deviceauth_lite/source:hichainsdk
//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk
//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk__notice
//third_party/musl:sysroot_lite
//third_party/mbedtls:mbedtls_static
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//build/lite:ohos
//base/hiviewdfx/blackbox:blackbox
//third_party/musl:sysroot_lite
//base/hiviewdfx/hidumper_lite/mini:hidumper_mini
//third_party/musl:sysroot_lite
//base/hiviewdfx/hievent_lite:hievent_lite
//base/hiviewdfx/hievent_lite:hievent_lite_static
//base/hiviewdfx/hiview_lite:hiview_lite
//base/hiviewdfx/hiview_lite:hiview_lite_static
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite
//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite_static
//base/hiviewdfx/hiview_lite:hiview_lite...
//third_party/musl:sysroot_lite
//base/iothardware/peripheral:iothardware
//device/soc/hisilicon/hi3861v100/hi3861_adapter/hals/iot_hardware/wifiiot_lite:hal_iothardware
//third_party/musl:sysroot_lite
//base/security/device_auth:deviceauth_build
//base/security/device_auth/services:deviceauth
//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite...
//base/security/device_auth/deps_adapter:deviceauth_hal_liteos
//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite...
//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk...
//base/startup/init/interfaces/innerkits:libbegetutil
//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static
//third_party/bounds_checking_function:libsec_static
//third_party/musl:sysroot_lite
//base/startup/init/interfaces/hals/utils/sys_param:hal_sys_param
//third_party/musl:sysroot_lite
//base/startup/init/services/log:init_log
//third_party/musl:sysroot_lite
//base/startup/init/services/modules/init_hook:inithook
//third_party/musl:sysroot_lite
//base/startup/init/services/param/liteos:param_client_lite
//base/startup/init/services/param/liteos:lite_ohos_param_to
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//base/startup/init/services/utils:libinit_utils
//third_party/musl:sysroot_lite
//third_party/bounds_checking_function:libsec_static
//third_party/musl:sysroot_lite
//vendor/bearpi/bearpi_hm_nano/hals/utils/sys_param:hal_sysparam
//third_party/musl:sysroot_lite
//build/lite/config/component/cJSON:cjson_shared
//commonlibrary/utils_lite:utils
//commonlibrary/utils_lite/file:file
//commonlibrary/utils_lite/file:native_file
//commonlibrary/utils_lite/hals/file:static_hal_file
//commonlibrary/utils_lite/hals/file:static_hal_file__notice
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//device/soc/hisilicon/hi3861v100/hi3861_adapter/hals/utils/file:hal_file_static
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store:kv_store
//foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store:utils_kv_store
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//build/lite/config/component/cJSON:cjson_shared
//commonlibrary/utils_lite:utils...
//foundation/communication/dsoftbus/sdk:softbus_client
//foundation/communication/dsoftbus/adapter:softbus_adapter
//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite...
//third_party/mbedtls:mbedtls
//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party/mbedtls:mbedtls
//third_party/musl:sysroot_lite
//foundation/communication/dsoftbus/core/common:softbus_utils
//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite...
//build/lite/config/component/cJSON:cjson_static
//third_party/musl:sysroot_lite
//foundation/communication/dsoftbus/adapter:softbus_adapter...
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//base/security/device_auth:deviceauth_sdk_build
//base/security/device_auth:deviceauth_service_build
//base/security/device_auth/frameworks/deviceauth_lite:hichainsdk...
//base/security/huks:fwk_group
//base/security/huks/frameworks/huks_lite:huks_sdk
//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk...
//base/security/huks/test:unittest
//base/security/huks:service_group
//base/startup/bootstrap_lite/services/source:bootstrap
//third_party/musl:sysroot_lite
//base/startup/init/services:startup_init
//base/startup/init/services/begetctl:begetctl_cmd
//base/startup/init/services/loopevent:loopeventgroup
//base/startup/init/services/modules:modulesgroup
//base/startup/init/services/param:parameter
//base/startup/init/ueventd:startup_ueventd
//base/startup/init/watchdog:watchdog
//base/update/ota_lite/frameworks:ota_lite
//base/update/ota_lite/frameworks/source:hota
//base/startup/init/interfaces/innerkits:libbegetutil...
//device/soc/hisilicon/hi3861v100/hi3861_adapter/hals/update:hal_update_static
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//commonlibrary/utils_lite/file:file...
//foundation/communication/dsoftbus:dsoftbus
//foundation/communication/dsoftbus/core:softbus_server
//foundation/communication/dsoftbus/adapter:softbus_adapter...
//foundation/communication/dsoftbus/core/common:softbus_utils...
//foundation/communication/dsoftbus/core/frame:softbus_server_frame
//base/security/device_auth/services:deviceauth...
//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk...
//base/startup/init/interfaces/innerkits:libbegetutil...
//build/lite/config/component/cJSON:cjson_static...
//build/lite/config/component/cJSON:cjson_static...
//foundation/communication/dsoftbus/adapter:softbus_adapter...
//foundation/communication/dsoftbus/components/nstackx/nstackx_ctrl:nstackx_ctrl
//foundation/communication/dsoftbus/components/nstackx/nstackx_util:nstackx_util.open
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//foundation/communication/dsoftbus/core/common:softbus_utils...
//third_party/musl:sysroot_lite
//foundation/communication/dsoftbus/sdk:softbus_client...
//foundation/communication/dsoftbus/tests:softbus_test
//foundation/communication/wifi_aware:wifiaware
//device/soc/hisilicon/hi3861v100/hi3861_adapter/hals/communication/wifi_lite/wifiaware:hal_wifiaware
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//foundation/communication/wifi_lite:wifi
//foundation/systemabilitymgr/samgr_lite:samgr
//foundation/systemabilitymgr/samgr_lite/communication/broadcast:broadcast
//third_party/musl:sysroot_lite
//foundation/systemabilitymgr/samgr_lite/samgr:samgr
//foundation/systemabilitymgr/samgr_lite/samgr/adapter:samgr_adapter
//third_party/musl:sysroot_lite
//foundation/systemabilitymgr/samgr_lite/samgr/source:samgr_source
//foundation/systemabilitymgr/samgr_lite/samgr/adapter:samgr_adapter...
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite
//device/soc/hisilicon/hi3861v100/sdk_liteos:sdk
//build/lite/config/component/cJSON:cjson_static...
//build/lite/config/component/cJSON:cjson_static...
//device/soc/hisilicon/hi3861v100/hi3861_adapter/hals/communication/wifi_lite/wifiservice:wifiservice
//third_party/musl:sysroot_lite
//device/soc/hisilicon/hi3861v100/hi3861_adapter/hals/communication/wifi_lite/wifiservice:wifiservice...
//device/soc/hisilicon/hi3861v100/hi3861_adapter/kal:kal
//device/soc/hisilicon/hi3861v100/hi3861_adapter/kal/cmsis:cmsis
//third_party/musl:sysroot_lite
//device/soc/hisilicon/hi3861v100/hi3861_adapter/kal/posix:posix
//third_party/musl:sysroot_lite
//device/soc/hisilicon/hi3861v100/hi3861_adapter/kal:kal...
//third_party/musl:sysroot_lite
//third_party/musl:sysroot_lite

可以看到很轻松就找到了kv_store是怎么被一层一层依赖的了,而且通过关系图可以得知kv_store竟然是由device_auth引入的,那么这个工具的意义就在于:有了依赖树,以后出现依赖相关的问题都可以通过它快速分析并定位问题了。看到这里是不是好心动,是不是想学习一下怎么用呢?只需要在命令行输入gn help desc就能得知用法了:root@346a62050f11:/home/openharmony# gn help desc
gn desc
gn desc <out_dir> <label or pattern> [<what to show>] [--blame]
[--format=json]
Displays information about a given target or config. The build parameters
will be taken for the build in the given <out_dir>.
The <label or pattern> can be a target label, a config label, or a label
pattern (see "gn help label_pattern"). A label pattern will only match
targets.
...all_dependent_configs
allow_circular_includes_from
arflags [–blame] args
cflags [–blame]
cflags_c [–blame]
cflags_cc [–blame]
check_includes
configs [–tree] (see below)
data_keys
defines [–blame]
depfile
deps [–all] [–tree] (see below)
framework_dirs
frameworks
include_dirs [–blame]
inputs ldflags [–blame]
lib_dirs libs
metadata
output_conversion
outputs
public_configs
public
rebase
script
sources
testonly
visibility
walk_keys
weak_frameworks
runtime_deps
[–format=json] 以JSON的格式输出。我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?