1 // Copyright (c) 2013 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/copy_target_generator.h"
6
7 #include "gn/build_settings.h"
8 #include "gn/filesystem_utils.h"
9 #include "gn/parse_tree.h"
10 #include "gn/scope.h"
11 #include "gn/value.h"
12
CopyTargetGenerator(Target * target,Scope * scope,const FunctionCallNode * function_call,Err * err)13 CopyTargetGenerator::CopyTargetGenerator(Target* target,
14 Scope* scope,
15 const FunctionCallNode* function_call,
16 Err* err)
17 : TargetGenerator(target, scope, function_call, err) {}
18
19 CopyTargetGenerator::~CopyTargetGenerator() = default;
20
DoRun()21 void CopyTargetGenerator::DoRun() {
22 target_->set_output_type(Target::COPY_FILES);
23
24 if (!FillSources())
25 return;
26 if (!FillOutputs(true))
27 return;
28
29 if (target_->sources().empty()) {
30 *err_ = Err(
31 function_call_, "Empty sources for copy command.",
32 "You have to specify at least one file to copy in the \"sources\".");
33 return;
34 }
35 if (target_->action_values().outputs().list().size() != 1) {
36 *err_ = Err(
37 function_call_, "Copy command must have exactly one output.",
38 "You must specify exactly one value in the \"outputs\" array for the "
39 "destination of the copy\n(see \"gn help copy\"). If there are "
40 "multiple sources to copy, use source expansion\n(see \"gn help "
41 "source_expansion\").");
42 return;
43 }
44 }
45