// Copyright 2014 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.xcode.xcodegen; import com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile; import com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference; import com.facebook.buck.apple.xcode.xcodeproj.PBXReference; import com.facebook.buck.apple.xcode.xcodeproj.PBXReference.SourceTree; import com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup; import com.facebook.buck.apple.xcode.xcodeproj.XCVersionGroup; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.SetMultimap; import com.google.devtools.build.xcode.util.Mapping; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; /** * A kind of cache which makes it easier to collect and manage PBXBuildFile and PBXReference * objects. It knows how to create new PBXBuildFile, PBXVariantGroup, and PBXFileReference objects * from {@link Path} objects and sequences thereof. *
* A PBXFileReference specifies a path to a file and its name. The name is confusingly * defined as the real file name for non-localized files (e.g. "foo" in "bar/foo"), and the language * name for localized files (e.g. "en" in "bar/en.lproj/foo"). *
* A PBXVariantGroup is a set of PBXFileReferences with the same file name (the virtual name). Each * file is in some directory named *.lproj. For instance, the following files would belong to the * same PBXVariantGroup: * *
* A PBXBuildFile is the simplest object - it is simply a reference to a PBXReference, which can be * either a PBXFileReference or PBXVariantGroup. The fact that PBXFileReference and PBXVariantGroup * are considered kinds of PBXReference is reflected in the Java inheritance hierarchy for the * classes that model these Xcode objects. *
* The PBXBuildFile is the object referred to in the build phases of targets, so it is seen as a * buildable or compilable unit. The PBXFileReference and PBXVariantGroup objects are referred to * by the PBXGroups, which define what is visible in the Project Navigator view in Xcode. *
* This class assumes that all paths given through the public API are specified relative to the * Xcodegen root, and creates PBXFileReferences that should be added to a group whose path is the * root. * TODO(bazel-team): Make this an immutable type, of which multiple instances are created as new * references and build files are added. The current API is side-effect-based and confusing. */ final class PBXBuildFiles implements HasProjectNavigatorFiles { /** * Map from Paths to the PBXBuildFile that encompasses all and only those Paths. Because the * {@link PBXBuildFile}s in this map encompass multiple files, their * {@link PBXBuildFile#getFileRef()} value is a {@link PBXVariantGroup} or {@link XCVersionGroup}. *
* Note that this Map reflects the intention of the API, namely that {"a"} does not map to the
* same thing as {"a", "b"}, and you cannot get a build file with only one of the corresponding
* files - you need the whole set.
*/
private Map