Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong build order with nested dependencies #702

Merged
merged 5 commits into from Aug 24, 2015
Merged

Conversation

ikesyo
Copy link
Member

@ikesyo ikesyo commented Aug 21, 2015

Should fix #415.

The results in Cartfile.resolved with github "Carthage/Carthage" "master":

// before (Carthage 0.8)
github "robrix/Box" "1.2.2"
github "jdhealy/PrettyColors" "v2.0.0"
github "thoughtbot/Runes" "v2.0.0"
github "Carthage/ReactiveTask" "0.7-beta.3"
github "antitypical/Result" "0.4.4"
github "Carthage/Commandant" "0.6.1"
github "ReactiveCocoa/ReactiveCocoa" "v3.0-RC.1"
github "thoughtbot/Argo" "v1.0.4"
github "Carthage/Carthage" "aed38106616578f6269b5d72f4d2dbad58beceab"

// after
github "robrix/Box" "1.2.2"
github "jdhealy/PrettyColors" "v2.0.0"
github "thoughtbot/Runes" "v2.0.0"
github "antitypical/Result" "0.4.4"
github "Carthage/Commandant" "0.6.1"
github "ReactiveCocoa/ReactiveCocoa" "v3.0-RC.1"
github "Carthage/ReactiveTask" "0.7-beta.3"
github "thoughtbot/Argo" "v1.0.4"
github "Carthage/Carthage" "aed38106616578f6269b5d72f4d2dbad58beceab"

@ikesyo
Copy link
Member Author

ikesyo commented Aug 21, 2015

Oh, latest master aed3810 produces the after result without the fix, but I don't know why. 😲

@ikesyo
Copy link
Member Author

ikesyo commented Aug 21, 2015

I confirmed that the behavior is changed at 9d1a67f.

@ikesyo
Copy link
Member Author

ikesyo commented Aug 21, 2015

That was really affected by the evaluation order of the set, which is changed in 9d1a67f by the change of GitHubRepository.hashValue. In conclusion, the current ordering logic in orderedNodes is non-deterministic, on the other hand, the updated logic in this PR is deterministic IMHO.

}

