summaryrefslogtreecommitdiffstats
path: root/tools/gn/binary_target_generator.cc
blob: b287fe94a43941840ce705370c9128b1ac725b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "tools/gn/binary_target_generator.h"

#include "tools/gn/config_values_generator.h"
#include "tools/gn/err.h"
#include "tools/gn/scope.h"
#include "tools/gn/variables.h"

BinaryTargetGenerator::BinaryTargetGenerator(
    Target* target,
    Scope* scope,
    const FunctionCallNode* function_call,
    Target::OutputType type,
    Err* err)
    : TargetGenerator(target, scope, function_call, err),
      output_type_(type) {
}

BinaryTargetGenerator::~BinaryTargetGenerator() {
}

void BinaryTargetGenerator::DoRun() {
  target_->set_output_type(output_type_);

  FillOutputName();
  if (err_->has_error())
    return;

  FillOutputExtension();
  if (err_->has_error())
    return;

  FillExternal();
  if (err_->has_error())
    return;

  FillSources();
  if (err_->has_error())
    return;

  FillSourcePrereqs();
  if (err_->has_error())
    return;

  FillConfigs();
  if (err_->has_error())
    return;

  // Config values (compiler flags, etc.) set directly on this target.
  ConfigValuesGenerator gen(&target_->config_values(), scope_,
                            scope_->GetSourceDir(), err_);
  gen.Run();
  if (err_->has_error())
    return;
}

void BinaryTargetGenerator::FillOutputName() {
  const Value* value = scope_->GetValue(variables::kOutputName, true);
  if (!value)
    return;
  if (!value->VerifyTypeIs(Value::STRING, err_))
    return;
  target_->set_output_name(value->string_value());
}

void BinaryTargetGenerator::FillOutputExtension() {
  const Value* value = scope_->GetValue(variables::kOutputExtension, true);
  if (!value)
    return;
  if (!value->VerifyTypeIs(Value::STRING, err_))
    return;
  target_->set_output_extension(value->string_value());
}