# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

gyp_file = "gn.gyp"
external = true

# Not defined when doing a GYP build, this lets the code key off of GN-specific
# features (the last change target). This can be removed when the last change
# target is supported by the GN->GYP converter (see is_gyp conditional for that
# below).
if (!is_gyp) {
  defines = [ "GN_BUILD" ]
}

static_library("gn_lib") {
  sources = [
    "args.cc",
    "args.h",
    "binary_target_generator.cc",
    "binary_target_generator.h",
    "build_settings.cc",
    "build_settings.h",
    "builder.cc",
    "builder.h",
    "builder_record.cc",
    "builder_record.h",
    "command_args.cc",
    "command_desc.cc",
    "command_gen.cc",
    "command_gyp.cc",
    "command_help.cc",
    "command_refs.cc",
    "commands.cc",
    "commands.h",
    "config.cc",
    "config.h",
    "config_values.cc",
    "config_values.h",
    "config_values_extractors.cc",
    "config_values_extractors.h",
    "config_values_generator.cc",
    "config_values_generator.h",
    "copy_target_generator.cc",
    "copy_target_generator.h",
    "err.cc",
    "err.h",
    "escape.cc",
    "escape.h",
    "file_template.cc",
    "file_template.h",
    "filesystem_utils.cc",
    "filesystem_utils.h",
    "functions.cc",
    "functions.h",
    "functions_target.cc",
    "function_exec_script.cc",
    "function_process_file_template.cc",
    "function_read_file.cc",
    "function_rebase_path.cc",
    "function_set_default_toolchain.cc",
    "function_set_defaults.cc",
    "function_template.cc",
    "function_toolchain.cc",
    "function_write_file.cc",
    "group_target_generator.cc",
    "group_target_generator.h",
    "gyp_binary_target_writer.cc",
    "gyp_binary_target_writer.h",
    "gyp_helper.cc",
    "gyp_helper.h",
    "gyp_script_target_writer.cc",
    "gyp_script_target_writer.h",
    "gyp_target_writer.cc",
    "gyp_target_writer.h",
    "import_manager.cc",
    "import_manager.h",
    "input_conversion.cc",
    "input_conversion.h",
    "input_file.cc",
    "input_file.h",
    "input_file_manager.cc",
    "input_file_manager.h",
    "item.cc",
    "item.h",
    "label.cc",
    "label.h",
    "label_ptr.h",
    "loader.cc",
    "loader.h",
    "location.cc",
    "location.h",
    "ninja_binary_target_writer.cc",
    "ninja_binary_target_writer.h",
    "ninja_build_writer.cc",
    "ninja_build_writer.h",
    "ninja_copy_target_writer.cc",
    "ninja_copy_target_writer.h",
    "ninja_group_target_writer.cc",
    "ninja_group_target_writer.h",
    "ninja_helper.cc",
    "ninja_helper.h",
    "ninja_script_target_writer.cc",
    "ninja_script_target_writer.h",
    "ninja_target_writer.cc",
    "ninja_target_writer.h",
    "ninja_toolchain_writer.cc",
    "ninja_toolchain_writer.h",
    "ninja_writer.cc",
    "ninja_writer.h",
    "operators.cc",
    "operators.h",
    "output_file.h",
    "parse_tree.cc",
    "parse_tree.h",
    "parser.cc",
    "parser.h",
    "path_output.cc",
    "path_output.h",
    "pattern.cc",
    "pattern.h",
    "scheduler.cc",
    "scheduler.h",
    "scope.cc",
    "scope.h",
    "scope_per_file_provider.cc",
    "scope_per_file_provider.h",
    "script_target_generator.cc",
    "script_target_generator.h",
    "script_values.cc",
    "script_values.h",
    "settings.cc",
    "settings.h",
    "setup.cc",
    "setup.h",
    "source_dir.cc",
    "source_dir.h",
    "source_file.cc",
    "source_file.h",
    "standard_out.cc",
    "standard_out.h",
    "string_utils.cc",
    "string_utils.h",
    "target.cc",
    "target.h",
    "target_generator.cc",
    "target_generator.h",
    "token.cc",
    "token.h",
    "tokenizer.cc",
    "tokenizer.h",
    "toolchain.cc",
    "toolchain.h",
    "trace.cc",
    "trace.h",
    "value.cc",
    "value.h",
    "value_extractors.cc",
    "value_extractors.h",
    "variables.cc",
    "variables.h",
  ]

  deps = [
    "//base",
    "//base/third_party/dynamic_annotations",
  ]
}

executable("gn") {
  sources = [
    "gn_main.cc",
  ]

  deps = [
    ":gn_lib",
  ]
  if (!is_gyp) {
    # Currently this only works in GYP (see GN_BUILD above).
    deps += "//build/util:last_change"
  }
}

test("gn_unittests") {
  sources = [
    "builder_unittest.cc",
    "escape_unittest.cc",
    "file_template_unittest.cc",
    "filesystem_utils_unittest.cc",
    "function_rebase_path_unittest.cc",
    "gyp_script_target_writer_unittest.cc",
    "input_conversion_unittest.cc",
    "label_unittest.cc",
    "loader_unittest.cc",
    "ninja_binary_target_writer_unittest.cc",
    "ninja_copy_target_writer_unittest.cc",
    "ninja_helper_unittest.cc",
    "ninja_script_target_writer_unittest.cc",
    "parser_unittest.cc",
    "path_output_unittest.cc",
    "pattern_unittest.cc",
    "scope_per_file_provider_unittest.cc",
    "scope_unittest.cc",
    "source_dir_unittest.cc",
    "string_utils_unittest.cc",
    "target_generator_unittest.cc",
    "target_unittest.cc",
    "test_with_scope.cc",
    "test_with_scope.h",
    "tokenizer_unittest.cc",
  ]
  deps = [
    ":gn_lib",
    "//base:run_all_unittests",
    "//base:test_support_base",
    "//testing:gtest",
  ]
}

executable("generate_test_gn_data") {
  sources = [ "generate_test_gn_data.cc" ]
  deps = [ "//base" ]
}