for node in edge {
if let nodeDependencies = self.edges[node] where edgeDependsOn(nodeDependencies, dependsOn: dependsOn) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to handle the nesting in addNode. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better and simpler, I'll try it.

@mdiep
Copy link
Member

mdiep commented Aug 21, 2015

That was really affected by the evaluation order of the set, which is changed in 9d1a67f by the change of GitHubRepository.hashValue. In conclusion, the current ordering logic in orderedNodes is non-deterministic, on the other hand, the updated logic in this PR is deterministic IMHO.

I don't understand what you're saying here. Can you elaborate?

sorted isn't stable, so it's not going to be deterministic. But it definitely wasn't handling the nested dependencies before.

@ikesyo
Copy link
Member Author

ikesyo commented Aug 21, 2015

Thank you for the feedback,

I don't understand what you're saying here. Can you elaborate?

what I wanted to say is that the initial order of the collection affects a final result before:

# if we do `return sorted(Array(allNodes).sorted { $0.project.name < $1.project.name }) { lhs, rhs in`
github "robrix/Box" "1.2.2"
github "jdhealy/PrettyColors" "v2.0.0"
github "thoughtbot/Runes" "v2.0.0"
github "Carthage/Commandant" "0.6.1"
github "ReactiveCocoa/ReactiveCocoa" "v3.0-RC.1"
github "Carthage/ReactiveTask" "0.7-beta.3"
github "antitypical/Result" "0.4.4"
github "thoughtbot/Argo" "v1.0.4"
github "Carthage/Carthage" "aed38106616578f6269b5d72f4d2dbad58beceab"

# if we do `return sorted(Array(allNodes).sorted { $0.project.name > $1.project.name }) { lhs, rhs in`
github "robrix/Box" "1.2.2"
github "jdhealy/PrettyColors" "v2.0.0"
github "thoughtbot/Runes" "v2.0.0"
github "Carthage/ReactiveTask" "0.7-beta.3"
github "antitypical/Result" "0.4.4"
github "Carthage/Commandant" "0.6.1"
github "ReactiveCocoa/ReactiveCocoa" "v3.0-RC.1"
github "thoughtbot/Argo" "v1.0.4"
github "Carthage/Carthage" "aed38106616578f6269b5d72f4d2dbad58beceab"

sorted isn't stable, so it's not going to be deterministic. But it definitely wasn't handling the nested dependencies before.

This is more correct explanation about the situation. 👍

@ikesyo
Copy link
Member Author

ikesyo commented Aug 22, 2015

I've updated with the way as you proposed. 🙇

itsDependencies.insert(node)
edges[ancestor] = itsDependencies
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also check to see if the nodes in nodeSet are in edges?

What happens if you call:

addNode(Box, dependencyOf: ReactiveCocoa)
addNode(ReactiveCocoa, dependencyOf: ReactiveTask)

?

Or do we know that these will always be ordered in the other direction?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand correctly what you mean and your concern. Could you give me more details?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let resolver1 = Resolver()
resolver1.addNode(Box, dependencyOf: ReactiveCocoa)
resolver1.addNode(ReactiveCocoa, dependencyOf: ReactiveTask)

let resolver2 = Resolver()
resolver2.addNode(ReactiveCocoa, dependencyOf: ReactiveTask)
resolver2.addNode(Box, dependencyOf: ReactiveCocoa)

resolver1.edges == resolver2.edges // is this true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, appreciate your input. 🙏

resolver1.edges == resolver2.edges // is this true?

That was false, I added a fix for the case you pointed out here.

@mdiep
Copy link
Member

mdiep commented Aug 24, 2015

Thanks for fixing this! ✨

mdiep added a commit that referenced this pull request Aug 24, 2015
Fix wrong build order with nested dependencies
@mdiep mdiep merged commit a844d67 into master Aug 24, 2015
@mdiep mdiep deleted the fix-wrong-build-order branch August 24, 2015 11:59
@ikesyo
Copy link
Member Author

ikesyo commented Aug 24, 2015

Thanks for your review! 🎉

@memmons-ntst
Copy link

@ikesyo

I don't think this has been fixed yet. Here is top level cartfile:

github "ReactiveCocoa/ReactiveCocoa" ~> 4.0.0
github "thoughtbot/Argo" ~> 2.2
github "jverdi/JVFloatLabeledTextField" ~> 1.1.0
github "some/privateRepo" "swift-2"
git "https://another/privateRepo" "SDK_Swift2_1.0.13.1"

here is the cartfile.resolved:

github "thoughtbot/Argo" "v2.2.0"
github "some/privateRepo" "62e519d1317eae34a22051db9edb06467aef9893"
github "jverdi/JVFloatLabeledTextField" "1.1.0"
github "antitypical/Result" "0.6.0-beta.5"
git "https://another/privateRepo.git" "SDK_Swift2_1.0.13.1"
github "ReactiveCocoa/ReactiveCocoa" "v4.0.0-alpha.3"

And here is the cartfile for some/privateRepo:

github "thoughtbot/Argo" ~> 2.2
github "jverdi/JVFloatLabeledTextField" ~> 1.1.0

Note that some/privateRepo has a dependency on Argo and JVFloatLabeledTextField, which is why they appear before that repo in the top level cartfile. Yet some/privateRepo is the second item that gets built after Argo, which obviously fails since the dependencies haven't been built yet.

Also note that unless I include Argo and JVFloatLabeledTextField in the top level cart file, they will be completely disregarded, even though some/privateRepo does specify them in its cart file.

Maybe I'm misunderstanding what the fix was supposed to address? I'm currently using carthage version 0.10.0.

@dfclark
Copy link

dfclark commented May 6, 2016

I'm running carthage 0.16.2 on OS X 10.11.4 and am seeing this behavior. my cart file looks like this:
Dons-MBP:Project$ cat cartfile
github "CocoaLumberjack/CocoaLumberJack" ~> 2.0
github "Alamofire/Alamofire" ~> 3.3
github "SwiftyJSON/SwiftyJSON" ~> 2.3
git "git@gitserver.foobar.com:repositories/HMLoggerServicesFramework.git" "master"
But "carthage update --platform iOS" attempts to build HMLoggerServicesFramework before SwiftyJSON and a dependency causes this to fail.

The cartfile.resolved looks like this:
Dons-MBP:Project$ cat cartfile.resolved
github "Alamofire/Alamofire" "3.3.1"
github "CocoaLumberjack/CocoaLumberJack" "2.3.0"
git "git@gitserver.foobar.com:repositories/HMLoggerServicesFramework.git" "6ca53078005e7853f962f78e1ea90d3a59f4470b"
github "SwiftyJSON/SwiftyJSON" "2.3.3"

It tried the trick of editing cartfile.resolved, to this:
Dons-MBP:Project$ cat cartfile.resolved
github "SwiftyJSON/SwiftyJSON" "2.3.3"
github "Alamofire/Alamofire" "3.3.1"
github "CocoaLumberjack/CocoaLumberJack" "2.3.0"
git "git@gitserver.foobar.com:repositories/HMLoggerServicesFramework.git" "6ca53078005e7853f962f78e1ea90d3a59f4470b"

and then running the command "carthage build --platform iOS" but that made no difference, the build ordering stayed the same, and failed:

Dons-MBP:Project$ carthage build --platform iOS
*** xcodebuild output can be found in /var/folders/46/vq47kpz909jfv8j4vml8c63h0000gp/T/carthage-xcodebuild.p6ZV8p.log
*** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
*** Building scheme "CocoaLumberjackSwift-iOS" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjack" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjackSwift" in Lumberjack.xcworkspace
*** Building scheme "CocoaLumberjack-iOS" in Lumberjack.xcworkspace
*** Building scheme "HMLoggerServices" in HMLoggerServices.xcworkspace
** BUILD FAILED **

The following build commands failed:
CompileSwift normal arm64 /Users/dfclark/Dev/HoboHH/Project/Carthage/Checkouts/HMLoggerServicesFramework/HMLoggerServices/WebServiceManager.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/dfclark/Dev/HoboHH/Project/Carthage/Checkouts/HMLoggerServicesFramework/HMLoggerServices/WebServiceManager.swift:16:8: error: no such module 'SwiftyJSON'
A shell task (/usr/bin/xcrun xcodebuild -workspace /Users/dfclark/Dev/HoboHH/Project/Carthage/Checkouts/HMLoggerServicesFramework/HMLoggerServices.xcworkspace -scheme HMLoggerServices -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
** BUILD FAILED **

The following build commands failed:
CompileSwift normal arm64 /Users/dfclark/Dev/HoboHH/Project/Carthage/Checkouts/HMLoggerServicesFramework/HMLoggerServices/WebServiceManager.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

@mdiep
Copy link
Member

mdiep commented May 7, 2016

@dfclark Can you please open a new issue with the details of what you're seeing? Commenting on an old issue or pull request makes it very difficult to track issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong build order with nested dependencies
4 participants