• 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/ohos.gni")
15
16gni_filepath = "//foundation/graphic/graphic_2d/utils/lex_yacc"
17
18template("lex_yacc") {
19  lex_name = invoker.lex
20  yacc_name = invoker.yacc
21  gen_flexlexer_name = "${target_name}_gen_flexlexer"
22  gen_lex_name = "${target_name}_gen_lex"
23  gen_yacc_name = "${target_name}_gen_yacc"
24  gen_lex_yacc_name = "${target_name}_gen_lex_yacc"
25  gen_config_name = "${target_name}_gen_config"
26
27  flexlexer_filename = "$root_gen_dir/$target_name/FlexLexer.h"
28  flexlexer_pathname = rebase_path(flexlexer_filename, root_build_dir)
29  action(gen_flexlexer_name) {
30    script = "$gni_filepath/gen_flexlexer_header.py"
31    inputs = [ script ]
32    outputs = [ flexlexer_filename ]
33    args = [
34      "--output",
35      flexlexer_pathname,
36    ]
37  }
38
39  lex_filename = "$root_gen_dir/$target_name/lexer.yy.cc"
40  lex_pathname = rebase_path(lex_filename, root_build_dir)
41  action(gen_lex_name) {
42    script = "$gni_filepath/gen_lex_cpp.py"
43    lex_inputfile = rebase_path(lex_name, root_build_dir)
44
45    inputs = [
46      script,
47      lex_name,
48    ]
49    outputs = [ lex_filename ]
50    args = [
51      "--input",
52      lex_inputfile,
53      "--output",
54      lex_pathname,
55    ]
56  }
57
58  yacc_filename = "$root_gen_dir/$target_name/parser.cpp"
59  yacc_pathname = rebase_path(yacc_filename, root_build_dir)
60  action(gen_yacc_name) {
61    script = "$gni_filepath/gen_yacc_cpp.py"
62    yacc_inputfile = rebase_path(yacc_name, root_build_dir)
63
64    inputs = [
65      script,
66      yacc_name,
67    ]
68    outputs = [ yacc_filename ]
69    args = [
70      "--input",
71      yacc_inputfile,
72      "--output",
73      yacc_pathname,
74    ]
75  }
76
77  config(gen_config_name) {
78    include_dirs = [
79      ".",
80      "$root_gen_dir/$target_name",
81    ]
82    cflags = [
83      "-Wno-unused-private-field",
84      "-Wno-header-hygiene",
85      "-Wno-implicit-fallthrough",
86    ]
87  }
88
89  ohos_static_library(gen_lex_yacc_name) {
90    sources = [
91      "$lex_filename",
92      "$yacc_filename",
93    ]
94
95    forward_variables_from(invoker,
96                           [
97                             "cflags",
98                             "include_dirs",
99                             "public_configs",
100                             "deps",
101                             "public_deps",
102                           ])
103
104    if (!defined(configs)) {
105      configs = []
106    }
107    if (defined(invoker.configs)) {
108      configs += invoker.configs
109    }
110
111    if (!defined(public_configs)) {
112      public_configs = []
113    }
114    public_configs += [
115      ":$gen_config_name",
116      "//build/config/compiler:rtti",
117      "//build/config/compiler:exceptions",
118    ]
119
120    deps = [
121      ":${gen_flexlexer_name}",
122      ":${gen_lex_name}",
123      ":${gen_yacc_name}",
124    ]
125  }
126
127  group(target_name) {
128    public_deps = [ ":${gen_lex_yacc_name}" ]
129  }
130}
131