如何将 Facebook BUCK 与 DTrace 文件一起使用?

How to use Facebook BUCK with DTrace files?

所以,如果你打开 https://github.com/airbnb/BuckSample 并将尝试使用 cocoaPods https://github.com/ReactiveCocoa/ReactiveObjC

安装

然后添加新的 BUCK 构建规则,例如

apple_third_party_lib(
    name = "ReactiveObjC",
    visibility = ["PUBLIC"],
    srcs = glob([
        "ReactiveObjC/**/*.m",
    ]),
    exported_headers = glob([
        "ReactiveObjC/**/*.h",
    ]),
    frameworks = [
        "$PLATFORM_DIR/Developer/Library/Frameworks/Foundation.framework",
    ],
)

buck build //Pods:ReactiveObjC 会失败并出现这样的错误

Pods/ReactiveObjC/ReactiveObjC/RACPassthroughSubscriber.m:12:9: fatal error: 'RACSignalProvider.h' file not found

如果我们走得更远,我们会看到 RACSignalProvider.h 不在 Pod 源中,但是 RACSignalProvider.d 是 DTrace 源文件。

当我们尝试用 XCode 编译它时,我们可以看到在编译实际框架之前有一个额外的步骤

CompileDTraceScript /*user folder*/Pods/ReactiveObjC/ReactiveObjC/RACSignalProvider.d (in target 'ReactiveObjC' from project 'Pods')
    cd /*user folder*/Pods
    /usr/sbin/dtrace -h -s /*user folder*/Pods/ReactiveObjC/ReactiveObjC/RACSignalProvider.d -o /*user folder*/Library/Developer/Xcode/DerivedData/Odnoklassniki-gsukbcogkxolydbhlpglswzdhhpg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/ReactiveObjC.build/DerivedSources/RACSignalProvider.h

当我们 运行 降压构建

时不会发生这种情况

配置中是否缺少某些内容?还是 BUCK 不支持?

所以答案是,您需要使用 genrule() 来处理您的 DTrace 文件 它应该看起来像

genrule(
    name = "ReactiveObjC_DTrace",
    srcs = [
        "ReactiveObjC/ReactiveObjC/RACSignalProvider.d",
        "ReactiveObjC/ReactiveObjC/RACCompoundDisposableProvider.d",
    ],
    bash = 
"""
    mkdir -p $OUT
    /usr/sbin/dtrace -h -s $SRCDIR/ReactiveObjC/ReactiveObjC/RACSignalProvider.d -o $OUT/RACSignalProvider.h
    /usr/sbin/dtrace -h -s $SRCDIR/ReactiveObjC/ReactiveObjC/RACCompoundDisposableProvider.d -o $OUT/RACCompoundDisposableProvider.h
""",
    out = "ReactiveObjC_DTrace",
    visibility = ["PUBLIC"]
)

然后将您的 ReactiveObjC 规则修改为

apple_third_party_lib(
    name = "ReactiveObjC",
    visibility = ["PUBLIC"],
    srcs = glob([
        "ReactiveObjC/**/*.m",
    ]),
    deps = [ 
        "//Pods:ReactiveObjC_DTrace",
    ],
    exported_headers = glob([
        "ReactiveObjC/**/*.h",
        "$(location :ReactiveObjC_DTrace)/**/*.h"
    ]),
    frameworks = [
        "$PLATFORM_DIR/Developer/Library/Frameworks/Foundation.framework",
    ],
)