Commit 5a1b4b17 authored by grt's avatar grt Committed by Commit bot

Revert of [GN] Add JSON project writer (patchset #11 id:200001 of...

Revert of [GN] Add JSON project writer (patchset #11 id:200001 of https://codereview.chromium.org/2064533002/ )

Reason for revert:
Broke Win8 GYP (dbg) builder:
[822/12249] LINK_EMBED gn.exe
FAILED: gn.exe gn.exe.pdb
E:\b\depot_tools\python276_bin\python.exe gyp-win-tool link-with-manifests environment.x86 True gn.exe "E:\b\depot_tools\python276_bin\python.exe gyp-win-tool link-wrapper environment.x86 False link.exe /nologo /OUT:gn.exe @gn.exe.rsp" 1 mt.exe rc.exe "obj\tools\gn\gn.gn.exe.intermediate.manifest" obj\tools\gn\gn.gn.exe.generated.manifest ..\..\build\win\compatibility.manifest
gn_lib.lib(gn_lib.command_desc.obj) : error LNK2019: unresolved external symbol "public: static class std::unique_ptr<class base::DictionaryValue,struct std::default_delete<class base::DictionaryValue> > __cdecl DescBuilder::DescriptionForTarget(class Target const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,bool,bool)" (?DescriptionForTarget@DescBuilder@@SA?AV?$unique_ptr@VDictionaryValue@base@@U?$default_delete@VDictionaryValue@base@@@std@@@std@@PBVTarget@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@_N22@Z) referenced in function "bool __cdecl commands::`anonymous namespace'::PrintTarget(class Target const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,bool,bool,bool)" (?PrintTarget@?A0x51180473@commands@@YA_NPBVTarget@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N222@Z)

gn_lib.lib(gn_lib.command_desc.obj) : error LNK2019: unresolved external symbol "public: static class std::unique_ptr<class base::DictionaryValue,struct std::default_delete<class base::DictionaryValue> > __cdecl DescBuilder::DescriptionForConfig(class Config const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?DescriptionForConfig@DescBuilder@@SA?AV?$unique_ptr@VDictionaryValue@base@@U?$default_delete@VDictionaryValue@base@@@std@@@std@@PBVConfig@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@Z) referenced in function "bool __cdecl commands::`anonymous namespace'::PrintConfig(class Config const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?PrintConfig@?A0x51180473@commands@@YA_NPBVConfig@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z)

gn_lib.lib(gn_lib.command_gen.obj) : error LNK2019: unresolved external symbol "public: static bool __cdecl JSONProjectWriter::RunAndWriteFiles(class BuildSettings const *,class Builder const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,class Err *)" (?RunAndWriteFiles@JSONProjectWriter@@SA_NPBVBuildSettings@@PBVBuilder@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@222_NPAVErr@@@Z) referenced in function "bool __cdecl commands::`anonymous namespace'::RunIdeWriter(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class BuildSettings const *,class Builder *,class Err *)" (?RunIdeWriter@?A0x1eff038c@commands@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBVBuildSettings@@PAVBuilder@@PAVErr@@@Z)

gn.exe : fatal error LNK1120: 3 unresolved externals

Traceback (most recent call last):

  File "gyp-win-tool", line 323, in <module>

    sys.exit(main(sys.argv[1:]))

  File "gyp-win-tool", line 29, in main

    exit_code = executor.Dispatch(args)

  File "gyp-win-tool", line 71, in Dispatch

    return getattr(self, method)(*args[1:])

  File "gyp-win-tool", line 179, in ExecLinkWithManifests

    subprocess.check_call(ldcmd + add_to_ld)

  File "E:\b\depot_tools\python276_bin\lib\subprocess.py", line 540, in check_call

    raise CalledProcessError(retcode, cmd)

subprocess.CalledProcessError: Command 'E:\b\depot_tools\python276_bin\python.exe gyp-win-tool link-wrapper environment.x86 False link.exe /nologo /OUT:gn.exe @gn.exe.rsp gn.exe.manifest.res' returned non-zero exit status 1120

Original issue's description:
> [GN] Add JSON project writer
>
> Output is a JSON file containing information about targets. The generator
> can also optionally invoke a python script on generated file.
>
> Example:
> gn gen --ide=json ./out-json --json-ide-script=//scripts/custom-ide-generator.py \
>     --ison-ide-script-args="additional script arguments"
>
> Also implements --format=json for gn desc as described in https://bugs.chromium.org/p/chromium/issues/detail?id=620132
>
> BUG=
>
> Committed: https://crrev.com/d2edeb9a743ad5a2046e655997277d3bb630db03
> Cr-Commit-Position: refs/heads/master@{#406064}

TBR=brettw@chromium.org,matej.knopp@gmail.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.chromium.org/2160533004
Cr-Commit-Position: refs/heads/master@{#406074}
parent 4ade1038
......@@ -409,7 +409,6 @@ Martin Bednorz <m.s.bednorz@gmail.com>
Martina Kollarova <martina.kollarova@intel.com>
Masahiro Yado <yado.masa@gmail.com>
Masaru Nishida <msr.i386@gmail.com>
Matej Knopp <matej.knopp@gmail.com>
Matheus Bratfisch <matheusbrat@gmail.com>
Mathias Bynens <mathias@qiwi.be>
Mathieu Meisser <mmeisser@logitech.com>
......
......@@ -58,8 +58,6 @@ static_library("gn_lib") {
"create_bundle_target_generator.h",
"deps_iterator.cc",
"deps_iterator.h",
"desc_builder.cc",
"desc_builder.h",
"eclipse_writer.cc",
"eclipse_writer.h",
"err.cc",
......@@ -103,8 +101,6 @@ static_library("gn_lib") {
"input_file_manager.h",
"item.cc",
"item.h",
"json_project_writer.cc",
"json_project_writer.h",
"label.cc",
"label.h",
"label_pattern.cc",
......
This diff is collapsed.
......@@ -11,7 +11,6 @@
#include "tools/gn/build_settings.h"
#include "tools/gn/commands.h"
#include "tools/gn/eclipse_writer.h"
#include "tools/gn/json_project_writer.h"
#include "tools/gn/ninja_target_writer.h"
#include "tools/gn/ninja_writer.h"
#include "tools/gn/qt_creator_writer.h"
......@@ -37,14 +36,10 @@ const char kSwitchIdeValueVs[] = "vs";
const char kSwitchIdeValueVs2013[] = "vs2013";
const char kSwitchIdeValueVs2015[] = "vs2015";
const char kSwitchIdeValueXcode[] = "xcode";
const char kSwitchIdeValueJson[] = "json";
const char kSwitchNinjaExtraArgs[] = "ninja-extra-args";
const char kSwitchRootTarget[] = "root-target";
const char kSwitchSln[] = "sln";
const char kSwitchWorkspace[] = "workspace";
const char kSwitchJsonFileName[] = "json-file-name";
const char kSwitchJsonIdeScript[] = "json-ide-script";
const char kSwitchJsonIdeScriptArgs[] = "json-ide-script-args";
// Called on worker thread to write the ninja file.
void BackgroundDoWrite(const Target* target) {
......@@ -118,7 +113,7 @@ void PrintInvalidGeneratedInput(const Builder* builder,
if (generator) {
err += "but this file was not generated by any dependencies of the " +
target_str + ". The target\nthat generates the file is:\n ";
target_str + ". The target\nthat generates the file is:\n ";
err += generator->label().GetUserVisibleName(show_toolchains);
} else {
err += "but no targets in the build generate that file.";
......@@ -171,12 +166,11 @@ bool RunIdeWriter(const std::string& ide,
Err* err) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
bool quiet = command_line->HasSwitch(switches::kQuiet);
base::ElapsedTimer timer;
if (ide == kSwitchIdeValueEclipse) {
bool res = EclipseWriter::RunAndWriteFile(build_settings, builder, err);
if (res && !quiet) {
if (res && !command_line->HasSwitch(switches::kQuiet)) {
OutputString("Generating Eclipse settings took " +
base::Int64ToString(timer.Elapsed().InMilliseconds()) +
"ms\n");
......@@ -195,7 +189,7 @@ bool RunIdeWriter(const std::string& ide,
filters = command_line->GetSwitchValueASCII(kSwitchFilters);
bool res = VisualStudioWriter::RunAndWriteFiles(
build_settings, builder, version, sln_name, filters, err);
if (res && !quiet) {
if (res && !command_line->HasSwitch(switches::kQuiet)) {
OutputString("Generating Visual Studio projects took " +
base::Int64ToString(timer.Elapsed().InMilliseconds()) +
"ms\n");
......@@ -208,7 +202,7 @@ bool RunIdeWriter(const std::string& ide,
command_line->GetSwitchValueASCII(kSwitchNinjaExtraArgs),
command_line->GetSwitchValueASCII(kSwitchFilters), build_settings,
builder, err);
if (res && !quiet) {
if (res && !command_line->HasSwitch(switches::kQuiet)) {
OutputString("Generating Xcode projects took " +
base::Int64ToString(timer.Elapsed().InMilliseconds()) +
"ms\n");
......@@ -220,32 +214,12 @@ bool RunIdeWriter(const std::string& ide,
root_target = command_line->GetSwitchValueASCII(kSwitchRootTarget);
bool res = QtCreatorWriter::RunAndWriteFile(build_settings, builder, err,
root_target);
if (res && !quiet) {
if (res && !command_line->HasSwitch(switches::kQuiet)) {
OutputString("Generating QtCreator projects took " +
base::Int64ToString(timer.Elapsed().InMilliseconds()) +
"ms\n");
}
return res;
} else if (ide == kSwitchIdeValueJson) {
std::string file_name =
command_line->GetSwitchValueASCII(kSwitchJsonFileName);
if (file_name.empty())
file_name = "project.json";
std::string exec_script =
command_line->GetSwitchValueASCII(kSwitchJsonIdeScript);
std::string exec_script_extra_args =
command_line->GetSwitchValueASCII(kSwitchJsonIdeScriptArgs);
std::string filters = command_line->GetSwitchValueASCII(kSwitchFilters);
bool res = JSONProjectWriter::RunAndWriteFiles(
build_settings, builder, file_name, exec_script, exec_script_extra_args,
filters, quiet, err);
if (res && !quiet) {
OutputString("Generating JSON projects took " +
base::Int64ToString(timer.Elapsed().InMilliseconds()) +
"ms\n");
}
return res;
}
*err = Err(Location(), "Unknown IDE: " + ide);
......@@ -255,7 +229,8 @@ bool RunIdeWriter(const std::string& ide,
} // namespace
const char kGen[] = "gen";
const char kGen_HelpShort[] = "gen: Generate ninja files.";
const char kGen_HelpShort[] =
"gen: Generate ninja files.";
const char kGen_Help[] =
"gn gen: Generate ninja files.\n"
"\n"
......@@ -284,13 +259,12 @@ const char kGen_Help[] =
" \"vs2015\" - Visual Studio 2015 project/solution files.\n"
" \"xcode\" - Xcode workspace/solution files.\n"
" \"qtcreator\" - QtCreator project files.\n"
" \"json\" - JSON file containing target information\n"
"\n"
" --filters=<path_prefixes>\n"
" Semicolon-separated list of label patterns used to limit the set\n"
" of generated projects (see \"gn help label_pattern\"). Only\n"
" matching targets and their dependencies will be included in the\n"
" solution. Only used for Visual Studio, Xcode and JSON.\n"
" solution. Only used for Visual Studio and Xcode.\n"
"\n"
"Visual Studio Flags\n"
"\n"
......@@ -331,27 +305,7 @@ const char kGen_Help[] =
" properly define includes/defines for each file individually.\n"
" Instead, one set of includes/defines is generated for the entire\n"
" project. This works fairly well but may still result in a few indexer\n"
" issues here and there.\n"
"\n"
"Generic JSON Output\n"
"\n"
" Dumps target information to JSON file and optionally invokes python\n"
" script on generated file. \n"
" See comments at the beginning of json_project_writer.cc and\n"
" desc_builder.cc for overview of JSON file format.\n"
"\n"
" --json-file-name=<json_file_name>\n"
" Overrides default file name (project.json) of generated JSON file.\n"
"\n"
" --json-ide-script=<path_to_python_script>\n"
" Executes python script after the JSON file is generated.\n"
" Path can be project absolute (//), system absolute (/) or\n"
" relative, in which case the output directory will be base.\n"
" Path to generated JSON file will be first argument when invoking\n"
" script.\n"
"\n"
" --json-ide-script-args=<argument>\n"
" Optional second argument that will passed to executed script.\n";
" issues here and there.\n";
int RunGen(const std::vector<std::string>& args) {
base::ElapsedTimer timer;
......
......@@ -6,7 +6,6 @@
#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "base/values.h"
#include "tools/gn/builder.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/item.h"
......@@ -281,20 +280,22 @@ base::FilePath BuildFileForItem(const Item* item) {
return item->defined_from()->GetRange().begin().file()->physical_name();
}
void PrintTargetsAsBuildfiles(const std::vector<const Target*>& targets,
base::ListValue* out) {
void PrintTargetsAsBuildfiles(bool indent,
const std::vector<const Target*>& targets) {
// Output the set of unique source files.
std::set<std::string> unique_files;
for (const Target* target : targets)
unique_files.insert(FilePathToUTF8(BuildFileForItem(target)));
for (const std::string& file : unique_files) {
out->AppendString(file);
if (indent)
OutputString(" ");
OutputString(file + "\n");
}
}
void PrintTargetsAsLabels(const std::vector<const Target*>& targets,
base::ListValue* out) {
void PrintTargetsAsLabels(bool indent,
const std::vector<const Target*>& targets) {
// Putting the labels into a set automatically sorts them for us.
std::set<Label> unique_labels;
for (auto* target : targets)
......@@ -306,13 +307,16 @@ void PrintTargetsAsLabels(const std::vector<const Target*>& targets,
for (const Label& label : unique_labels) {
// Print toolchain only for ones not in the default toolchain.
out->AppendString(label.GetUserVisibleName(label.GetToolchainLabel() !=
default_tc_label));
if (indent)
OutputString(" ");
OutputString(label.GetUserVisibleName(
label.GetToolchainLabel() != default_tc_label));
OutputString("\n");
}
}
void PrintTargetsAsOutputs(const std::vector<const Target*>& targets,
base::ListValue* out) {
void PrintTargetsAsOutputs(bool indent,
const std::vector<const Target*>& targets) {
if (targets.empty())
return;
......@@ -332,7 +336,10 @@ void PrintTargetsAsOutputs(const std::vector<const Target*>& targets,
std::string result = RebasePath(output_as_source.value(),
build_settings->build_dir(),
build_settings->root_path_utf8());
out->AppendString(result);
if (indent)
OutputString(" ");
OutputString(result);
OutputString("\n");
}
}
......@@ -483,8 +490,7 @@ bool FilterPatternsFromString(const BuildSettings* build_settings,
return true;
}
void FilterAndPrintTargets(std::vector<const Target*>* targets,
base::ListValue* out) {
void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets) {
if (targets->empty())
return;
......@@ -498,40 +504,21 @@ void FilterAndPrintTargets(std::vector<const Target*>* targets,
return;
switch (printing_mode) {
case TARGET_PRINT_BUILDFILE:
PrintTargetsAsBuildfiles(*targets, out);
PrintTargetsAsBuildfiles(indent, *targets);
break;
case TARGET_PRINT_LABEL:
PrintTargetsAsLabels(*targets, out);
PrintTargetsAsLabels(indent, *targets);
break;
case TARGET_PRINT_OUTPUT:
PrintTargetsAsOutputs(*targets, out);
PrintTargetsAsOutputs(indent, *targets);
break;
}
}
void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets) {
base::ListValue tmp;
FilterAndPrintTargets(targets, &tmp);
for (const auto& value : tmp) {
std::string string;
value->GetAsString(&string);
if (indent)
OutputString(" ");
OutputString(string);
OutputString("\n");
}
}
void FilterAndPrintTargetSet(bool indent,
const std::set<const Target*>& targets) {
std::vector<const Target*> target_vector(targets.begin(), targets.end());
FilterAndPrintTargets(indent, &target_vector);
}
void FilterAndPrintTargetSet(const std::set<const Target*>& targets,
base::ListValue* out) {
std::vector<const Target*> target_vector(targets.begin(), targets.end());
FilterAndPrintTargets(&target_vector, out);
}
} // namespace commands
......@@ -11,7 +11,6 @@
#include <vector>
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "tools/gn/target.h"
#include "tools/gn/unique_vector.h"
......@@ -180,13 +179,8 @@ bool FilterPatternsFromString(const BuildSettings* build_settings,
//
// The vector will be modified so that only the printed targets will remain.
void FilterAndPrintTargets(bool indent, std::vector<const Target*>* targets);
void FilterAndPrintTargets(std::vector<const Target*>* targets,
base::ListValue* out);
void FilterAndPrintTargetSet(bool indent,
const std::set<const Target*>& targets);
void FilterAndPrintTargetSet(const std::set<const Target*>& targets,
base::ListValue* out);
// Extra help from command_check.cc
extern const char kNoGnCheck_Help[];
......
This diff is collapsed.
// Copyright (c) 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.
#ifndef TOOLS_GN_DESC_BUILDER_H_
#define TOOLS_GN_DESC_BUILDER_H_
#include "base/values.h"
#include "tools/gn/target.h"
class DescBuilder {
public:
// Creates Dictionary representation for given target
static std::unique_ptr<base::DictionaryValue> DescriptionForTarget(
const Target* target,
const std::string& what,
bool all,
bool tree,
bool blame);
// Creates Dictionary representation for given config
static std::unique_ptr<base::DictionaryValue> DescriptionForConfig(
const Config* config,
const std::string& what);
};
#endif
// Copyright (c) 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/json_project_writer.h"
#include <iostream>
#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "tools/gn/builder.h"
#include "tools/gn/commands.h"
#include "tools/gn/deps_iterator.h"
#include "tools/gn/desc_builder.h"
#include "tools/gn/exec_process.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/settings.h"
// Structure of JSON output file
// {
// "build_settings" = {
// "root_path" : "absolute path of project root",
// "build_dir" : "build directory (project relative)",
// "default_toolchain" : "name of default toolchain"
// }
// "targets" = {
// "target x name" : { target x properties },
// "target y name" : { target y properties },
// ...
// }
// }
// See desc_builder.cc for overview of target properties
namespace {
void AddTargetDependencies(const Target* target,
std::set<const Target*>* deps) {
for (const auto& pair : target->GetDeps(Target::DEPS_LINKED)) {
if (deps->find(pair.ptr) == deps->end()) {
deps->insert(pair.ptr);
AddTargetDependencies(pair.ptr, deps);
}
}
}
// Filters targets according to filter string; Will also recursively
// add dependent targets.
bool FilterTargets(const BuildSettings* build_settings,
std::vector<const Target*>& all_targets,
std::vector<const Target*>* targets,
const std::string& dir_filter_string,
Err* err) {
if (dir_filter_string.empty()) {
*targets = all_targets;
} else {
targets->reserve(all_targets.size());
std::vector<LabelPattern> filters;
if (!commands::FilterPatternsFromString(build_settings, dir_filter_string,
&filters, err)) {
return false;
}
commands::FilterTargetsByPatterns(all_targets, filters, targets);
std::set<const Target*> target_set(targets->begin(), targets->end());
for (const auto* target : *targets)
AddTargetDependencies(target, &target_set);
targets->clear();
targets->insert(targets->end(), target_set.begin(), target_set.end());
}
// Sort the list of targets per-label to get a consistent ordering of them
// in the generated project (and thus stability of the file generated).
std::sort(targets->begin(), targets->end(),
[](const Target* a, const Target* b) {
return a->label().name() < b->label().name();
});
return true;
}
std::string RenderJSON(const BuildSettings* build_settings,
const Builder* builder,
std::vector<const Target*>& all_targets) {
Label default_toolchain_label;
auto targets = base::WrapUnique(new base::DictionaryValue());
for (const auto* target : all_targets) {
if (default_toolchain_label.is_null())
default_toolchain_label = target->settings()->default_toolchain_label();
auto description =
DescBuilder::DescriptionForTarget(target, "", false, false, false);
// Outputs need to be asked for separately.
auto outputs = DescBuilder::DescriptionForTarget(target, "source_outputs",
false, false, false);
base::DictionaryValue* outputs_value = nullptr;
if (outputs->GetDictionary("source_outputs", &outputs_value) &&
!outputs_value->empty()) {
description->MergeDictionary(outputs.get());
}
targets->Set(target->label().GetUserVisibleName(default_toolchain_label),
std::move(description));
}
auto settings = base::WrapUnique(new base::DictionaryValue());
settings->SetString("root_path", build_settings->root_path_utf8());
settings->SetString("build_dir", build_settings->build_dir().value());
settings->SetString("default_toolchain",
default_toolchain_label.GetUserVisibleName(false));
auto output = base::WrapUnique(new base::DictionaryValue());
output->Set("targets", std::move(targets));
output->Set("build_settings", std::move(settings));
std::string s;
base::JSONWriter::WriteWithOptions(
*output.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &s);
return s;
}
bool InvokePython(const BuildSettings* build_settings,
const base::FilePath& python_script_path,
const std::string& python_script_extra_args,
const base::FilePath& output_path,
bool quiet,
Err* err) {
const base::FilePath& python_path = build_settings->python_path();
base::CommandLine cmdline(python_path);
cmdline.AppendArg("--");
cmdline.AppendArgPath(python_script_path);
cmdline.AppendArgPath(output_path);
if (!python_script_extra_args.empty()) {
cmdline.AppendArg(python_script_extra_args);
}
base::FilePath startup_dir =
build_settings->GetFullPath(build_settings->build_dir());
std::string output;
std::string stderr_output;
int exit_code = 0;
if (!internal::ExecProcess(cmdline, startup_dir, &output, &stderr_output,
&exit_code)) {
*err =
Err(Location(), "Could not execute python.",
"I was trying to execute \"" + FilePathToUTF8(python_path) + "\".");
return false;
}
if (!quiet) {
std::cout << output;
std::cerr << stderr_output;
}
if (exit_code != 0) {
*err = Err(Location(), "Python has quit with exit code " +
base::IntToString(exit_code) + ".");
return false;
}
return true;
}
} // namespace
bool JSONProjectWriter::RunAndWriteFiles(
const BuildSettings* build_settings,
const Builder* builder,
const std::string& file_name,
const std::string& exec_script,
const std::string& exec_script_extra_args,
const std::string& dir_filter_string,
bool quiet,
Err* err) {
SourceFile output_file = build_settings->build_dir().ResolveRelativeFile(
Value(nullptr, file_name), err);
if (output_file.is_null()) {
return false;
}
base::FilePath output_path = build_settings->GetFullPath(output_file);
std::vector<const Target*> all_targets = builder->GetAllResolvedTargets();
std::vector<const Target*> targets;
if (!FilterTargets(build_settings, all_targets, &targets, dir_filter_string,
err)) {
return false;
}
std::string json = RenderJSON(build_settings, builder, targets);
if (!ContentsEqual(output_path, json)) {
if (!WriteFileIfChanged(output_path, json, err)) {
return false;
}
if (!exec_script.empty()) {
SourceFile script_file;
if (exec_script[0] != '/') {
// Relative path, assume the base is in build_dir.
script_file = build_settings->build_dir().ResolveRelativeFile(
Value(nullptr, exec_script), err);
if (script_file.is_null()) {
return false;
}
} else {
script_file = SourceFile(exec_script);
}
base::FilePath script_path = build_settings->GetFullPath(script_file);
return InvokePython(build_settings, script_path, exec_script_extra_args,
output_path, quiet, err);
}
}
return true;
}
// Copyright (c) 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.
#ifndef TOOLS_GN_JSON_WRITER_H_
#define TOOLS_GN_JSON_WRITER_H_
#include "tools/gn/err.h"
#include "tools/gn/target.h"
class Builder;
class BuildSettings;
class JSONProjectWriter {
public:
static bool RunAndWriteFiles(const BuildSettings* build_setting,
const Builder* builder,
const std::string& file_name,
const std::string& exec_script,
const std::string& exec_script_extra_args,
const std::string& dir_filter_string,
bool quiet,
Err* err);
};
#endif
......@@ -14,7 +14,6 @@
#include "tools/gn/config_values_extractors.h"
#include "tools/gn/deps_iterator.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/functions.h"
#include "tools/gn/scheduler.h"
#include "tools/gn/source_file_type.h"
#include "tools/gn/substitution_writer.h"
......@@ -216,29 +215,29 @@ Target::~Target() {
const char* Target::GetStringForOutputType(OutputType type) {
switch (type) {
case UNKNOWN:
return "unknown";
return "Unknown";
case GROUP:
return functions::kGroup;
return "Group";
case EXECUTABLE:
return functions::kExecutable;
return "Executable";
case LOADABLE_MODULE:
return functions::kLoadableModule;
return "Loadable module";
case SHARED_LIBRARY:
return functions::kSharedLibrary;
return "Shared library";
case STATIC_LIBRARY:
return functions::kStaticLibrary;
return "Static library";
case SOURCE_SET:
return functions::kSourceSet;
return "Source set";
case COPY_FILES:
return functions::kCopy;
return "Copy";
case ACTION:
return functions::kAction;
return "Action";
case ACTION_FOREACH:
return functions::kActionForEach;
return "ActionForEach";
case BUNDLE_DATA:
return functions::kBundleData;
return "Bundle data";
case CREATE_BUNDLE:
return functions::kCreateBundle;
return "Create bundle";
default:
return "";
}
......
......@@ -4,10 +4,8 @@
#include "tools/gn/visibility.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "tools/gn/err.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/item.h"
......@@ -85,14 +83,6 @@ std::string Visibility::Describe(int indent, bool include_brackets) const {
return result;
}
std::unique_ptr<base::Value> Visibility::AsValue() const {
auto* res = new base::ListValue();
for (const auto& pattern : patterns_)
res->AppendString(pattern.Describe());
return WrapUnique(res);
}
// static
bool Visibility::CheckItemVisibility(const Item* from,
const Item* to,
......@@ -103,7 +93,7 @@ bool Visibility::CheckItemVisibility(const Item* from,
"The item " + from->label().GetUserVisibleName(false) + "\n"
"can not depend on " + to_label + "\n"
"because it is not in " + to_label + "'s visibility list: " +
to->visibility().Describe(0, true));
to->visibility().Describe(0, true));
return false;
}
return true;
......
......@@ -5,17 +5,12 @@
#ifndef TOOLS_GN_VISIBILITY_H_
#define TOOLS_GN_VISIBILITY_H_
#include <memory>
#include <vector>
#include "base/macros.h"
#include "tools/gn/label_pattern.h"
#include "tools/gn/source_dir.h"
namespace base {
class Value;
}
class Err;
class Item;
class Label;
......@@ -48,9 +43,6 @@ class Visibility {
// result will end in a newline.
std::string Describe(int indent, bool include_brackets) const;
// Returns value representation of this visibility
std::unique_ptr<base::Value> AsValue() const;
// Helper function to check visibility between the given two items. If
// to is invisible to from, returns false and sets the error.
static bool CheckItemVisibility(const Item* from, const Item* to, Err* err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment