summaryrefslogtreecommitdiffstats
path: root/tools/gn/create_bundle_target_generator.cc
blob: 206a91861e92cc6529f2477fc508d764c94fe16e (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
// Copyright 2016 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/create_bundle_target_generator.h"

#include "tools/gn/filesystem_utils.h"
#include "tools/gn/parse_tree.h"
#include "tools/gn/scope.h"
#include "tools/gn/substitution_type.h"
#include "tools/gn/target.h"
#include "tools/gn/value.h"
#include "tools/gn/variables.h"

CreateBundleTargetGenerator::CreateBundleTargetGenerator(
    Target* target,
    Scope* scope,
    const FunctionCallNode* function_call,
    Err* err)
    : TargetGenerator(target, scope, function_call, err) {}

CreateBundleTargetGenerator::~CreateBundleTargetGenerator() {}

void CreateBundleTargetGenerator::DoRun() {
  target_->set_output_type(Target::CREATE_BUNDLE);

  BundleData& bundle_data = target_->bundle_data();
  if (!GetBundleDir(std::string(),
                    variables::kBundleRootDir,
                    &bundle_data.root_dir()))
    return;
  if (!GetBundleDir(bundle_data.root_dir(),
                    variables::kBundleResourcesDir,
                    &bundle_data.resources_dir()))
    return;
  if (!GetBundleDir(bundle_data.root_dir(),
                    variables::kBundleExecutableDir,
                    &bundle_data.executable_dir()))
    return;
  if (!GetBundleDir(bundle_data.root_dir(),
                    variables::kBundlePlugInsDir,
                    &bundle_data.plugins_dir()))
    return;
}

bool CreateBundleTargetGenerator::GetBundleDir(
    const std::string& bundle_root_dir,
    const base::StringPiece& name,
    std::string* bundle_dir) {
  const Value* value = scope_->GetValue(name, true);
  if (!value)
    return true;
  if (!value->VerifyTypeIs(Value::STRING, err_))
    return false;
  const std::string& str = value->string_value();
  if (!EnsureStringIsInOutputDir(GetBuildSettings()->build_dir(), str,
                                 value->origin(), err_))
    return false;
  if (str != bundle_root_dir &&
      !IsStringInOutputDir(SourceDir(bundle_root_dir), str)) {
    *err_ = Err(value->origin(), "Path is not in bundle root dir.",
        "The given file should be in the bundle root directory or below.\n"
        "Normally you would do \"$bundle_root_dir/foo\". I interpreted this\n"
        "as \"" + str + "\".");
    return false;
  }
  bundle_dir->assign(value->string_value());
  return true;
}