• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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/swift_values_generator.h"
6 
7 #include "gn/label.h"
8 #include "gn/scope.h"
9 #include "gn/settings.h"
10 #include "gn/swift_values.h"
11 #include "gn/swift_variables.h"
12 #include "gn/target.h"
13 #include "gn/value_extractors.h"
14 
SwiftValuesGenerator(Target * target,Scope * scope,Err * err)15 SwiftValuesGenerator::SwiftValuesGenerator(Target* target,
16                                            Scope* scope,
17                                            Err* err)
18     : target_(target), scope_(scope), err_(err) {}
19 
20 SwiftValuesGenerator::~SwiftValuesGenerator() = default;
21 
Run()22 void SwiftValuesGenerator::Run() {
23   if (!FillBridgeHeader())
24     return;
25 
26   if (!FillModuleName())
27     return;
28 }
29 
FillBridgeHeader()30 bool SwiftValuesGenerator::FillBridgeHeader() {
31   const Value* value = scope_->GetValue(variables::kSwiftBridgeHeader, true);
32   if (!value)
33     return true;
34 
35   if (!value->VerifyTypeIs(Value::STRING, err_))
36     return false;
37 
38   SourceFile dest;
39   if (!ExtractRelativeFile(scope_->settings()->build_settings(), *value,
40                            scope_->GetSourceDir(), &dest, err_))
41     return false;
42 
43   target_->swift_values().bridge_header() = std::move(dest);
44   return true;
45 }
46 
FillModuleName()47 bool SwiftValuesGenerator::FillModuleName() {
48   const Value* value = scope_->GetValue(variables::kSwiftModuleName, true);
49   if (!value) {
50     // The target name will be used.
51     target_->swift_values().module_name() = target_->label().name();
52     return true;
53   }
54 
55   if (!value->VerifyTypeIs(Value::STRING, err_))
56     return false;
57 
58   target_->swift_values().module_name() = std::move(value->string_value());
59   return true;
60 }
61