[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / relocation_packer / BUILD.gn
blob563a64d62cee91c8cf56f6d08afd82981d67a904
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("config.gni")
6 import("//testing/test.gni")
8 assert(relocation_packing_supported)
10 if (target_cpu == "arm") {
11   target_define = "TARGET_ARM"
12 } else if (target_cpu == "arm64") {
13   target_define = "TARGET_ARM64"
16 if (current_toolchain == host_toolchain) {
17   # GYP: //tools/relocation_packer/relocation_packer.gyp:lib_relocation_packer
18   source_set("lib_relocation_packer") {
19     defines = [ target_define ]
20     deps = [
21       "//third_party/elfutils:libelf",
22     ]
23     configs -= [ "//build/config/compiler:chromium_code" ]
24     configs += [ "//build/config/compiler:no_chromium_code" ]
25     sources = [
26       "src/debug.cc",
27       "src/delta_encoder.cc",
28       "src/elf_file.cc",
29       "src/leb128.cc",
30       "src/packer.cc",
31       "src/run_length_encoder.cc",
32       "src/sleb128.cc",
33     ]
34   }
36   # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer
37   executable("relocation_packer") {
38     defines = [ target_define ]
39     deps = [
40       ":lib_relocation_packer",
41       "//third_party/elfutils:libelf",
42     ]
43     sources = [
44       "src/main.cc",
45     ]
46   }
48   # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer_unittests
49   test("relocation_packer_unittests") {
50     sources = [
51       "src/debug_unittest.cc",
52       "src/delta_encoder_unittest.cc",
53       "src/elf_file_unittest.cc",
54       "src/leb128_unittest.cc",
55       "src/packer_unittest.cc",
56       "src/run_all_unittests.cc",
57       "src/run_length_encoder_unittest.cc",
58       "src/sleb128_unittest.cc",
59     ]
60     rebased_test_data = rebase_path("test_data", root_build_dir)
61     data = [
62       "test_data/elf_file_unittest_relocs_arm32.so",
63       "test_data/elf_file_unittest_relocs_arm32_packed.so",
64       "test_data/elf_file_unittest_relocs_arm64.so",
65       "test_data/elf_file_unittest_relocs_arm64_packed.so",
66     ]
67     defines = [
68       target_define,
69       "INTERMEDIATE_DIR=\"$rebased_test_data\"",
70     ]
71     include_dirs = [ "//" ]
72     deps = [
73       ":lib_relocation_packer",
74       ":relocation_packer_test_data",
75       "//testing:gtest",
76     ]
77   }
80 if (current_toolchain == default_toolchain &&
81     (target_cpu == "arm" || target_cpu == "arm64")) {
82   # Targets to build test data.  These participate only in building test
83   # data for use with elf_file_unittest.cc, and are not part of the main
84   # relocation packer build.  Unit test data files are checked in to the
85   # source tree as 'golden' data, and are not generated 'on the fly' by
86   # the build.
87   #
88   # See test_data/generate_elf_file_unittest_relocs.sh for instructions.
90   # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer_test_data
91   shared_library("relocation_packer_test_data") {
92     cflags = [
93       "-O0",
94       "-g0",
95     ]
96     sources = [
97       "test_data/elf_file_unittest_relocs.cc",
98     ]
99   }
101   # GYP: //tools/relocation_packer/relocation_packer.gyp:relocation_packer_unittests_test_data
102   action("relocation_packer_unittests_test_data") {
103     script = "test_data/generate_elf_file_unittest_relocs.py"
104     test_file = "$root_build_dir/librelocation_packer_test_data.so"
105     if (target_cpu == "arm") {
106       added_section = ".android.rel.dyn"
107       packed_output = "elf_file_unittest_relocs_arm32_packed.so"
108       unpacked_output = "elf_file_unittest_relocs_arm32.so"
109     } else if (target_cpu == "arm64") {
110       added_section = ".android.rela.dyn"
111       packed_output = "elf_file_unittest_relocs_arm64_packed.so"
112       unpacked_output = "elf_file_unittest_relocs_arm64.so"
113     } else {
114       assert(false, "Unsupported target arch for relocation packer")
115     }
117     packed_output = "$root_build_dir/$packed_output"
118     unpacked_output = "$root_build_dir/$unpacked_output"
120     inputs = [
121       test_file,
122     ]
124     deps = [
125       ":relocation_packer_test_data",
126       ":relocation_packer($host_toolchain)",
127     ]
129     outputs = [
130       packed_output,
131       unpacked_output,
132     ]
134     args = [
135       "--android-pack-relocations",
136       rebase_path(relocation_packer_exe, root_build_dir),
137       "--android-objcopy",
138       rebase_path(android_objcopy, root_build_dir),
139       "--added-section=$added_section",
140       "--test-file",
141       rebase_path(test_file, root_build_dir),
142       "--packed-output",
143       rebase_path(packed_output, root_build_dir),
144       "--unpacked-output",
145       rebase_path(unpacked_output, root_build_dir),
146     ]
147   }