OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 # The absolute path to the directory containing the mojo public SDK (i.e., the |
| 6 # directory containing mojo/public). The build files within the Mojo public |
| 7 # SDK use this variable to allow themselves to be parameterized by the location |
| 8 # of the public SDK within a client repo. |
| 9 mojo_root = get_path_info("../..", "abspath") |
| 10 |
| 11 # Takes as input a "source_set" that includes dependencies that are relative to |
| 12 # the parent directory of the Mojo public SDK (given in |mojo_sdk_deps|). |
| 13 # Generates a source_set that has the mojo_sdk_deps added as ordinary deps |
| 14 # rebased to the current directory. |
| 15 # By default, restricts the entries that are given in invoker.deps and |
| 16 # invoker.public_deps to be only within the same file and on a small set of |
| 17 # whitelisted external dependencies. This check can be elided by setting |
| 18 # restrict_external_dependencies to false in the invoker. DO NOT DO THIS in |
| 19 # //mojo/public. |
| 20 # |
| 21 # Example of a mojo_sdk_source_set: |
| 22 # |
| 23 # mojo_sdk_source_set("foo") { |
| 24 # sources = [ |
| 25 # "foo.h", |
| 26 # "foo.cc", |
| 27 # ] |
| 28 # |
| 29 # # Same-file deps are specified in the ordinary way. Any external |
| 30 # dependencies are specified the same way (although in general there should |
| 31 # be very few of these). |
| 32 # deps = [ |
| 33 # ":bar", |
| 34 # ] |
| 35 # |
| 36 # # Mojo SDK deps are specified relative to the containing directory of the |
| 37 # SDK via mojo_sdk_deps. |
| 38 # mojo_sdk_deps = [ |
| 39 # "mojo/public/cpp/bindings", |
| 40 # "mojo/public/cpp/environment", |
| 41 # "mojo/public/cpp/system", |
| 42 # ] |
| 43 # } |
| 44 # |
| 45 template("mojo_sdk_source_set") { |
| 46 source_set(target_name) { |
| 47 if (defined(invoker.visibility)) { |
| 48 visibility = invoker.visibility |
| 49 } else { |
| 50 visibility = [ "*" ] |
| 51 } |
| 52 if (defined(invoker.mojo_sdk_visibility)) { |
| 53 foreach(sdk_target, invoker.mojo_sdk_visibility) { |
| 54 # Check that the SDK target was not mistakenly given as an absolute |
| 55 # path. |
| 56 assert(get_path_info(sdk_target, "abspath") != sdk_target) |
| 57 visibility += [ rebase_path(sdk_target, ".", mojo_root) ] |
| 58 } |
| 59 } |
| 60 |
| 61 if (defined(invoker.testonly)) { |
| 62 testonly = invoker.testonly |
| 63 } |
| 64 |
| 65 if (defined(invoker.sources)) { |
| 66 sources = invoker.sources |
| 67 } |
| 68 |
| 69 if (defined(invoker.defines)) { |
| 70 defines = invoker.defines |
| 71 } |
| 72 |
| 73 public_configs = [ |
| 74 rebase_path("mojo/public/build/config:mojo_sdk", ".", mojo_root), |
| 75 ] |
| 76 if (defined(invoker.public_configs)) { |
| 77 public_configs += invoker.public_configs |
| 78 } |
| 79 |
| 80 if (defined(invoker.configs)) { |
| 81 configs += invoker.configs |
| 82 } |
| 83 |
| 84 if (defined(invoker.allow_circular_includes_from)) { |
| 85 allow_circular_includes_from = invoker.allow_circular_includes_from |
| 86 } |
| 87 |
| 88 if (defined(invoker.public_deps) || (defined(invoker.deps))) { |
| 89 restrict_external_deps = true |
| 90 if (defined(invoker.restrict_external_deps)) { |
| 91 restrict_external_deps = invoker.restrict_external_deps |
| 92 } |
| 93 } |
| 94 |
| 95 public_deps = [] |
| 96 if (defined(invoker.public_deps)) { |
| 97 foreach(dep, invoker.public_deps) { |
| 98 if (restrict_external_deps) { |
| 99 # The only deps that are not specified relative to the location of |
| 100 # the Mojo SDK should be on targets within the same file or on a |
| 101 # whitelisted set of external dependencies. |
| 102 assert(get_path_info(dep, "dir") == ".") |
| 103 } |
| 104 public_deps += [ dep ] |
| 105 } |
| 106 } |
| 107 if (defined(invoker.mojo_sdk_public_deps)) { |
| 108 foreach(sdk_dep, invoker.mojo_sdk_public_deps) { |
| 109 # Check that the SDK dep was not mistakenly given as an absolute path. |
| 110 assert(get_path_info(sdk_dep, "abspath") != sdk_dep) |
| 111 public_deps += [ rebase_path(sdk_dep, ".", mojo_root) ] |
| 112 } |
| 113 } |
| 114 |
| 115 deps = [] |
| 116 if (defined(invoker.deps)) { |
| 117 foreach(dep, invoker.deps) { |
| 118 if (restrict_external_deps) { |
| 119 # The only deps that are not specified relative to the location of |
| 120 # the Mojo SDK should be on targets within the same file or on a |
| 121 # whitelisted set of external dependencies. |
| 122 dep_dir = get_path_info(dep, "dir") |
| 123 assert(dep_dir == "." || dep == "//testing/gtest") |
| 124 } |
| 125 deps += [ dep ] |
| 126 } |
| 127 } |
| 128 if (defined(invoker.mojo_sdk_deps)) { |
| 129 foreach(sdk_dep, invoker.mojo_sdk_deps) { |
| 130 # Check that the SDK dep was not mistakenly given as an absolute path. |
| 131 assert(get_path_info(sdk_dep, "abspath") != sdk_dep) |
| 132 deps += [ rebase_path(sdk_dep, ".", mojo_root) ] |
| 133 } |
| 134 } |
| 135 } |
| 136 } |
OLD | NEW |