spotify / XCRemoteCache

Other
830 stars 53 forks source link

error: XCRemoteCache cannot be initialized with a consumer mode. Error: noArtifactsToReuse. #43

Closed GOKUXGOD closed 2 years ago

GOKUXGOD commented 2 years ago

Hi I am using the CocoaPods plugin to integrate the same, As suggested for debug mode I am using docker for local server.

While producer mode I am able to see logs in docker console that all artifacts are generated

Screenshot 2021-12-29 at 4 04 39 PM

But when I am switching to consumer mode I am getting the above error XCRemoteCache cannot be initialized with a consumer mode. Error: noArtifactsToReuse.

my .rcinfo file : primary_repo: XYZ.git cache_addresses: http://localhost:8080/cache/pods custom_fingerprint_envs: ARCHS primary_branch: master

My podfile: plugin 'cocoapods-xcremotecache' xcremotecache({ 'cache_addresses' => ['http://localhost:8080/cache/pods'], 'primary_repo' => 'XYZ.git', 'mode' => 'consumer', 'final_target' => 'Sample' })

few observations : When running pod install in consumer mode I can see that all fetch request are failing in docker container

Screenshot 2021-12-29 at 4 15 11 PM

More over I am checking the logs on console could make out much from them regarding the issue The ending logs says:

Network request failed with unsuccessful code 404 No artifacts available

polac24 commented 2 years ago

Hi! Some follow-up questions:

  1. When you build the producer mode, can you see if there is an extra build step for Sample target? I see that you set final_target=Sample so once Sample is built, it should mark the given sha as available.
  2. Do you build the producer from a sha that is part of your primary_brach (master)? From the log I can see that your producer tries to reuse artifacts for a commit ef5612 (as the first common with master). Did you build a producer for that sha?
GOKUXGOD commented 2 years ago

Thanks for your reply,

  1. Yes I can see an extra build step for sample
  2. Do you build the producer from a sha that is part of your primary_brach (master)? From the log I can see that your producer tries to reuse artifacts for a commit ef5612 (as the first common with master). Did you build a producer for that sha? -> Yes as you can in the producer logs arifcats are generated against this ef5612.

I have a single branch master on which I have generated artists for the 3rd commit ef5612, build succeeds and artefacts are available,

Now on consumer side I am on the same commit ef5612, I can see its not fetching for this particular commit but for commits before it. Since I have not generated artefacts for the commits before this one, this might be the reason for the error noArtifactsToReuse.

But then again I'm on the exact commit then why its not fetching for the same.

I will try by creating artefacts against each commit

polac24 commented 2 years ago

I looked again on your 2nd screenshot and the most important HEAD request is actually 200: cache/pods/marker/ef5612.... You get 404 for health requests, which shouldn't matter - this is only used if you have more than 2 remote cache replicas.

I recommend checking xcprepare logs right after pod install: log show --predicate 'sender BEGINSWITH "xc"' --style compact --info --debug -last 2m. Creating artifacts for all previous commits seems not required.

Here is my output for a successful integration:

log show --predicate 'sender BEGINSWITH "xc"' --style compact --info --debug -last 2m

