| OLD | NEW |
| 1 # GYP->GN Conversion Cookbook | 1 # GYP->GN Conversion Cookbook |
| 2 | 2 |
| 3 [TOC] | 3 [TOC] |
| 4 | 4 |
| 5 ## Targets | 5 ## Targets |
| 6 | 6 |
| 7 | *GYP* | *GN*
| | 7 | *GYP* | *GN*
| |
| 8 |:-------------------------------------------------|:---------------------------
------------------------| | 8 |:-------------------------------------------------|:---------------------------
------------------------| |
| 9 | `'type': 'static_library', 'name': 'foo',` | `static_library("foo") {` o
r `source_set("foo") {` | | 9 | `'type': 'static_library', 'name': 'foo',` | `static_library("foo") {` o
r `source_set("foo") {` | |
| 10 | `'type': 'shared_library', 'name': 'foo',` | `shared_library("foo") {`
| | 10 | `'type': 'shared_library', 'name': 'foo',` | `shared_library("foo") {`
| |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | `'conditions': [['chromeos==1', {` | `if (is_chromeos) {` | | 115 | `'conditions': [['chromeos==1', {` | `if (is_chromeos) {` | |
| 116 | 116 |
| 117 ## Typical sources and deps modifications | 117 ## Typical sources and deps modifications |
| 118 | 118 |
| 119 ### GYP | 119 ### GYP |
| 120 | 120 |
| 121 ``` | 121 ``` |
| 122 'sources': [ | 122 'sources': [ |
| 123 'a.cc', | 123 'a.cc', |
| 124 'b.cc', | 124 'b.cc', |
| 125 'c.cc', |
| 125 ], | 126 ], |
| 126 'dependencies': [ | 127 'dependencies': [ |
| 127 '<(DEPTH)/base/base.gyp:foo', | 128 '<(DEPTH)/base/base.gyp:foo', |
| 128 ], | 129 ], |
| 129 'conditions': [ | 130 'conditions': [ |
| 130 ['OS=="win"': { | 131 ['OS=="win"': { |
| 131 'sources!': [ | 132 'sources!': [ |
| 132 'a.cc', | 133 'a.cc', |
| 133 ], | 134 ], |
| 134 'sources': [ | 135 'sources': [ |
| 135 'foo.cc', | 136 'foo.cc', |
| 136 ], | 137 ], |
| 137 'dependencies': [ | 138 'dependencies': [ |
| 138 '<(DEPTH)/base/base.gyp:bar', | 139 '<(DEPTH)/base/base.gyp:bar', |
| 139 ], | 140 ], |
| 140 }, { | 141 }, { |
| 141 'sources/': [ | 142 'sources/': [ |
| 142 ['exclude', '^b\\.cc$'], | 143 ['exclude', '^b\\.cc$'], |
| 143 ], | 144 ], |
| 144 }], | 145 }], |
| 145 ], | 146 ], |
| 146 ``` | 147 ``` |
| 147 | 148 |
| 148 ### GN | 149 ### GN |
| 149 | 150 |
| 150 ``` | 151 ``` |
| 151 sources = [ | 152 sources = [ |
| 152 "a.cc", | 153 "c.cc", |
| 153 "b.cc", | |
| 154 ] | 154 ] |
| 155 deps = [ | 155 deps = [ |
| 156 "//base:foo", | 156 "//base:foo", |
| 157 ] | 157 ] |
| 158 | 158 |
| 159 if (is_win) { | 159 if (is_win) { |
| 160 sources -= [ "a.cc" ] | 160 sources += [ |
| 161 sources += [ "foo.cc" ] | 161 "b.cc", |
| 162 "foo.cc', |
| 163 ] |
| 162 deps += [ "//base:bar" ] | 164 deps += [ "//base:bar" ] |
| 163 } else { | 165 } else { |
| 164 sources -= [ "b.cc" ] | 166 sources += [ "a.cc" ] |
| 165 } | 167 } |
| 166 ``` | 168 ``` |
| 167 | 169 |
| 170 Note that in GN we prefer to only add files when needed, and don't add all of |
| 171 them at first only to remove them later like in gyp. |
| 172 |
| 168 ## Variable mappings | 173 ## Variable mappings |
| 169 | 174 |
| 170 ### Build configuration | 175 ### Build configuration |
| 171 | 176 |
| 172 Build configuration and feature flags are usually global in GYP. In GN | 177 Build configuration and feature flags are usually global in GYP. In GN |
| 173 we try to limit global variables and instead put variables used by only | 178 we try to limit global variables and instead put variables used by only |
| 174 some files into `.gni` files. These files are then imported into your | 179 some files into `.gni` files. These files are then imported into your |
| 175 buildfile by specifying at the top: | 180 buildfile by specifying at the top: |
| 176 | 181 |
| 177 ``` | 182 ``` |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 674 |
| 670 ``` | 675 ``` |
| 671 import("//mojo/public/tools/bindings/mojom.gni") | 676 import("//mojo/public/tools/bindings/mojom.gni") |
| 672 | 677 |
| 673 mojom("mojo_bindings") { | 678 mojom("mojo_bindings") { |
| 674 sources = [ | 679 sources = [ |
| 675 "foo.mojom", | 680 "foo.mojom", |
| 676 ] | 681 ] |
| 677 } | 682 } |
| 678 ``` | 683 ``` |
| OLD | NEW |