chromium/ash/webui/file_manager/resources/BUILD.gn

# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//chrome/common/features.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/preprocess_if_expr.gni")
import("//tools/typescript/webui_ts_library.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
import("//ui/webui/resources/tools/optimize_webui.gni")
import("//ui/webui/webui_features.gni")

assert(is_chromeos_ash)

# Only build Labs for debug (non-optimize-webui).
if (!optimize_webui) {
  ts_files = [ "labs/main.ts" ]

  copy("copy_labs") {
    sources = [ "labs/labs.html" ] + ts_files
    outputs = [ "$target_gen_dir/{{source_target_relative}}" ]
  }

  webui_ts_library("labs_build_ts") {
    root_dir = target_gen_dir
    out_dir = "$target_gen_dir/tsc"
    enable_source_maps = true
    extra_deps = [ ":copy_labs" ]

    in_files = ts_files

    deps = [ "//ui/webui/resources/js:build_ts" ]
  }
}

generated_static_grdp = "$target_gen_dir/static_resources.grdp"

generate_grd("build_static_grdp") {
  out_grd = generated_static_grdp
  grd_prefix = "file_manager_swa"

  input_files_base_dir = rebase_path(".", "//")

  input_files = [ "images/icon192.png" ]
}

grd_prefix = "file_manager_swa"
generated_grd = "$target_gen_dir/${grd_prefix}_resources.grd"

generate_grd("build_grd") {
  out_grd = generated_grd

  grdp_files = [ generated_static_grdp ]

  deps = [ ":build_static_grdp" ]
  input_files_base_dir = rebase_path(target_gen_dir, root_build_dir)
  input_files = []
  manifest_files = []

  if (!optimize_webui) {
    # Labs:
    manifest_files += filter_include(get_target_outputs(":labs_build_ts"),
                                     [ "*_manifest.json" ])
    input_files += [ "labs/labs.html" ]
    deps += [
      ":copy_labs",
      ":labs_build_ts",
    ]
  }
}

grit("file_manager_swa_resources") {
  defines = chrome_grit_defines

  # These arguments are needed since the grd is generated at build time.
  enable_input_discovery_for_gn_analyze = false

  source = generated_grd
  deps = [ ":build_grd" ]

  outputs = [
    "grit/file_manager_swa_resources.h",
    "grit/file_manager_swa_resources_map.cc",
    "grit/file_manager_swa_resources_map.h",
    "file_manager_swa_resources.pak",
  ]
  output_dir = target_gen_dir
}