1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file. 4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include <algorithm> 6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include <sstream> 7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "tools/gn/ninja_copy_target_writer.h" 1003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "tools/gn/target.h" 11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "tools/gn/test_with_scope.h" 12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Tests mutliple files with an output pattern and no toolchain dependency. 14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)TEST(NinjaCopyTargetWriter, Run) { 15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) TestWithScope setup; 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Err err; 1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch setup.settings()->set_target_os(Settings::LINUX); 19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) target.set_output_type(Target::COPY_FILES); 22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) target.sources().push_back(SourceFile("//foo/input1.txt")); 24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) target.sources().push_back(SourceFile("//foo/input2.txt")); 25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) target.action_values().outputs() = 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); 28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) target.SetToolchain(setup.toolchain()); 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_TRUE(target.OnResolved(&err)); 3103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::ostringstream out; 3303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) NinjaCopyTargetWriter writer(&target, out); 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch writer.Run(); 35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const char expected_linux[] = 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build input1.out: copy ../../foo/input1.txt\n" 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build input2.out: copy ../../foo/input2.txt\n" 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "\n" 40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::string out_str = out.str(); 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(expected_linux, out_str); 43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Tests a single file with no output pattern. 46116680a4aac90f2aa7413d9095a592090648e557Ben MurdochTEST(NinjaCopyTargetWriter, ToolchainDeps) { 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch TestWithScope setup; 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Err err; 4903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch setup.settings()->set_target_os(Settings::LINUX); 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch target.set_output_type(Target::COPY_FILES); 54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch target.sources().push_back(SourceFile("//foo/input1.txt")); 56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) target.action_values().outputs() = 585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SubstitutionList::MakeForTest("//out/Debug/output.out"); 59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) target.SetToolchain(setup.toolchain()); 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_TRUE(target.OnResolved(&err)); 6203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::ostringstream out; 6403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) NinjaCopyTargetWriter writer(&target, out); 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch writer.Run(); 66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const char expected_linux[] = 685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) "build output.out: copy ../../foo/input1.txt\n" 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "\n" 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build obj/foo/bar.stamp: stamp output.out\n"; 71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::string out_str = out.str(); 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(expected_linux, out_str); 73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 74