Filtering the log data using "sender BEGINSWITH "xc""
Timestamp               Ty Process[PID:TID]
2021-12-30 07:42:09.710 I  xcprepare[7368:2ac1be] Checking HTTP file HEAD for http://localhost:8080/cache/nginx-health
2021-12-30 07:42:09.710 I  xcprepare[7368:2ac1be] Making request http://localhost:8080/cache/nginx-health
2021-12-30 07:42:09.807 I  xcprepare[7368:2ac1c5] Network request failed with unsuccessful code 404
2021-12-30 07:42:09.807 I  xcprepare[7368:2ac1be] Checking HTTP file HEAD for http://localhost:8080/cache/nginx-health
2021-12-30 07:42:09.807 I  xcprepare[7368:2ac1be] Making request http://localhost:8080/cache/nginx-health
2021-12-30 07:42:09.811 I  xcprepare[7368:2ac1c5] Network request failed with unsuccessful code 404
2021-12-30 07:42:09.811 I  xcprepare[7368:2ac1be] Checking HTTP file HEAD for http://localhost:8080/cache/nginx-health
2021-12-30 07:42:09.811 I  xcprepare[7368:2ac1be] Making request http://localhost:8080/cache/nginx-health
2021-12-30 07:42:09.812 I  xcprepare[7368:2ac1c1] Network request failed with unsuccessful code 404
2021-12-30 07:42:10.732 I  xcprepare[7368:2ac1be] Checking HTTP file HEAD for http://localhost:8080/cache/marker/ce06cac5f56049c23803afcbbe252cc4f68d6295-Debug-iphonesimulator-13C100-5
2021-12-30 07:42:10.732 I  xcprepare[7368:2ac1be] Making request http://localhost:8080/cache/marker/ce06cac5f56049c23803afcbbe252cc4f68d6295-Debug-iphonesimulator-13C100-5
2021-12-30 07:42:10.739 I  xcprepare[7368:2ac1be] ClangWrapperBuilder compiles file at file:///var/folders/zw/sbsyx6mj3llgqp2cy59vlxq40000gp/T/xccc.c.
2021-12-30 07:42:11.542 I  xcprepare[7368:2ac1be] Clang compilation output:
GOKUXGOD commented 2 years ago

Thanks finally I am able to integrate consumer mode, I have created a new project Sparta,

Podfile xcremotecache({ 'cache_addresses' => ['http://localhost:8080/cache/pods'], 'primary_repo' => 'sparta.git', 'mode' => 'producer', 'final_target' => 'Sparta' }) Just check these logs My 2nd commit is 082f9288d097fd0e721a292dbcb4614eb7f0979a all artefacts are generated successfully

Screenshot 2021-12-30 at 12 40 41 PM

For consumer mode pod install I get the following logs

