{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/buck/pulls/comments/74355751","id":74355751,"diff_hunk":"@@ -16,60 +16,97 @@\n \n package com.facebook.buck.swift;\n \n+import static com.facebook.buck.swift.SwiftUtil.Constants.SWIFT_EXTENSION;\n+\n import com.facebook.buck.apple.AppleCxxPlatform;\n import com.facebook.buck.apple.ApplePlatforms;\n import com.facebook.buck.apple.MultiarchFileInfo;\n+import com.facebook.buck.cxx.CxxConstructorArg;\n import com.facebook.buck.cxx.CxxPlatform;\n+import com.facebook.buck.model.BuildTarget;\n import com.facebook.buck.model.BuildTargets;\n+import com.facebook.buck.model.Flavor;\n import com.facebook.buck.model.FlavorDomain;\n import com.facebook.buck.rules.BuildRule;\n import com.facebook.buck.rules.BuildRuleParams;\n import com.facebook.buck.rules.BuildRuleResolver;\n import com.facebook.buck.rules.SourcePath;\n import com.facebook.buck.rules.SourcePathResolver;\n-import com.facebook.buck.rules.TargetGraph;\n+import com.facebook.buck.rules.SourceWithFlags;\n import com.facebook.buck.rules.Tool;\n-import com.facebook.buck.rules.coercer.FrameworkPath;\n import com.facebook.buck.util.HumanReadableException;\n+import com.facebook.buck.util.MoreStrings;\n import com.google.common.base.Optional;\n import com.google.common.collect.ImmutableList;\n import com.google.common.collect.ImmutableSortedSet;\n \n public class SwiftDescriptions {\n-  /** Utility class: do not instantiate. */\n-  private SwiftDescriptions() {}\n+  /**\n+   * Utility class: do not instantiate.\n+   */\n+  private SwiftDescriptions() {\n+  }\n \n-  @SuppressWarnings(\"unused\")\n-  static BuildRule createSwiftModule(\n-      FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,\n+  public static <T extends CxxConstructorArg> Optional<BuildRule> generateCompanionSwiftBuildRule(\n+      BuildRuleParams parentParams,\n+      BuildRuleResolver buildRuleResolver,\n+      T args,\n       CxxPlatform defaultCxxPlatform,\n-      FlavorDomain<AppleCxxPlatform> appleCxxPlatformFlavorDomain,\n-      TargetGraph targetGraph,\n-      BuildRuleParams params,\n-      BuildRuleResolver resolver,\n-      CxxPlatform platform,\n-      String moduleName,\n-      ImmutableSortedSet<SourcePath> sources,\n-      ImmutableList<String> compilerFlags,\n-      ImmutableSortedSet<FrameworkPath> frameworks,\n-      ImmutableSortedSet<FrameworkPath> libraries,\n-      boolean enableObjcInterop) {\n+      FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,\n+      FlavorDomain<AppleCxxPlatform> platformFlavorsToAppleCxxPlatforms) {\n+    BuildTarget parentTarget = parentParams.getBuildTarget();\n+    CxxPlatform cxxPlatform = cxxPlatformFlavorDomain.getValue(parentTarget)\n+        .or(defaultCxxPlatform);\n+    // TODO(tho@uber.com) support version in swift flavor.\n+    BuildTarget swiftCompanionTarget = parentTarget.withFlavors(\n+        cxxPlatform.getFlavor(),\n+        Optional.of(\"Swift\").transform(Flavor.TO_FLAVOR).get());\n+    BuildRuleParams params = parentParams.copyWithBuildTarget(swiftCompanionTarget);\n+\n+    // check the cache\n+    Optional<BuildRule> rule = buildRuleResolver.getRuleOptional(swiftCompanionTarget);\n+    if (rule.isPresent()) {\n+      return rule;\n+    }\n+\n+    if (!args.srcs.isPresent() || args.srcs.get().isEmpty()) {\n+      return Optional.absent();\n+    }\n+\n+    ImmutableSortedSet.Builder<SourcePath> swiftSrcsBuilder = ImmutableSortedSet.naturalOrder();\n+    for (SourceWithFlags source : args.srcs.get()) {\n+      if (MoreStrings.endsWithIgnoreCase(source.getSourcePath().toString(), SWIFT_EXTENSION)) {\n+        swiftSrcsBuilder.add(source.getSourcePath());\n+      }\n+    }\n+    ImmutableSortedSet<SourcePath> swiftSrcs = swiftSrcsBuilder.build();\n+    if (swiftSrcs.isEmpty()) {\n+      return Optional.absent();\n+    }\n+\n     AppleCxxPlatform appleCxxPlatform = ApplePlatforms.getAppleCxxPlatformForBuildTarget(\n         cxxPlatformFlavorDomain,\n         defaultCxxPlatform,\n-        appleCxxPlatformFlavorDomain,\n+        platformFlavorsToAppleCxxPlatforms,\n         params.getBuildTarget(),\n         Optional.<MultiarchFileInfo>absent());\n     Optional<Tool> swiftCompiler = appleCxxPlatform.getSwift();\n     if (!swiftCompiler.isPresent()) {\n       throw new HumanReadableException(\"Platform %s is missing swift compiler\", appleCxxPlatform);\n     }\n-    return new SwiftCompile(\n-        params,\n-        new SourcePathResolver(resolver),\n+\n+    return Optional.<BuildRule>of(new SwiftLibrary(\n         swiftCompiler.get(),\n-        moduleName,\n-        BuildTargets.getGenPath(params.getProjectFilesystem(), params.getBuildTarget(), \"%s\"),\n-        sources);\n+        params,\n+        new SourcePathResolver(buildRuleResolver),\n+        ImmutableList.<BuildRule>of(),\n+        args.frameworks.get(),\n+        args.libraries.get(),\n+        platformFlavorsToAppleCxxPlatforms,\n+        BuildTargets.getGenPath(\n+            params.getProjectFilesystem(),\n+            swiftCompanionTarget.withAppendedFlavors(cxxPlatform.getFlavor()), \"%s\"),","path":"src/com/facebook/buck/swift/SwiftDescriptions.java","position":118,"original_position":118,"commit_id":"702a7d51397b29452e8d22b11a651a6e87991a1b","original_commit_id":"702a7d51397b29452e8d22b11a651a6e87991a1b","user":{"login":"ryu2","id":443244,"avatar_url":"https://avatars.githubusercontent.com/u/443244?v=3","gravatar_id":"","url":"https://api.github.com/users/ryu2","html_url":"https://github.com/ryu2","followers_url":"https://api.github.com/users/ryu2/followers","following_url":"https://api.github.com/users/ryu2/following{/other_user}","gists_url":"https://api.github.com/users/ryu2/gists{/gist_id}","starred_url":"https://api.github.com/users/ryu2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryu2/subscriptions","organizations_url":"https://api.github.com/users/ryu2/orgs","repos_url":"https://api.github.com/users/ryu2/repos","events_url":"https://api.github.com/users/ryu2/events{/privacy}","received_events_url":"https://api.github.com/users/ryu2/received_events","type":"User","site_admin":false},"body":"Don't need `.withAppendedFlavors` as you already have the platform flavor in `swiftCompanionTarget`.","created_at":"2016-08-11T00:29:22Z","updated_at":"2016-08-11T00:29:22Z","html_url":"https://github.com/facebook/buck/pull/831#discussion_r74355751","pull_request_url":"https://api.github.com/repos/facebook/buck/pulls/831","_links":{"self":{"href":"https://api.github.com/repos/facebook/buck/pulls/comments/74355751"},"html":{"href":"https://github.com/facebook/buck/pull/831#discussion_r74355751"},"pull_request":{"href":"https://api.github.com/repos/facebook/buck/pulls/831"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/buck/pulls/831","id":80127702,"html_url":"https://github.com/facebook/buck/pull/831","diff_url":"https://github.com/facebook/buck/pull/831.diff","patch_url":"https://github.com/facebook/buck/pull/831.patch","issue_url":"https://api.github.com/repos/facebook/buck/issues/831","number":831,"state":"open","locked":false,"title":"Allow using swift from objc","user":{"login":"nguyentruongtho","id":1457567,"avatar_url":"https://avatars.githubusercontent.com/u/1457567?v=3","gravatar_id":"","url":"https://api.github.com/users/nguyentruongtho","html_url":"https://github.com/nguyentruongtho","followers_url":"https://api.github.com/users/nguyentruongtho/followers","following_url":"https://api.github.com/users/nguyentruongtho/following{/other_user}","gists_url":"https://api.github.com/users/nguyentruongtho/gists{/gist_id}","starred_url":"https://api.github.com/users/nguyentruongtho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nguyentruongtho/subscriptions","organizations_url":"https://api.github.com/users/nguyentruongtho/orgs","repos_url":"https://api.github.com/users/nguyentruongtho/repos","events_url":"https://api.github.com/users/nguyentruongtho/events{/privacy}","received_events_url":"https://api.github.com/users/nguyentruongtho/received_events","type":"User","site_admin":false},"body":"In this PR:\r\n\r\n1. Create a companion swift library from a `apple_*` target which contains both swift and objc sources (see changes in `buck.py`).\r\n2. Generate objc header for `swift_library` target.\r\n3. Linking companion swift target as a library.\r\n\r\nA integration test for this feature is added as well, for more complex test, ref. [here](https://github.com/nguyentruongtho/buck_swift_test/tree/master/objc_mix_swift1).","created_at":"2016-08-04T18:35:35Z","updated_at":"2016-08-11T00:29:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9251fd058da7018242210b61f98f135b31cc091","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/facebook/buck/pulls/831/commits","review_comments_url":"https://api.github.com/repos/facebook/buck/pulls/831/comments","review_comment_url":"https://api.github.com/repos/facebook/buck/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/buck/issues/831/comments","statuses_url":"https://api.github.com/repos/facebook/buck/statuses/702a7d51397b29452e8d22b11a651a6e87991a1b","head":{"label":"nguyentruongtho:tho/objectivec_mix_swift","ref":"tho/objectivec_mix_swift","sha":"702a7d51397b29452e8d22b11a651a6e87991a1b","user":{"login":"nguyentruongtho","id":1457567,"avatar_url":"https://avatars.githubusercontent.com/u/1457567?v=3","gravatar_id":"","url":"https://api.github.com/users/nguyentruongtho","html_url":"https://github.com/nguyentruongtho","followers_url":"https://api.github.com/users/nguyentruongtho/followers","following_url":"https://api.github.com/users/nguyentruongtho/following{/other_user}","gists_url":"https://api.github.com/users/nguyentruongtho/gists{/gist_id}","starred_url":"https://api.github.com/users/nguyentruongtho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nguyentruongtho/subscriptions","organizations_url":"https://api.github.com/users/nguyentruongtho/orgs","repos_url":"https://api.github.com/users/nguyentruongtho/repos","events_url":"https://api.github.com/users/nguyentruongtho/events{/privacy}","received_events_url":"https://api.github.com/users/nguyentruongtho/received_events","type":"User","site_admin":false},"repo":{"id":56134505,"name":"buck","full_name":"nguyentruongtho/buck","owner":{"login":"nguyentruongtho","id":1457567,"avatar_url":"https://avatars.githubusercontent.com/u/1457567?v=3","gravatar_id":"","url":"https://api.github.com/users/nguyentruongtho","html_url":"https://github.com/nguyentruongtho","followers_url":"https://api.github.com/users/nguyentruongtho/followers","following_url":"https://api.github.com/users/nguyentruongtho/following{/other_user}","gists_url":"https://api.github.com/users/nguyentruongtho/gists{/gist_id}","starred_url":"https://api.github.com/users/nguyentruongtho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nguyentruongtho/subscriptions","organizations_url":"https://api.github.com/users/nguyentruongtho/orgs","repos_url":"https://api.github.com/users/nguyentruongtho/repos","events_url":"https://api.github.com/users/nguyentruongtho/events{/privacy}","received_events_url":"https://api.github.com/users/nguyentruongtho/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nguyentruongtho/buck","description":"A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.","fork":true,"url":"https://api.github.com/repos/nguyentruongtho/buck","forks_url":"https://api.github.com/repos/nguyentruongtho/buck/forks","keys_url":"https://api.github.com/repos/nguyentruongtho/buck/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nguyentruongtho/buck/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nguyentruongtho/buck/teams","hooks_url":"https://api.github.com/repos/nguyentruongtho/buck/hooks","issue_events_url":"https://api.github.com/repos/nguyentruongtho/buck/issues/events{/number}","events_url":"https://api.github.com/repos/nguyentruongtho/buck/events","assignees_url":"https://api.github.com/repos/nguyentruongtho/buck/assignees{/user}","branches_url":"https://api.github.com/repos/nguyentruongtho/buck/branches{/branch}","tags_url":"https://api.github.com/repos/nguyentruongtho/buck/tags","blobs_url":"https://api.github.com/repos/nguyentruongtho/buck/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nguyentruongtho/buck/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nguyentruongtho/buck/git/refs{/sha}","trees_url":"https://api.github.com/repos/nguyentruongtho/buck/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nguyentruongtho/buck/statuses/{sha}","languages_url":"https://api.github.com/repos/nguyentruongtho/buck/languages","stargazers_url":"https://api.github.com/repos/nguyentruongtho/buck/stargazers","contributors_url":"https://api.github.com/repos/nguyentruongtho/buck/contributors","subscribers_url":"https://api.github.com/repos/nguyentruongtho/buck/subscribers","subscription_url":"https://api.github.com/repos/nguyentruongtho/buck/subscription","commits_url":"https://api.github.com/repos/nguyentruongtho/buck/commits{/sha}","git_commits_url":"https://api.github.com/repos/nguyentruongtho/buck/git/commits{/sha}","comments_url":"https://api.github.com/repos/nguyentruongtho/buck/comments{/number}","issue_comment_url":"https://api.github.com/repos/nguyentruongtho/buck/issues/comments{/number}","contents_url":"https://api.github.com/repos/nguyentruongtho/buck/contents/{+path}","compare_url":"https://api.github.com/repos/nguyentruongtho/buck/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nguyentruongtho/buck/merges","archive_url":"https://api.github.com/repos/nguyentruongtho/buck/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nguyentruongtho/buck/downloads","issues_url":"https://api.github.com/repos/nguyentruongtho/buck/issues{/number}","pulls_url":"https://api.github.com/repos/nguyentruongtho/buck/pulls{/number}","milestones_url":"https://api.github.com/repos/nguyentruongtho/buck/milestones{/number}","notifications_url":"https://api.github.com/repos/nguyentruongtho/buck/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nguyentruongtho/buck/labels{/name}","releases_url":"https://api.github.com/repos/nguyentruongtho/buck/releases{/id}","deployments_url":"https://api.github.com/repos/nguyentruongtho/buck/deployments","created_at":"2016-04-13T08:28:43Z","updated_at":"2016-04-13T08:28:54Z","pushed_at":"2016-08-10T14:46:19Z","git_url":"git://github.com/nguyentruongtho/buck.git","ssh_url":"git@github.com:nguyentruongtho/buck.git","clone_url":"https://github.com/nguyentruongtho/buck.git","svn_url":"https://github.com/nguyentruongtho/buck","homepage":"https://buckbuild.com","size":404253,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"2f5a90b3ea96184b1b73104ab9f0328400c68c0b","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":9504214,"name":"buck","full_name":"facebook/buck","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/buck","description":"A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.","fork":false,"url":"https://api.github.com/repos/facebook/buck","forks_url":"https://api.github.com/repos/facebook/buck/forks","keys_url":"https://api.github.com/repos/facebook/buck/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/buck/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/buck/teams","hooks_url":"https://api.github.com/repos/facebook/buck/hooks","issue_events_url":"https://api.github.com/repos/facebook/buck/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/buck/events","assignees_url":"https://api.github.com/repos/facebook/buck/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/buck/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/buck/tags","blobs_url":"https://api.github.com/repos/facebook/buck/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/buck/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/buck/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/buck/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/buck/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/buck/languages","stargazers_url":"https://api.github.com/repos/facebook/buck/stargazers","contributors_url":"https://api.github.com/repos/facebook/buck/contributors","subscribers_url":"https://api.github.com/repos/facebook/buck/subscribers","subscription_url":"https://api.github.com/repos/facebook/buck/subscription","commits_url":"https://api.github.com/repos/facebook/buck/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/buck/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/buck/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/buck/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/buck/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/buck/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/buck/merges","archive_url":"https://api.github.com/repos/facebook/buck/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/buck/downloads","issues_url":"https://api.github.com/repos/facebook/buck/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/buck/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/buck/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/buck/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/buck/labels{/name}","releases_url":"https://api.github.com/repos/facebook/buck/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/buck/deployments","created_at":"2013-04-17T18:12:18Z","updated_at":"2016-08-10T15:17:11Z","pushed_at":"2016-08-11T00:27:01Z","git_url":"git://github.com/facebook/buck.git","ssh_url":"git@github.com:facebook/buck.git","clone_url":"https://github.com/facebook/buck.git","svn_url":"https://github.com/facebook/buck","homepage":"https://buckbuild.com","size":436282,"stargazers_count":2902,"watchers_count":2902,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":497,"mirror_url":null,"open_issues_count":158,"forks":497,"open_issues":158,"watchers":2902,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/buck/pulls/831"},"html":{"href":"https://github.com/facebook/buck/pull/831"},"issue":{"href":"https://api.github.com/repos/facebook/buck/issues/831"},"comments":{"href":"https://api.github.com/repos/facebook/buck/issues/831/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/buck/pulls/831/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/buck/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/buck/pulls/831/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/buck/statuses/702a7d51397b29452e8d22b11a651a6e87991a1b"}}}}
{"actor":{"display_login":"ryu2"}}