• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ohos_variables.h"
10 #include "gn/parse_tree.h"
11 #include "gn/scope.h"
12 #include "gn/value.h"
13 
CopyTargetGenerator(Target * target,Scope * scope,const FunctionCallNode * function_call,Err * err)14 CopyTargetGenerator::CopyTargetGenerator(Target* target,
15                                          Scope* scope,
16                                          const FunctionCallNode* function_call,
17                                          Err* err)
18     : TargetGenerator(target, scope, function_call, err) {}
19 
20 CopyTargetGenerator::~CopyTargetGenerator() = default;
21 
FillCopyLinkableFile()22 bool CopyTargetGenerator::FillCopyLinkableFile()
23 {
24     const Value* value = scope_->GetValue(variables::kCopyLinkableFile, true);
25     if (!value)
26         return true;
27     if (!value->VerifyTypeIs(Value::BOOLEAN, err_))
28         return false;
29     target_->set_copy_linkable_file(value->boolean_value());
30   return true;
31 }
32 
DoRun()33 void CopyTargetGenerator::DoRun() {
34   target_->set_output_type(Target::COPY_FILES);
35 
36   if (!FillSources())
37     return;
38   if (!FillOutputs(true))
39     return;
40 
41   if (target_->sources().empty()) {
42     *err_ = Err(
43         function_call_, "Empty sources for copy command.",
44         "You have to specify at least one file to copy in the \"sources\".");
45     return;
46   }
47   if (target_->action_values().outputs().list().size() != 1) {
48     *err_ = Err(
49         function_call_, "Copy command must have exactly one output.",
50         "You must specify exactly one value in the \"outputs\" array for the "
51         "destination of the copy\n(see \"gn help copy\"). If there are "
52         "multiple sources to copy, use source expansion\n(see \"gn help "
53         "source_expansion\").");
54     return;
55   }
56 
57   if (!FillCopyLinkableFile())
58     return;
59 }
60