|
| 1 | +# Copyright (c) 2020 Project CHIP Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import("//build_overrides/build.gni") |
| 16 | +import("//build_overrides/chip.gni") |
| 17 | +import("//build_overrides/tizen.gni") |
| 18 | + |
| 19 | +import("${build_root}/config/tizen/config.gni") |
| 20 | + |
| 21 | +tizen_manifest_parser = rebase_path("tizen_manifest_parser.py") |
| 22 | + |
| 23 | +template("tizen_sdk") { |
| 24 | + forward_variables_from(invoker, |
| 25 | + [ |
| 26 | + "project_build_dir", |
| 27 | + "project_app_name", |
| 28 | + ]) |
| 29 | + |
| 30 | + if (!defined(project_app_name)) { |
| 31 | + project_app_name = "tizen-app" |
| 32 | + } |
| 33 | + |
| 34 | + # Create a dummy project definition file, so the Tizen Studio CLI |
| 35 | + # will recognize our build directory as a Tizen project. |
| 36 | + write_file("${project_build_dir}/project_def.prop", |
| 37 | + [ |
| 38 | + "# Generated by the GN script. DO NOT EDIT!", |
| 39 | + "APPNAME = " + project_app_name, |
| 40 | + "type = app", |
| 41 | + ]) |
| 42 | + |
| 43 | + # Create a dummy project file, so the Tizen Studio CLI will not |
| 44 | + # complain about invalid XPath (this file is not used anyway...) |
| 45 | + write_file("${project_build_dir}/.project", |
| 46 | + [ |
| 47 | + "<!-- Generated by the build script. DO NOT EDIT! -->", |
| 48 | + "<projectDescription></projectDescription>", |
| 49 | + ]) |
| 50 | + |
| 51 | + action(target_name) { |
| 52 | + forward_variables_from(invoker, |
| 53 | + [ |
| 54 | + "deps", |
| 55 | + "outputs", |
| 56 | + ]) |
| 57 | + script = "${build_root}/gn_run_binary.py" |
| 58 | + args = [ "${tizen_sdk_root}/tools/ide/bin/tizen" ] + invoker.args |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +template("tizen_sdk_package") { |
| 63 | + # Output directory where packaging will occur. We need a separate directory |
| 64 | + # for this, because Tizen Studio CLI scans "res" (resources), "shared" and |
| 65 | + # "lib" directories for items to pack. In our case it could include in the |
| 66 | + # TPK package libraries available in ${root_build_dir}/lib directory. |
| 67 | + tizen_package_dir = "${root_build_dir}/package" |
| 68 | + tizen_package_out_dir = "${tizen_package_dir}/out" |
| 69 | + |
| 70 | + assert(defined(invoker.manifest), |
| 71 | + "It is required to specify Tizen `manifest` XML file.") |
| 72 | + assert(defined(invoker.sign_security_profile), |
| 73 | + "It is required to specify a `sign_security_profile` which " + |
| 74 | + "should be used for signing TPK package.") |
| 75 | + |
| 76 | + # Extract data from Tizen XML manifest. |
| 77 | + manifest = exec_script(tizen_manifest_parser, [ invoker.manifest ], "json") |
| 78 | + manifest_package = manifest["package"] |
| 79 | + manifest_apps = manifest["apps"] |
| 80 | + |
| 81 | + # Copy Tizen manifest from the source directory. |
| 82 | + copy("${target_name}:manifest") { |
| 83 | + sources = [ invoker.manifest ] |
| 84 | + outputs = [ "${tizen_package_dir}/{{source_file_part}}" ] |
| 85 | + deps = invoker.deps |
| 86 | + } |
| 87 | + |
| 88 | + # List of dependencies for Tizen Studio CLI packager. |
| 89 | + dependencies = [ ":${target_name}:manifest" ] |
| 90 | + |
| 91 | + # Copy executable(s) to temporary output directory. This action is required, |
| 92 | + # because Tizen Studio CLI expects particular directory layout - it is not |
| 93 | + # possible to specify input files manually. |
| 94 | + if (manifest_apps["service"] != "") { |
| 95 | + dependencies += [ ":${target_name}:app:service" ] |
| 96 | + copy("${target_name}:app:service") { |
| 97 | + sources = [ root_build_dir + "/" + manifest_apps["service"] ] |
| 98 | + outputs = [ "${tizen_package_out_dir}/{{source_file_part}}" ] |
| 99 | + deps = invoker.deps |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + tpk = manifest_package["name"] + "-" + manifest_package["version"] + ".tpk" |
| 104 | + tizen_sdk(target_name) { |
| 105 | + deps = invoker.deps + dependencies |
| 106 | + outputs = [ "${tizen_package_out_dir}/" + tpk ] |
| 107 | + project_build_dir = tizen_package_dir |
| 108 | + args = [ |
| 109 | + "package", |
| 110 | + "--type", |
| 111 | + "tpk", |
| 112 | + "--sign", |
| 113 | + invoker.sign_security_profile, |
| 114 | + "--", |
| 115 | + tizen_package_out_dir, |
| 116 | + ] |
| 117 | + } |
| 118 | +} |
0 commit comments