2021-12-30 12:46:39.452 I xcprepare[16750:27ee4] Extra config override failed with missingConfigurationFile(user.rcinfo -- file:///Users/nitinupadhyay/Desktop/SpotifySample/Consumer/sparta/Sparta/). Skipping extra configuration 2021-12-30 12:46:40.757 I xcprepare[16750:27ee4] Checking HTTP file HEAD for http://localhost:8080/cache/pods/nginx-health 2021-12-30 12:46:40.757 I xcprepare[16750:27ee4] Making request http://localhost:8080/cache/pods/nginx-health 2021-12-30 12:46:40.785 I xcprepare[16750:27f36] Network request failed with unsuccessful code 404 2021-12-30 12:46:40.785 I xcprepare[16750:27ee4] Checking HTTP file HEAD for http://localhost:8080/cache/pods/nginx-health 2021-12-30 12:46:40.785 I xcprepare[16750:27ee4] Making request http://localhost:8080/cache/pods/nginx-health 2021-12-30 12:46:40.787 I xcprepare[16750:27f36] Network request failed with unsuccessful code 404 2021-12-30 12:46:40.788 I xcprepare[16750:27ee4] Checking HTTP file HEAD for http://localhost:8080/cache/pods/nginx-health 2021-12-30 12:46:40.788 I xcprepare[16750:27ee4] Making request http://localhost:8080/cache/pods/nginx-health 2021-12-30 12:46:40.790 I xcprepare[16750:27f34] Network request failed with unsuccessful code 404 2021-12-30 12:46:41.066 I xcprepare[16750:27ee4] Checking HTTP file HEAD for http://localhost:8080/cache/pods/marker/082f9288d097fd0e721a292dbcb4614eb7f0979a-Debug-iphonesimulator-12B45b-5 2021-12-30 12:46:41.066 I xcprepare[16750:27ee4] Making request http://localhost:8080/cache/pods/marker/082f9288d097fd0e721a292dbcb4614eb7f0979a-Debug-iphonesimulator-12B45b-5 2021-12-30 12:46:41.074 I xcprepare[16750:27ee4] ClangWrapperBuilder compiles file at file:///var/folders/9y/s1pcgsgx09j4txz3f1g8wg700000gq/T/xccc.c. 2021-12-30 12:46:41.537 I xcprepare[16750:27ee4] Clang compilation output:

My pod has 4 decencies and main app target is Sparta, which I also specified in the podfile I can see in the build logs that for all the dependencies Disabled remote cache for (Dependency1, Dependency2, and so on)

Screenshot 2021-12-30 at 1 04 48 PM

Only main app target Sparta is showiing Cached build for Sparta target

To verify the same I looked at docker it makes only get request for Sparta target

Screenshot 2021-12-30 at 12 58 32 PM

Am I doing something wrong, The only local change that I am doing is changing the mode in podfile to consumer

polac24 commented 2 years ago
GOKUXGOD commented 2 years ago

How do I verify if this configured correctly, I can see XCRC Prebuild against each of the pod dependency

Screenshot 2021-12-30 at 2 24 54 PM
polac24 commented 2 years ago

That looks OK. You should find something interesting in xcprebuild logs.

GOKUXGOD commented 2 years ago

The logs after clean build are

Timestamp Ty Process[PID:TID] 2021-12-30 14:32:00.237 E xcprebuild[33929:482f9] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.237 E xcprebuild[33934:4830b] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.237 E xcprebuild[33935:48311] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.237 E xcprebuild[33928:482f8] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.237 E xcprebuild[33932:48302] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.255 E xcprebuild[33937:48317] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.268 E xcprebuild[33938:48320] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:00.399 Df xcswiftc[33950:4834e] Fallbacking to compilation using swiftc. 2021-12-30 14:32:03.970 Df xcswiftc[34197:48676] Fallbacking to compilation using swiftc. 2021-12-30 14:32:13.431 E xcprebuild[34509:48c23] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:13.499 Df xcswiftc[34512:48c2b] Fallbacking to compilation using swiftc. 2021-12-30 14:32:13.601 E xcprebuild[34515:48c38] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:13.899 E xcprebuild[34538:48c6b] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:16.344 E xcprebuild[34612:48d76] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:16.427 Df xcswiftc[34615:48d7b] Fallbacking to compilation using swiftc. 2021-12-30 14:32:17.195 E xcprebuild[34636:48dc0] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:17.254 Df xcswiftc[34638:48dca] Fallbacking to compilation using swiftc. 2021-12-30 14:32:18.282 E xcprebuild[34667:48e0b] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:23.216 E xcprebuild[34741:48f4c] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:25.841 E xcprebuild[34763:48fd5] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:28.426 E xcprebuild[34819:490d5] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:28.431 E xcprebuild[34820:490d7] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:31.581 E xcprebuild[34894:49244] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:31.588 E xcprebuild[34896:4924a] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:31.588 E xcprebuild[34895:49248] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:38.547 E xcprebuild[35156:495c0] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:38.582 E xcprebuild[35157:495c4] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:32:55.076 E xcprebuild[35398:49ba4] Prebuild step was disabled for current commit: unavailable 2021-12-30 14:33:01.596 Df xcswiftc[35432:4a0b1] Fallbacking to compilation using swiftc. 2021-12-30 14:33:23.609 I xcprebuild[35515:4a3ce] Extra config override failed with missingConfigurationFile(user.rcinfo -- file:///Users/nitinupadhyay/Desktop/SpotifySample/Consumer/sparta/Sparta/). Skipping extra configuration 2021-12-30 14:33:23.625 E xcprebuild[35515:4a3ce] Couldn't verify if should disable RC for 5ca30d9f012b90efd380f7db9497b8d4eedf266f. 2021-12-30 14:33:23.640 I xcprebuild[35515:4a3ce] Downloading artifact to file:///Users/nitinupadhyay/Library/Developer/Xcode/DerivedData/Sparta-ekqsjwdajoxzlzajnncxrdxelazd/Build/Intermediates.noindex/Sparta.build/Debug-iphonesimulator/Sparta.build/xccache/92e206a2168ea2f4fdfb8139c7cca1a6.zip 2021-12-30 14:33:23.701 I xcprebuild[35515:4a3ce] Artifact unzipped to file:///Users/nitinupadhyay/Library/Developer/Xcode/DerivedData/Sparta-ekqsjwdajoxzlzajnncxrdxelazd/Build/Intermediates.noindex/Sparta.build/Debug-iphonesimulator/Sparta.build/xccache/92e206a2168ea2f4fdfb8139c7cca1a6 2021-12-30 14:33:23.798 I xcswiftc[35518:4a3db] Extra config override failed with missingConfigurationFile(user.rcinfo -- file:///Users/nitinupadhyay/Desktop/SpotifySample/Consumer/sparta/Sparta/). Skipping extra configuration 2021-12-30 14:33:23.826 I xcswiftc[35518:4a3db] Swiftc noop for x86_64-apple-ios14.2-simulator 2021-12-30 14:33:23.857 I xcld[35520:4a3de] Extra config override failed with missingConfigurationFile(user.rcinfo -- file:///Users/nitinupadhyay/Desktop/SpotifySample/Consumer/sparta/Sparta/). Skipping extra configuration 2021-12-30 14:33:30.483 I xcpostbuild[35998:4a7f5] Extra config override failed with missingConfigurationFile(user.rcinfo -- file:///Users/nitinupadhyay/Desktop/SpotifySample/Consumer/sparta/Sparta/). Skipping extra configuration

My .rcinfo/arc.rc path's are different in consumer and producer, do they need to same Producer -> /Users/Desktop/SpotifySample/Consumer/sparta/Sparta/.rc/arc.rc Consumer -> /Users/Desktop/SpotifySample/Producer/sparta/Sparta/.rc/arc.rc

is there any way to get more verbose logging

polac24 commented 2 years ago

I was able to reproduce your scenario locally. Here is my Podfile:

plugin 'cocoapods-xcremotecache'

xcremotecache({
    'cache_addresses' => ['http://localhost:8080/cache/pods'], 
    'primary_repo' => '.',
    'mode' => 'consumer',
    'final_target' => 'PPA'
})

target 'PPA' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for PPA
  pod 'SDWebImage'
end

I found a workaround though, provide absolute path of 'remote_commit_file' => '_SOME_ABSOLUTE_PATH_IN_A_PROJECT', e.g.:

xcremotecache({
    'cache_addresses' => ['http://localhost:8080/cache/pods'], 
    'primary_repo' => '.',
    'mode' => 'consumer',
    'final_target' => 'PPA',
    'remote_commit_file' => '/tmp/PPA/arc.rc'
})

Bug summary

The bug happens because xcprebuild looks for remote_commit_file relative to the .xcodeproj (e.g. PROJECT_ROOT/Pods/build/remote-cache/arc.rc for the Pods project) while the file is placed in PROJECT_ROOT/build/remote-cache/arc.rc

polac24 commented 2 years ago

The bug has been introduced a month ago with #22: https://github.com/spotify/XCRemoteCache/pull/22/commits/ba41e40bb00cb953e21a4a033252627e94f5fdf4#diff-e17c2614ae4580d99654216da364f421f11a566e60effc99722da837bb071f9cR59

GOKUXGOD commented 2 years ago

Thanks for insights and workaround, its working fine with it. Just to mention forPods project theremote_commit_file is placed at PROJECT_ROOT/.rc/arc.rc There is no build folder. However if we integrate in anon Pods project there is a build folder and the file can be found at PROJECT_ROOT/build/remote-cache/arc.rc

GOKUXGOD commented 2 years ago

is this included in release 0.3.1

polac24 commented 2 years ago

It is available in XCRemoteCache->v.0.3.2 and plugin xcremotecache-> 0.0.4

GOKUXGOD commented 2 years ago

working fine with plugin xcremotecache-> 0.0.4 Thank you for the support ✌️