Home | History | Annotate | Download | only in gn
      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 "tools/gn/binary_target_generator.h"
      6 
      7 #include "tools/gn/config_values_generator.h"
      8 #include "tools/gn/err.h"
      9 #include "tools/gn/scope.h"
     10 #include "tools/gn/variables.h"
     11 
     12 BinaryTargetGenerator::BinaryTargetGenerator(
     13     Target* target,
     14     Scope* scope,
     15     const FunctionCallNode* function_call,
     16     Target::OutputType type,
     17     Err* err)
     18     : TargetGenerator(target, scope, function_call, err),
     19       output_type_(type) {
     20 }
     21 
     22 BinaryTargetGenerator::~BinaryTargetGenerator() {
     23 }
     24 
     25 void BinaryTargetGenerator::DoRun() {
     26   target_->set_output_type(output_type_);
     27 
     28   FillOutputName();
     29   if (err_->has_error())
     30     return;
     31 
     32   FillOutputExtension();
     33   if (err_->has_error())
     34     return;
     35 
     36   FillSources();
     37   if (err_->has_error())
     38     return;
     39 
     40   FillPublic();
     41   if (err_->has_error())
     42     return;
     43 
     44   FillInputs();
     45   if (err_->has_error())
     46     return;
     47 
     48   FillConfigs();
     49   if (err_->has_error())
     50     return;
     51 
     52   // Config values (compiler flags, etc.) set directly on this target.
     53   ConfigValuesGenerator gen(&target_->config_values(), scope_,
     54                             scope_->GetSourceDir(), err_);
     55   gen.Run();
     56   if (err_->has_error())
     57     return;
     58 }
     59 
     60 void BinaryTargetGenerator::FillOutputName() {
     61   const Value* value = scope_->GetValue(variables::kOutputName, true);
     62   if (!value)
     63     return;
     64   if (!value->VerifyTypeIs(Value::STRING, err_))
     65     return;
     66   target_->set_output_name(value->string_value());
     67 }
     68 
     69 void BinaryTargetGenerator::FillOutputExtension() {
     70   const Value* value = scope_->GetValue(variables::kOutputExtension, true);
     71   if (!value)
     72     return;
     73   if (!value->VerifyTypeIs(Value::STRING, err_))
     74     return;
     75   target_->set_output_extension(value->string_value());
     76 }
     77