Index: tools/gn/xcode_writer.cc |
diff --git a/tools/gn/xcode_writer.cc b/tools/gn/xcode_writer.cc |
index 633a1c8db5ea35b354ff3bfb5297aa3c1628dae4..78125954ac133fd9cd30fb8eb72eace18dbf7a37 100644 |
--- a/tools/gn/xcode_writer.cc |
+++ b/tools/gn/xcode_writer.cc |
@@ -31,6 +31,10 @@ |
namespace { |
+using TargetToFileList = std::unordered_map<const Target*, Target::FileList>; |
+ |
+const char kEarlGreyFileNameIdentifier[] = "egtest.mm"; |
+ |
struct SafeEnvironmentVariableInfo { |
const char* name; |
bool capture_at_generation; |
@@ -86,6 +90,60 @@ std::string GetBuildScript(const std::string& target_name, |
return script.str(); |
} |
+// Searches the list of earl grey files recursively under |target|. |
+void SearchEarlGreyFiles(const Target* target, |
sdefresne
2016/12/21 12:46:07
Maybe we can make this a bit more general and look
liaoyuke
2016/12/21 18:25:18
Done.
|
+ TargetToFileList* eg_files_per_target) { |
+ // Early return if already visited and processed. |
+ if (eg_files_per_target->find(target) != eg_files_per_target->end()) |
+ return; |
+ |
+ Target::FileList eg_files; |
+ for (const SourceFile& file : target->sources()) { |
+ if (base::EndsWith(file.GetName(), kEarlGreyFileNameIdentifier, |
+ base::CompareCase::SENSITIVE)) { |
+ eg_files.push_back(file); |
+ } |
+ } |
+ |
+ // Call recursively on public and private deps. |
+ for (const auto& target : target->public_deps()) { |
+ SearchEarlGreyFiles(target.ptr, eg_files_per_target); |
+ const Target::FileList& deps_eg_files = (*eg_files_per_target)[target.ptr]; |
+ eg_files.insert(eg_files.end(), deps_eg_files.begin(), deps_eg_files.end()); |
+ } |
+ |
+ for (const auto& target : target->private_deps()) { |
+ SearchEarlGreyFiles(target.ptr, eg_files_per_target); |
+ const Target::FileList& deps_eg_files = (*eg_files_per_target)[target.ptr]; |
+ eg_files.insert(eg_files.end(), deps_eg_files.begin(), deps_eg_files.end()); |
+ } |
+ |
+ // Sort eg_files to remove duplicates. |
+ std::sort(eg_files.begin(), eg_files.end()); |
+ eg_files.erase(std::unique(eg_files.begin(), eg_files.end()), eg_files.end()); |
+ |
+ eg_files_per_target->insert(std::make_pair(target, eg_files)); |
+} |
+ |
+// Searches the list of earl grey files recursively under each of the |
+// application target. |
+void SearchEarlGreyFilesForAll( |
+ const std::vector<const Target*>& application_targets, |
+ std::vector<Target::FileList>* file_lists) { |
+ TargetToFileList eg_files_per_target; |
+ |
+ for (const Target* target : application_targets) { |
+ SearchEarlGreyFiles(target, &eg_files_per_target); |
+ file_lists->push_back(eg_files_per_target[target]); |
+ } |
+} |
+ |
+bool IsApplicationTarget(const Target* target) { |
+ return target->output_type() == Target::CREATE_BUNDLE && |
+ target->bundle_data().product_type() == |
+ "com.apple.product-type.application"; |
+} |
+ |
class CollectPBXObjectsPerClassHelper : public PBXObjectVisitor { |
public: |
CollectPBXObjectsPerClassHelper() {} |
@@ -266,6 +324,20 @@ bool XcodeWriter::FilterTargets(const BuildSettings* build_settings, |
return true; |
} |
+// static |
+void XcodeWriter::FilterApplicationTargets( |
+ const std::vector<const Target*>& targets, |
+ std::vector<const Target*>* application_targets) { |
+ // Filter out all targets of type CREATE_BUNDLE and whose bundle_data has |
+ // product_type: "com.apple.product-type.application". |
+ for (const Target* target : targets) { |
+ if (!IsApplicationTarget(target)) |
+ continue; |
+ |
+ application_targets->push_back(target); |
+ } |
+} |
+ |
void XcodeWriter::CreateProductsProject( |
const std::vector<const Target*>& targets, |
const PBXAttributes& attributes, |
@@ -278,6 +350,14 @@ void XcodeWriter::CreateProductsProject( |
std::unique_ptr<PBXProject> main_project( |
new PBXProject("products", config_name, source_path, attributes)); |
+ // Filter application targets and find list of earl grey test files |
+ // recursively under them. |
+ std::vector<const Target*> application_targets; |
+ std::vector<Target::FileList> earl_grey_file_lists; |
+ XcodeWriter::FilterApplicationTargets(targets, &application_targets); |
sdefresne
2016/12/21 12:46:07
Previously the code was doing:
1. look for all xc
liaoyuke
2016/12/21 18:25:19
Done.
|
+ SearchEarlGreyFilesForAll(application_targets, &earl_grey_file_lists); |
+ DCHECK_EQ(application_targets.size(), earl_grey_file_lists.size()); |
+ |
std::string build_path; |
std::unique_ptr<base::Environment> env(base::Environment::Create()); |