From d900d54d60a256d2d2859d029c300e6d9dd61e22 Mon Sep 17 00:00:00 2001 From: Rumou Duan Date: Fri, 2 Oct 2015 20:12:27 +0000 Subject: Add imported static libraries to the list of libraries to link, instead of specifying them as linker flags, and also add their associated library search paths. This makes sure the link order for libraries is consistent with Bazel build. -- MOS_MIGRATED_REVID=104524532 --- .../build/xcode/xcodegen/XcodeprojGeneration.java | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/objc_tools') diff --git a/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java b/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java index 198d4f991b..b0ed080222 100644 --- a/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java +++ b/src/objc_tools/xcodegen/java/com/google/devtools/build/xcode/xcodegen/XcodeprojGeneration.java @@ -331,6 +331,18 @@ public class XcodeprojGeneration { return (NSArray) NSObject.wrap(result.build().asList()); } + /** + * Returns the {@code LIBRARY_SEARCH_PATHS} array for a target's imported static libraries. + */ + private static NSArray librarySearchPaths(Iterable importedLibraries) { + ImmutableSet.Builder result = new ImmutableSet.Builder<>(); + for (String importedLibrary : importedLibraries) { + result.add(new NSString("$(WORKSPACE_ROOT)/" + Paths.get(importedLibrary).getParent())); + } + + return (NSArray) NSObject.wrap(result.build().asList()); + } + /** * Returns the {@code ARCHS} array for a target's build config given the list of architecture * strings. If none is given, an array with default architectures "armv7" and "arm64" will be @@ -364,11 +376,6 @@ public class XcodeprojGeneration { Iterable givenFlags = targetControl.getLinkoptList(); ImmutableList.Builder flags = new ImmutableList.Builder<>(); flags.addAll(givenFlags); - if (!Equaling.of(ProductType.STATIC_LIBRARY, productType(targetControl))) { - for (String importedLibrary : targetControl.getImportedLibraryList()) { - flags.add("$(WORKSPACE_ROOT)/" + importedLibrary); - } - } if (Containing.item(PRODUCT_TYPES_THAT_HAVE_A_BINARY, productType(targetControl))) { for (String dylib : targetControl.getSdkDylibList()) { if (dylib.startsWith("lib")) { @@ -513,6 +520,11 @@ public class XcodeprojGeneration { targetBuildConfigMap.put(name, value); } + if (!Equaling.of(ProductType.STATIC_LIBRARY, productType(targetControl))) { + targetBuildConfigMap.put("LIBRARY_SEARCH_PATHS", + librarySearchPaths(targetControl.getImportedLibraryList())); + } + // Note that HFS+ (the Mac filesystem) is usually case insensitive, so we cast all target // names to lower case before checking for duplication because otherwise users may end up // having duplicated intermediate build directories that can interfere with the build. @@ -586,9 +598,18 @@ public class XcodeprojGeneration { Iterables.addAll(project.getMainGroup().getChildren(), processedProjectFiles); for (TargetInfo targetInfo : targetInfoByLabel.values()) { - for (DependencyControl dependency : targetInfo.control.getDependencyList()) { + TargetControl targetControl = targetInfo.control; + for (DependencyControl dependency : targetControl.getDependencyList()) { targetInfo.addDependencyInfo(dependency, targetInfoByLabel); } + + if (!Equaling.of(ProductType.STATIC_LIBRARY, productType(targetControl))) { + for (String importedLibrary : targetControl.getImportedLibraryList()) { + FileReference fileReference = FileReference.of(importedLibrary, SourceTree.GROUP) + .withExplicitFileType(FILE_TYPE_ARCHIVE_LIBRARY); + targetInfo.frameworksPhase.getFiles().add(pbxBuildFiles.getStandalone(fileReference)); + } + } } return project; -- cgit v1.2.3