ashfurrow / Nimble-Snapshots

Nimble matchers for FBSnapshotTestCase.
https://medium.com/cocoaacademymag/unit-testing-uiview-with-nimble-snapshot-651a7c5a5e93
MIT License
318 stars 102 forks source link

Can't compile because "Nimble_Snapshots/Nimble_Snapshots-Swift.h" can't be found. CocoaPods 1.5 & static #176

Closed Machipla closed 5 years ago

Machipla commented 5 years ago

Hi there 😄

We're using CocoaPods version 1.5.3 and using this pod as a static library. The compiler complains when building, outputs:

"#import "Nimble_Snapshots/Nimble_Snapshots-Swift.h cannot be found in XCTestObservationCenter+CurrentTestCaseTracker.m"

Looking around, I saw that Quick has some similar problems with that: https://github.com/Quick/Quick/issues/780 And that there's a proposed workaround (by the CocoaPods team): https://github.com/Quick/Quick/pull/781

I think that maybe in XCTestObservationCenter+CurrentTestCaseTracker.m the import could be changed from this:

#import "XCTestObservationCenter+CurrentTestCaseTracker.h"
#import "Nimble_Snapshots/Nimble_Snapshots-Swift.h"

to this:

#import "XCTestObservationCenter+CurrentTestCaseTracker.h"
#if __has_include("Nimble_Snapshot-Swift.h")
    #import "Nimble_Snapshot-Swift.h"
#else
    #import <Nimble_Snapshot/Nimble_Snapshot-Swift.h>
#endif

I've just tried changing the import and it compiles, but I want to confirm with you this, just in case I'm missing something.

PS: For now I'm working around it with this hacky script (maybe it's useful to someone):

post_install do |installer|
    target = installer.pods_project.targets.find{|t| t.to_s == "Nimble-Snapshots"}
    compatibility_phase = target.build_phases.find { |ph| ph.display_name == 'Copy generated compatibility header' }
    if compatibility_phase
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_OBJC_INTERFACE_HEADER_NAME'] = "${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h"
        end

        compatibility_phase.shell_script = <<-SH.strip_heredoc
            COMPATIBILITY_HEADER_PATH="${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h"
            MODULE_MAP_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap"

            ditto "${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h" "${COMPATIBILITY_HEADER_PATH}"
            ditto "${PODS_ROOT}/Headers/Public/Nimble_Snapshots/Nimble-Snapshots.modulemap" "${MODULE_MAP_PATH}"
            ditto "${PODS_ROOT}/Headers/Public/Nimble_Snapshots/Nimble-Snapshots-umbrella.h" "${BUILT_PRODUCTS_DIR}"
            printf "module ${PRODUCT_MODULE_NAME}.Swift {  header \\\"${COMPATIBILITY_HEADER_PATH}\\\"  requires objc}" >> "${MODULE_MAP_PATH}"
        SH

        compatibility_phase.input_paths = ["${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h",
        "${PODS_ROOT}/Headers/Public/Nimble_Snapshots/Nimble-Snapshots.modulemap",
        "${PODS_ROOT}/Headers/Public/Nimble_Snapshots/Nimble-Snapshots-umbrella.h"]

        compatibility_phase.output_paths = ["${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap",
        "${BUILT_PRODUCTS_DIR}/Nimble-Snapshots-umbrella.h",
        "${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}-Swift.h"]
    end
end
Lascorbe commented 5 years ago

LGTM; could you make a PR with this change? Thanks @Machipla!

Machipla commented 5 years ago

Done, here it is now the PR (https://github.com/ashfurrow/Nimble-Snapshots/pull/177)