• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "gn/ninja_generated_file_target_writer.h"
6 
7 #include "gn/source_file.h"
8 #include "gn/target.h"
9 #include "gn/test_with_scheduler.h"
10 #include "gn/test_with_scope.h"
11 #include "util/test/test.h"
12 
13 using NinjaGeneratedFileTargetWriterTest = TestWithScheduler;
14 
TEST_F(NinjaGeneratedFileTargetWriterTest,Run)15 TEST_F(NinjaGeneratedFileTargetWriterTest, Run) {
16   Err err;
17   TestWithScope setup;
18 
19   Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
20   target.set_output_type(Target::GENERATED_FILE);
21   target.visibility().SetPublic();
22   target.action_values().outputs() =
23       SubstitutionList::MakeForTest("//out/Debug/foo.json");
24   target.set_contents(Value(nullptr, true));
25   target.set_output_conversion(Value(nullptr, "json"));
26 
27   Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"));
28   dep.set_output_type(Target::ACTION);
29   dep.visibility().SetPublic();
30   dep.SetToolchain(setup.toolchain());
31   ASSERT_TRUE(dep.OnResolved(&err));
32 
33   Target dep2(setup.settings(), Label(SourceDir("//foo/"), "dep2"));
34   dep2.set_output_type(Target::ACTION);
35   dep2.visibility().SetPublic();
36   dep2.SetToolchain(setup.toolchain());
37   ASSERT_TRUE(dep2.OnResolved(&err));
38 
39   Target bundle_data_dep(setup.settings(),
40                          Label(SourceDir("//foo/"), "bundle_data_dep"));
41   bundle_data_dep.sources().push_back(SourceFile("//foo/some_data.txt"));
42   bundle_data_dep.set_output_type(Target::BUNDLE_DATA);
43   bundle_data_dep.visibility().SetPublic();
44   bundle_data_dep.SetToolchain(setup.toolchain());
45   ASSERT_TRUE(bundle_data_dep.OnResolved(&err));
46 
47   Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"));
48   datadep.set_output_type(Target::ACTION);
49   datadep.visibility().SetPublic();
50   datadep.SetToolchain(setup.toolchain());
51   ASSERT_TRUE(datadep.OnResolved(&err));
52 
53   target.public_deps().push_back(LabelTargetPair(&dep));
54   target.public_deps().push_back(LabelTargetPair(&dep2));
55   target.public_deps().push_back(LabelTargetPair(&bundle_data_dep));
56   target.data_deps().push_back(LabelTargetPair(&datadep));
57 
58   target.SetToolchain(setup.toolchain());
59   ASSERT_TRUE(target.OnResolved(&err)) << err.message();
60 
61   std::ostringstream out;
62   NinjaGeneratedFileTargetWriter writer(&target, out);
63   writer.Run();
64 
65   const char expected[] =
66       "build obj/foo/bar.stamp: stamp obj/foo/dep.stamp obj/foo/dep2.stamp || "
67       "obj/foo/bundle_data_dep.stamp obj/foo/datadep.stamp\n";
68   EXPECT_EQ(expected, out.str());
69 }
70