{"action":"created","comment":{"url":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments/60262384","id":60262384,"diff_hunk":"@@ -0,0 +1,161 @@\n+/*\n+ This source file is part of the Swift.org open source project\n+ \n+ Copyright 2015 - 2016 Apple Inc. and the Swift project authors\n+ Licensed under Apache License v2.0 with Runtime Library Exception\n+ \n+ See http://swift.org/LICENSE.txt for license information\n+ See http://swift.org/CONTRIBUTORS.txt for Swift project authors \n+*/\n+\n+import Utility\n+import func POSIX.getenv\n+\n+enum PkgConfigError: ErrorProtocol {\n+    case CouldNotFindConfigFile\n+}\n+\n+struct PkgConfig {\n+    static let searchPaths = [\"/usr/local/lib/pkgconfig\",\n+                              \"/usr/local/share/pkgconfig\",\n+                              \"/usr/lib/pkgconfig\",\n+                              \"/usr/share/pkgconfig\",\n+                              // FIXME: These should only be searched for linux?\n+                              \"/usr/lib/x86_64-linux-gnu/pkgconfig\",\n+                              \"/usr/local/lib/x86_64-linux-gnu/pkgconfig\",\n+                              ]\n+    \n+    let name: String\n+    let pcFile: String\n+    var cFlags = [String]()\n+    var libs = [String]()\n+    private var parser: PkgConfigParser\n+    \n+    init(name: String) throws {\n+        self.name = name\n+        self.pcFile = try PkgConfig.locatePCFile(name: name)\n+        parser = PkgConfigParser(pcFile: pcFile)\n+    }\n+    \n+    static var envSearchPaths: [String] {\n+        if let configPath = getenv(\"PKG_CONFIG_PATH\") {\n+            return configPath.characters.split(separator: \":\").map(String.init)\n+        }\n+        return []\n+    }\n+    \n+    static func locatePCFile(name: String) throws -> String {\n+        for path in (searchPaths + envSearchPaths) {\n+            let pcFile = Path.join(path, \"\\(name).pc\")\n+            if pcFile.isFile {\n+                return pcFile\n+            }\n+        }\n+        throw PkgConfigError.CouldNotFindConfigFile\n+    }\n+    \n+    mutating func load() throws {\n+        cFlags = [String]()\n+        libs = [String]()\n+        try parser.parse()\n+        if let cFlags = parser.cFlags {\n+            // FIXME: handle spaces in paths.\n+            self.cFlags += cFlags.characters.split(separator: \" \").map(String.init)\n+        }\n+        if let libs = parser.libs {\n+            // FIXME: handle spaces in paths.\n+            self.libs += libs.characters.split(separator: \" \").map(String.init)\n+        }\n+        \n+        if(parser.dependencies.isEmpty) {\n+            return\n+        }\n+        \n+        for dep in parser.dependencies {\n+            var pkg = try PkgConfig(name: dep)\n+            try pkg.load()\n+            self.cFlags += pkg.cFlags\n+            self.libs += pkg.libs\n+        }\n+    }\n+}\n+\n+private struct PkgConfigParser {\n+    let pcFile: String\n+    var variables = [String: String]()\n+    var dependencies = [String]()\n+    var cFlags: String?\n+    var libs: String?\n+    \n+    enum Token {\n+        case CFlats(String)\n+        case Libs(String)\n+        case Dependencies(String)\n+        case Variable(name: String, value: String)\n+    }\n+    \n+    init(pcFile: String) {\n+        self.pcFile = pcFile\n+    }\n+    \n+    mutating func parse() throws {\n+        let file = File(path: self.pcFile)\n+        for line in try file.enumerate() {\n+            if !line.characters.contains(\":\") && line.characters.contains(\"=\")  {\n+                let equalsIndex = line.characters.index(of: \"=\")!\n+                let name = line[line.startIndex..<equalsIndex]\n+                let value = line[equalsIndex.successor()..<line.endIndex]\n+                variables[name] = resolveVariables(value)\n+            } else if line.hasPrefix(\"Requires: \") {\n+                dependencies = parseDependencies(value(line: line))\n+            } else if line.hasPrefix(\"Libs: \") {\n+                libs = resolveVariables(value(line: line)).chomp()\n+            } else if line.hasPrefix(\"Cflags: \") {\n+                cFlags = resolveVariables( value(line: line)).chomp()\n+            }","path":"Sources/Build/PkgConfig.swift","position":115,"original_position":115,"commit_id":"2a434f425c9ce97863108dac7ac08bb2c8995560","original_commit_id":"2a434f425c9ce97863108dac7ac08bb2c8995560","user":{"login":"ddunbar","id":106625,"avatar_url":"https://avatars.githubusercontent.com/u/106625?v=3","gravatar_id":"","url":"https://api.github.com/users/ddunbar","html_url":"https://github.com/ddunbar","followers_url":"https://api.github.com/users/ddunbar/followers","following_url":"https://api.github.com/users/ddunbar/following{/other_user}","gists_url":"https://api.github.com/users/ddunbar/gists{/gist_id}","starred_url":"https://api.github.com/users/ddunbar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddunbar/subscriptions","organizations_url":"https://api.github.com/users/ddunbar/orgs","repos_url":"https://api.github.com/users/ddunbar/repos","events_url":"https://api.github.com/users/ddunbar/events{/privacy}","received_events_url":"https://api.github.com/users/ddunbar/received_events","type":"User","site_admin":false},"body":"Is there a complete list available? If so, we could just check if it is in the known complete list and ignore if not there. \r\n\r\nWe can at least partition into the following three cases, right?\r\n1. Variable assignment\r\n2. Key-value binding (Name: Value)\r\n3. Comment\r\n","created_at":"2016-04-19T16:17:36Z","updated_at":"2016-04-19T16:17:36Z","html_url":"https://github.com/apple/swift-package-manager/pull/257#discussion_r60262384","pull_request_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/257","_links":{"self":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments/60262384"},"html":{"href":"https://github.com/apple/swift-package-manager/pull/257#discussion_r60262384"},"pull_request":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/257"}}},"pull_request":{"url":"https://api.github.com/repos/apple/swift-package-manager/pulls/257","id":66737164,"html_url":"https://github.com/apple/swift-package-manager/pull/257","diff_url":"https://github.com/apple/swift-package-manager/pull/257.diff","patch_url":"https://github.com/apple/swift-package-manager/pull/257.patch","issue_url":"https://api.github.com/repos/apple/swift-package-manager/issues/257","number":257,"state":"closed","locked":false,"title":"pkgconfig System Module Search Paths","user":{"login":"aciidb0mb3r","id":4136295,"avatar_url":"https://avatars.githubusercontent.com/u/4136295?v=3","gravatar_id":"","url":"https://api.github.com/users/aciidb0mb3r","html_url":"https://github.com/aciidb0mb3r","followers_url":"https://api.github.com/users/aciidb0mb3r/followers","following_url":"https://api.github.com/users/aciidb0mb3r/following{/other_user}","gists_url":"https://api.github.com/users/aciidb0mb3r/gists{/gist_id}","starred_url":"https://api.github.com/users/aciidb0mb3r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aciidb0mb3r/subscriptions","organizations_url":"https://api.github.com/users/aciidb0mb3r/orgs","repos_url":"https://api.github.com/users/aciidb0mb3r/repos","events_url":"https://api.github.com/users/aciidb0mb3r/events{/privacy}","received_events_url":"https://api.github.com/users/aciidb0mb3r/received_events","type":"User","site_admin":false},"body":"This aims at implementing : https://github.com/apple/swift-evolution/blob/master/proposals/0063-swiftpm-system-module-search-paths.md\r\n\r\nTested with compiling GTK+3\r\n","created_at":"2016-04-16T12:50:00Z","updated_at":"2016-04-19T16:17:36Z","closed_at":"2016-04-18T20:49:37Z","merged_at":"2016-04-18T20:49:37Z","merge_commit_sha":"7bb14b22df8ef0c5b8d8814e5d2ed1e6733ac9b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/257/commits","review_comments_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/257/comments","review_comment_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apple/swift-package-manager/issues/257/comments","statuses_url":"https://api.github.com/repos/apple/swift-package-manager/statuses/2a434f425c9ce97863108dac7ac08bb2c8995560","head":{"label":"aciidb0mb3r:pkg-config","ref":"pkg-config","sha":"2a434f425c9ce97863108dac7ac08bb2c8995560","user":{"login":"aciidb0mb3r","id":4136295,"avatar_url":"https://avatars.githubusercontent.com/u/4136295?v=3","gravatar_id":"","url":"https://api.github.com/users/aciidb0mb3r","html_url":"https://github.com/aciidb0mb3r","followers_url":"https://api.github.com/users/aciidb0mb3r/followers","following_url":"https://api.github.com/users/aciidb0mb3r/following{/other_user}","gists_url":"https://api.github.com/users/aciidb0mb3r/gists{/gist_id}","starred_url":"https://api.github.com/users/aciidb0mb3r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aciidb0mb3r/subscriptions","organizations_url":"https://api.github.com/users/aciidb0mb3r/orgs","repos_url":"https://api.github.com/users/aciidb0mb3r/repos","events_url":"https://api.github.com/users/aciidb0mb3r/events{/privacy}","received_events_url":"https://api.github.com/users/aciidb0mb3r/received_events","type":"User","site_admin":false},"repo":{"id":47417816,"name":"swift-package-manager","full_name":"aciidb0mb3r/swift-package-manager","owner":{"login":"aciidb0mb3r","id":4136295,"avatar_url":"https://avatars.githubusercontent.com/u/4136295?v=3","gravatar_id":"","url":"https://api.github.com/users/aciidb0mb3r","html_url":"https://github.com/aciidb0mb3r","followers_url":"https://api.github.com/users/aciidb0mb3r/followers","following_url":"https://api.github.com/users/aciidb0mb3r/following{/other_user}","gists_url":"https://api.github.com/users/aciidb0mb3r/gists{/gist_id}","starred_url":"https://api.github.com/users/aciidb0mb3r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aciidb0mb3r/subscriptions","organizations_url":"https://api.github.com/users/aciidb0mb3r/orgs","repos_url":"https://api.github.com/users/aciidb0mb3r/repos","events_url":"https://api.github.com/users/aciidb0mb3r/events{/privacy}","received_events_url":"https://api.github.com/users/aciidb0mb3r/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aciidb0mb3r/swift-package-manager","description":"The Package Manager for the Swift Programming Language","fork":true,"url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager","forks_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/forks","keys_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/teams","hooks_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/hooks","issue_events_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/issues/events{/number}","events_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/events","assignees_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/assignees{/user}","branches_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/branches{/branch}","tags_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/tags","blobs_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/languages","stargazers_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/stargazers","contributors_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/contributors","subscribers_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/subscribers","subscription_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/subscription","commits_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/contents/{+path}","compare_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/merges","archive_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/downloads","issues_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/issues{/number}","pulls_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/labels{/name}","releases_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/releases{/id}","deployments_url":"https://api.github.com/repos/aciidb0mb3r/swift-package-manager/deployments","created_at":"2015-12-04T17:05:51Z","updated_at":"2016-02-04T13:02:44Z","pushed_at":"2016-04-18T17:10:43Z","git_url":"git://github.com/aciidb0mb3r/swift-package-manager.git","ssh_url":"git@github.com:aciidb0mb3r/swift-package-manager.git","clone_url":"https://github.com/aciidb0mb3r/swift-package-manager.git","svn_url":"https://github.com/aciidb0mb3r/swift-package-manager","homepage":"","size":1172,"stargazers_count":0,"watchers_count":0,"language":"Swift","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":"apple:master","ref":"master","sha":"b313d3ccfc062a59fdd2f3546e48cf74725de61a","user":{"login":"apple","id":10639145,"avatar_url":"https://avatars.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"repo":{"id":44840041,"name":"swift-package-manager","full_name":"apple/swift-package-manager","owner":{"login":"apple","id":10639145,"avatar_url":"https://avatars.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apple/swift-package-manager","description":"The Package Manager for the Swift Programming Language","fork":false,"url":"https://api.github.com/repos/apple/swift-package-manager","forks_url":"https://api.github.com/repos/apple/swift-package-manager/forks","keys_url":"https://api.github.com/repos/apple/swift-package-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apple/swift-package-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apple/swift-package-manager/teams","hooks_url":"https://api.github.com/repos/apple/swift-package-manager/hooks","issue_events_url":"https://api.github.com/repos/apple/swift-package-manager/issues/events{/number}","events_url":"https://api.github.com/repos/apple/swift-package-manager/events","assignees_url":"https://api.github.com/repos/apple/swift-package-manager/assignees{/user}","branches_url":"https://api.github.com/repos/apple/swift-package-manager/branches{/branch}","tags_url":"https://api.github.com/repos/apple/swift-package-manager/tags","blobs_url":"https://api.github.com/repos/apple/swift-package-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apple/swift-package-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apple/swift-package-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/apple/swift-package-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apple/swift-package-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/apple/swift-package-manager/languages","stargazers_url":"https://api.github.com/repos/apple/swift-package-manager/stargazers","contributors_url":"https://api.github.com/repos/apple/swift-package-manager/contributors","subscribers_url":"https://api.github.com/repos/apple/swift-package-manager/subscribers","subscription_url":"https://api.github.com/repos/apple/swift-package-manager/subscription","commits_url":"https://api.github.com/repos/apple/swift-package-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/apple/swift-package-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/apple/swift-package-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/apple/swift-package-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/apple/swift-package-manager/contents/{+path}","compare_url":"https://api.github.com/repos/apple/swift-package-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apple/swift-package-manager/merges","archive_url":"https://api.github.com/repos/apple/swift-package-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apple/swift-package-manager/downloads","issues_url":"https://api.github.com/repos/apple/swift-package-manager/issues{/number}","pulls_url":"https://api.github.com/repos/apple/swift-package-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/apple/swift-package-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/apple/swift-package-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apple/swift-package-manager/labels{/name}","releases_url":"https://api.github.com/repos/apple/swift-package-manager/releases{/id}","deployments_url":"https://api.github.com/repos/apple/swift-package-manager/deployments","created_at":"2015-10-23T21:41:12Z","updated_at":"2016-04-19T13:37:22Z","pushed_at":"2016-04-19T05:20:31Z","git_url":"git://github.com/apple/swift-package-manager.git","ssh_url":"git@github.com:apple/swift-package-manager.git","clone_url":"https://github.com/apple/swift-package-manager.git","svn_url":"https://github.com/apple/swift-package-manager","homepage":"","size":1353,"stargazers_count":3909,"watchers_count":3909,"language":"Swift","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":316,"mirror_url":null,"open_issues_count":13,"forks":316,"open_issues":13,"watchers":3909,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/257"},"html":{"href":"https://github.com/apple/swift-package-manager/pull/257"},"issue":{"href":"https://api.github.com/repos/apple/swift-package-manager/issues/257"},"comments":{"href":"https://api.github.com/repos/apple/swift-package-manager/issues/257/comments"},"review_comments":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/257/comments"},"review_comment":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/257/commits"},"statuses":{"href":"https://api.github.com/repos/apple/swift-package-manager/statuses/2a434f425c9ce97863108dac7ac08bb2c8995560"}}}}