| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 declare_args() { | 5 declare_args() { |
| 6 # By default, there is no go build tool, because go builds are not supported. | 6 # By default, there is no go build tool, because go builds are not supported. |
| 7 go_build_tool = "" | 7 go_build_tool = "" |
| 8 } | 8 } |
| 9 | 9 |
| 10 # Declare a go library. | 10 # Declare a go library. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 rebase_path(root_out_dir, root_build_dir), | 84 rebase_path(root_out_dir, root_build_dir), |
| 85 "-I" + rebase_path("//"), | 85 "-I" + rebase_path("//"), |
| 86 "-L" + rebase_path(target_out_dir) + " -l" + static_library_name + | 86 "-L" + rebase_path(target_out_dir) + " -l" + static_library_name + |
| 87 " -lstdc++ -lpthread -lm -lglib-2.0 -lrt", | 87 " -lstdc++ -lpthread -lm -lglib-2.0 -lrt", |
| 88 "test", | 88 "test", |
| 89 "-c", | 89 "-c", |
| 90 ] + rebase_path(invoker.sources, build_dir) | 90 ] + rebase_path(invoker.sources, build_dir) |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 # Declare a go binary target. |
| 95 # |
| 96 # The target generates a go executable, optionally linking against C code, |
| 97 # which is compiled into a static library and linked against Go. |
| 98 # |
| 99 # Only works on linux. |go_build_tool| must be set to the absolute path |
| 100 # of the go build tool. |
| 101 # |
| 102 # Variables |
| 103 # sources: list of top-level .go files to compile (required) |
| 104 # inputs: list of files that are input dependencies. Use this to |
| 105 # specify your imported .go files. These files will not be |
| 106 # specified in the command line to go build but they will cause |
| 107 # a re-compile if they are touched. (optional) |
| 108 # static_library_sources: list of C sources needed for the static library |
| 109 # (optional) |
| 110 # deps: dependencies (optional) |
| 111 template("go_binary") { |
| 112 assert(is_linux) |
| 113 assert(defined(invoker.sources)) |
| 114 assert(go_build_tool != "") |
| 115 |
| 116 static_library_name = target_name + "_static_library" |
| 117 |
| 118 static_library(static_library_name) { |
| 119 complete_static_lib = true |
| 120 |
| 121 if (defined(invoker.static_library_sources)) { |
| 122 sources = invoker.static_library_sources |
| 123 } |
| 124 if (defined(invoker.deps)) { |
| 125 deps = invoker.deps |
| 126 } |
| 127 } |
| 128 |
| 129 go_binary_name = target_name + "_go" |
| 130 action(go_binary_name) { |
| 131 deps = [ |
| 132 ":${static_library_name}", |
| 133 ] |
| 134 if (defined(invoker.deps)) { |
| 135 deps += invoker.deps |
| 136 } |
| 137 script = "//mojo/go/go.py" |
| 138 inputs = invoker.sources |
| 139 if (defined(invoker.inputs)) { |
| 140 inputs += invoker.inputs |
| 141 } |
| 142 outputs = [ |
| 143 "${target_out_dir}/${target_name}", |
| 144 ] |
| 145 |
| 146 # Since go build does not permit specifying an output directory or output |
| 147 # binary name, we create a temporary build directory, and the python |
| 148 # script will later identify the output, copy it to the target location, |
| 149 # and clean up the temporary build directory. |
| 150 # TODO(rudominer) Update the version of go in the Mojo repo and then |
| 151 # we will be able to use the -o flag instead. |
| 152 build_dir = "${target_out_dir}/${target_name}_build" |
| 153 args = [ |
| 154 "--", |
| 155 "${go_build_tool}", |
| 156 rebase_path(build_dir, root_build_dir), |
| 157 rebase_path(target_out_dir, root_build_dir) + "/${target_name}", |
| 158 rebase_path("//", root_build_dir), |
| 159 rebase_path(root_out_dir, root_build_dir), |
| 160 "-I" + rebase_path("//"), |
| 161 "-L" + rebase_path(target_out_dir) + " -l" + static_library_name + "", |
| 162 "build", |
| 163 ] |
| 164 args += rebase_path(invoker.sources, build_dir) |
| 165 } |
| 166 |
| 167 copy(target_name) { |
| 168 deps = [ |
| 169 ":${go_binary_name}", |
| 170 ] |
| 171 sources = [ |
| 172 "${target_out_dir}/${go_binary_name}", |
| 173 ] |
| 174 outputs = [ |
| 175 "${root_out_dir}/${target_name}", |
| 176 ] |
| 177 } |
| 178 } |
| 179 |
| 94 template("go_mojo_application") { | 180 template("go_mojo_application") { |
| 95 assert(is_android || is_linux) | 181 assert(is_android || is_linux) |
| 96 assert(defined(invoker.sources)) | 182 assert(defined(invoker.sources)) |
| 97 assert(go_build_tool != "") | 183 assert(go_build_tool != "") |
| 98 | 184 |
| 99 static_library_name = target_name + "_static_library" | 185 static_library_name = target_name + "_static_library" |
| 100 static_library(static_library_name) { | 186 static_library(static_library_name) { |
| 101 complete_static_lib = true | 187 complete_static_lib = true |
| 102 deps = [ | 188 deps = [ |
| 103 "//mojo/public/platform/native:system", | 189 "//mojo/public/platform/native:system", |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 ":${go_library_name}", | 233 ":${go_library_name}", |
| 148 ] | 234 ] |
| 149 sources = [ | 235 sources = [ |
| 150 "${target_out_dir}/${go_library_name}", | 236 "${target_out_dir}/${go_library_name}", |
| 151 ] | 237 ] |
| 152 outputs = [ | 238 outputs = [ |
| 153 "${root_out_dir}/${target_name}.mojo", | 239 "${root_out_dir}/${target_name}.mojo", |
| 154 ] | 240 ] |
| 155 } | 241 } |
| 156 } | 242 } |
| OLD | NEW |