| # Copyright 2020 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This file builds the AT command library and tests. It has several steps. |
| # |
| # 1. Building the at_command_gen tool is an external depedency, defined |
| # in codegen/BUILD.gn |
| # |
| # 2. Once built, the at_command_gen tool is used to build generated/types.rs |
| # and generated/translate.rs into $target_gen_dir. |
| # |
| # 3. The other source files are copied into $target_gen_dir. |
| # |
| # 4. Ether the at-commands library or the tests are built from the the copied |
| # and generated files. |
| |
| import("//build/compiled_action.gni") |
| import("//build/drivers.gni") |
| import("//build/rust/rustc_library.gni") |
| |
| # Generate the rust sources using the code generator |
| compiled_action("generate_sources") { |
| tool = "//src/connectivity/lib/at-commands/codegen:" |
| tool_output_name = "at_command_gen" |
| sources = [ |
| "definitions/example1.at", |
| "definitions/example2.at", |
| "definitions/hfp.at", |
| ] |
| output_dir = "$target_gen_dir/src/generated/" |
| output_types = output_dir + "types.rs" |
| output_translate = output_dir + "translate.rs" |
| outputs = [ |
| output_types, |
| output_translate, |
| ] |
| args = [ |
| "--quiet", |
| "--output-types", |
| rebase_path(output_types, root_build_dir), |
| "--output-translate", |
| rebase_path(output_translate, root_build_dir), |
| ] |
| foreach(input, rebase_path(sources, root_build_dir)) { |
| args += [ "--input" ] + [ input ] |
| } |
| } |
| |
| # Copy existing rust source to the generated source directory |
| copy("copy_sources") { |
| sources = [ |
| "src/command_generated_tests.rs", |
| "src/lib.rs", |
| "src/lowlevel/arguments.rs", |
| "src/lowlevel/command.rs", |
| "src/lowlevel/command_tests.rs", |
| "src/lowlevel/response.rs", |
| "src/lowlevel/response_tests.rs", |
| "src/lowlevel/write_to.rs", |
| "src/parser/arguments_parser.rs", |
| "src/parser/command_grammar.rs", |
| "src/parser/command_parser.rs", |
| "src/parser/command_parser_tests.rs", |
| "src/parser/common.rs", |
| "src/parser/response_grammar.rs", |
| "src/parser/response_parser.rs", |
| "src/parser/response_parser_tests.rs", |
| "src/response.rs", |
| "src/response_generated_tests.rs", |
| "src/serde.rs", |
| "src/serde_tests.rs", |
| "src/tests.rs", |
| "src/translate_response.rs", |
| "src/translate_util.rs", |
| ] |
| outputs = [ "$target_gen_dir/{{source_target_relative}}" ] |
| } |
| |
| # Build the at command library from the generated sources |
| rustc_library("lib") { |
| name = "at_commands" |
| edition = "2018" |
| deps = [ |
| "//third_party/rust_crates:num-derive", |
| "//third_party/rust_crates:num-traits", |
| "//third_party/rust_crates:pest", |
| "//third_party/rust_crates:pest_derive", |
| "//third_party/rust_crates:thiserror", |
| ] |
| non_rust_deps = [ |
| ":copy_sources", |
| ":generate_sources", |
| ] |
| source_root = "$target_gen_dir/src/lib.rs" |
| sources = [ |
| "$target_gen_dir/src/generated/translate.rs", |
| "$target_gen_dir/src/generated/types.rs", |
| "$target_gen_dir/src/lib.rs", |
| "$target_gen_dir/src/lowlevel/arguments.rs", |
| "$target_gen_dir/src/lowlevel/command.rs", |
| "$target_gen_dir/src/lowlevel/response.rs", |
| "$target_gen_dir/src/lowlevel/write_to.rs", |
| "$target_gen_dir/src/parser/arguments_parser.rs", |
| "$target_gen_dir/src/parser/command_grammar.rs", |
| "$target_gen_dir/src/parser/command_parser.rs", |
| "$target_gen_dir/src/parser/common.rs", |
| "$target_gen_dir/src/parser/response_grammar.rs", |
| "$target_gen_dir/src/parser/response_parser.rs", |
| "$target_gen_dir/src/response.rs", |
| "$target_gen_dir/src/serde.rs", |
| "$target_gen_dir/src/translate_response.rs", |
| "$target_gen_dir/src/translate_util.rs", |
| ] |
| |
| configs -= [ "//build/config/rust:allow_unused_results" ] |
| } |
| |
| # Root target |
| group("at-commands") { |
| public_deps = [ ":lib" ] |
| } |
| |
| # Tests |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":lib_tests($host_toolchain)", |
| "codegen:tests", |
| ] |
| } |
| |
| # Build the at command tests from the generated sources |
| rustc_test("lib_tests") { |
| edition = "2018" |
| deps = [ |
| "//third_party/rust_crates:assert_matches", |
| "//third_party/rust_crates:num-derive", |
| "//third_party/rust_crates:num-traits", |
| "//third_party/rust_crates:pest", |
| "//third_party/rust_crates:pest_derive", |
| "//third_party/rust_crates:thiserror", |
| ] |
| non_rust_deps = [ |
| ":copy_sources", |
| ":generate_sources", |
| ] |
| source_root = "$target_gen_dir/src/tests.rs" |
| sources = [ |
| "$target_gen_dir/src/command_generated_tests.rs", |
| "$target_gen_dir/src/generated/translate.rs", |
| "$target_gen_dir/src/generated/types.rs", |
| "$target_gen_dir/src/lowlevel/arguments.rs", |
| "$target_gen_dir/src/lowlevel/command.rs", |
| "$target_gen_dir/src/lowlevel/command_tests.rs", |
| "$target_gen_dir/src/lowlevel/response.rs", |
| "$target_gen_dir/src/lowlevel/response_tests.rs", |
| "$target_gen_dir/src/lowlevel/write_to.rs", |
| "$target_gen_dir/src/parser/arguments_parser.rs", |
| "$target_gen_dir/src/parser/command_grammar.rs", |
| "$target_gen_dir/src/parser/command_parser.rs", |
| "$target_gen_dir/src/parser/command_parser_tests.rs", |
| "$target_gen_dir/src/parser/common.rs", |
| "$target_gen_dir/src/parser/response_grammar.rs", |
| "$target_gen_dir/src/parser/response_parser.rs", |
| "$target_gen_dir/src/parser/response_parser_tests.rs", |
| "$target_gen_dir/src/response.rs", |
| "$target_gen_dir/src/response_generated_tests.rs", |
| "$target_gen_dir/src/serde.rs", |
| "$target_gen_dir/src/serde_tests.rs", |
| "$target_gen_dir/src/tests.rs", |
| "$target_gen_dir/src/translate_response.rs", |
| "$target_gen_dir/src/translate_util.rs", |
| ] |
| |
| configs -= [ "//build/config/rust:allow_unused_results" ] |
| } |