• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/config/python.gni")
15import("//build/ohos/build_var.gni")
16import("//build/ohos/notice/notice.gni")
17import("//build/version.gni")
18
19sdk_base_build_gn = "//build/ohos/sdk/BUILD.gn"
20generated_files_dir = get_path_info(sdk_base_build_gn, "gen_dir")
21generated_sdk_module_install_paths =
22    "${generated_files_dir}/ohos_sdk_install_paths.json"
23
24sdk_system_windows = "windows"
25sdk_system_linux = "linux"
26sdk_system_darwin = "darwin"
27
28ohos_sdk_out_dir = "$product_output_dir/ohos-sdk"
29ohos_sdk_copy_dir = "$root_build_dir/ohos-sdk"
30
31sdk_toolchains = {
32  linux = "//build/toolchain/linux:clang_x64"
33  windows = "//build/toolchain/mingw:mingw_x86_64"
34  if (host_cpu == "arm64") {
35    darwin = "//build/toolchain/mac:clang_arm64"
36  } else {
37    darwin = "//build/toolchain/mac:clang_x64"
38  }
39}
40
41if (host_cpu == "arm64") {
42  arch = "arm64"
43} else {
44  arch = "x64"
45}
46
47if (host_os == "mac") {
48  sdk_systems = [ sdk_system_darwin ]
49} else {
50  sdk_systems = [
51    sdk_system_windows,
52    sdk_system_linux,
53  ]
54}
55
56template("copy_and_archive") {
57  assert(defined(invoker.dest_dir))
58  assert(defined(invoker.sdk_system))
59  assert(defined(invoker.sdk_type))
60  assert(defined(invoker.sdk_modules_desc_file))
61  forward_variables_from(invoker, [ "testonly" ])
62
63  action_with_pydeps(target_name) {
64    deps = []
65    if (defined(invoker.deps)) {
66      deps += invoker.deps
67    }
68
69    script = "//build/ohos/sdk/copy_sdk_modules.py"
70    depfile = "$target_gen_dir/$target_name.d"
71
72    _sdk_output_archive =
73        "$ohos_sdk_out_dir/${invoker.sdk_system}/${invoker.zipfile_name}"
74    _notice_output_archive = "${sdk_notice_archive_dir}/${invoker.sdk_system}-${invoker.sdk_type}.zip"
75    outputs = [
76      _sdk_output_archive,
77      _notice_output_archive,
78    ]
79
80    args = [
81      "--sdk-modules-desc-file",
82      rebase_path(invoker.sdk_modules_desc_file, root_build_dir),
83      "--sdk-archive-paths-file",
84      rebase_path(generated_sdk_module_install_paths, root_build_dir),
85      "--dest-dir",
86      rebase_path(invoker.dest_dir, root_build_dir),
87      "--sdk-output-archive",
88      rebase_path(_sdk_output_archive, root_build_dir),
89      "--notice-output-archive",
90      rebase_path(_notice_output_archive, root_build_dir),
91      "--depfile",
92      rebase_path(depfile, root_build_dir),
93      "--archive-dir",
94      rebase_path("${invoker.dest_dir}/${invoker.sdk_type}", root_build_dir),
95    ]
96
97    if (defined(invoker.zip_prefix_path)) {
98      args += [
99        "--zip-prefix-path",
100        invoker.zip_prefix_path,
101      ]
102    }
103  }
104}
105
106template("make_sdk_modules") {
107  assert(defined(invoker.zipfile_name))
108  assert(defined(invoker.sdk_modules))
109  assert(defined(invoker.sdk_toolchain))
110  assert(defined(invoker.sdk_type))
111  assert(defined(invoker.sdk_system))
112
113  if (invoker.sdk_modules == []) {
114    not_needed(invoker, [ "sdk_toolchain" ])
115  }
116  copy_and_archive(target_name) {
117    forward_variables_from(invoker,
118                           [
119                             "testonly",
120                             "sdk_system",
121                             "sdk_type",
122                             "zipfile_name",
123                           ])
124    _sdk_modules = []
125    _sdk_module_infos = []
126
127    foreach(_label, invoker.sdk_modules) {
128      _target_label = get_label_info(_label, "label_no_toolchain")
129      sources = [ _target_label ]
130      if (sources == []) {
131        _sdk_modules += [ _target_label ]
132      } else {
133        _sdk_modules += [ "${_target_label}(${invoker.sdk_toolchain})" ]
134      }
135      sources = []
136      set_sources_assignment_filter([])
137    }
138    not_needed(invoker, [ "sdk_toolchain" ])
139
140    foreach(_label, _sdk_modules) {
141      _module_info_file = get_label_info(_label, "target_out_dir") + "/" +
142                          get_label_info(_label, "name") + "_module_info.json"
143      _sdk_module_infos += [
144        {
145          label = get_label_info(_label, "label_no_toolchain")
146          module_info_file = rebase_path(_module_info_file, root_build_dir)
147        },
148      ]
149    }
150    sdk_modules_desc_file = "${target_gen_dir}/${target_name}_sdk_modules.json"
151    write_file(sdk_modules_desc_file, _sdk_module_infos, "json")
152
153    deps = _sdk_modules
154    if (defined(invoker.deps)) {
155      deps += invoker.deps
156    }
157    dest_dir = "${ohos_sdk_copy_dir}/${sdk_system}"
158    zip_prefix_path = "${invoker.sdk_type}"
159  }
160}
161
162template("make_linux_sdk_modules") {
163  make_sdk_modules(target_name) {
164    forward_variables_from(invoker,
165                           [
166                             "testonly",
167                             "zipfile_name",
168                             "sdk_modules",
169                             "sdk_type",
170                             "deps",
171                           ])
172    sdk_toolchain = sdk_toolchains.linux
173    sdk_system = sdk_system_linux
174  }
175}
176
177template("make_windows_sdk_modules") {
178  make_sdk_modules(target_name) {
179    forward_variables_from(invoker,
180                           [
181                             "testonly",
182                             "zipfile_name",
183                             "sdk_modules",
184                             "sdk_type",
185                             "deps",
186                           ])
187    sdk_toolchain = sdk_toolchains.windows
188    sdk_system = sdk_system_windows
189  }
190}
191
192template("make_darwin_sdk_modules") {
193  make_sdk_modules(target_name) {
194    forward_variables_from(invoker,
195                           [
196                             "testonly",
197                             "zipfile_name",
198                             "sdk_modules",
199                             "sdk_type",
200                             "deps",
201                           ])
202    sdk_toolchain = sdk_toolchains.darwin
203    sdk_system = sdk_system_darwin
204  }
205}
206