Migrate Tulsi to use the new provider style to access Objc
This will fix support for the new Starlark objc_proto_library
PiperOrigin-RevId: 254424707
diff --git a/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl b/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
index eba0e5d..7267a52 100644
--- a/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
+++ b/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
@@ -27,6 +27,8 @@
)
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
+ObjcInfo = apple_common.Objc
+
# Defensive list of features that can appear in the C++ toolchain, but that we
# definitely don't want to enable (meaning we don't want them to contribute
# command line flags).
@@ -439,6 +441,10 @@
]
return [dep.label for dep in deps if hasattr(dep, "label")]
+def _get_opt_provider(target, provider):
+ """Returns the given provider on target, if present."""
+ return target[provider] if provider in target else None
+
def _get_opt_attr(obj, attr_path):
"""Returns the value at attr_path on the given object if it is set."""
attr_path = attr_path.split(".")
@@ -564,7 +570,7 @@
def _extract_generated_sources(target):
"""Returns (source_metadatas, includes) generated by the given target."""
file_metadatas = []
- objc_provider = _get_opt_attr(target, "objc")
+ objc_provider = _get_opt_provider(target, ObjcInfo)
if hasattr(objc_provider, "source") and hasattr(objc_provider, "header"):
all_files = depset(transitive = [objc_provider.source, objc_provider.header])
file_metadatas = _depset_to_file_metadata_list(all_files)
@@ -619,9 +625,9 @@
def _collect_module_maps(target, rule_attr):
"""Returns a depset of Clang module maps found on the given target."""
- if SwiftInfo in target and apple_common.Objc in target:
+ if SwiftInfo in target and ObjcInfo in target:
depsets = []
- objc = target[apple_common.Objc]
+ objc = target[ObjcInfo]
if hasattr(objc, "module_map"):
depsets.append(objc.module_map)
@@ -648,8 +654,8 @@
# swift_* targets put the generated header into their objc provider HEADER
# field.
- if SwiftInfo in target and apple_common.Objc in target:
- return target[apple_common.Objc].header
+ if SwiftInfo in target and ObjcInfo in target:
+ return target[ObjcInfo].header
return depset()
def _target_filtering_info(ctx):
@@ -805,7 +811,7 @@
all_attributes.update(inheritable_attributes)
all_attributes.update(transitive_attributes)
- objc_provider = _get_opt_attr(target, "objc")
+ objc_provider = _get_opt_provider(target, ObjcInfo)
objc_defines = []
target_includes = []
@@ -1051,7 +1057,7 @@
# Collect generated files for bazel_build.py to copy under Tulsi root.
all_files_depsets = []
if target_kind in _SOURCE_GENERATING_RULES + _NON_ARC_SOURCE_GENERATING_RULES:
- objc_provider = _get_opt_attr(target, "objc")
+ objc_provider = _get_opt_provider(target, ObjcInfo)
if hasattr(objc_provider, "source") and hasattr(objc_provider, "header"):
all_files_depsets.append(objc_provider.source)
all_files_depsets.append(objc_provider.header)
diff --git a/src/TulsiGeneratorIntegrationTests/Resources/GoldenProjects/SwiftProject.xcodeproj/project.pbxproj b/src/TulsiGeneratorIntegrationTests/Resources/GoldenProjects/SwiftProject.xcodeproj/project.pbxproj
index 47136da..500d003 100644
--- a/src/TulsiGeneratorIntegrationTests/Resources/GoldenProjects/SwiftProject.xcodeproj/project.pbxproj
+++ b/src/TulsiGeneratorIntegrationTests/Resources/GoldenProjects/SwiftProject.xcodeproj/project.pbxproj
@@ -466,7 +466,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_WR)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/ ";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ OTHER_CFLAGS = "-DLIBRARY_DEFINE_V3";
OTHER_SWIFT_FLAGS = "$(inherited) -swift-version 3 -DLIBRARY_DEFINE_V3";
PRODUCT_NAME = _idx_SwiftLibraryV3_46A0CA4F_ios_min10.0;
SDKROOT = iphoneos;
@@ -478,7 +480,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_WR)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/ ";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ OTHER_CFLAGS = "-DLIBRARY_DEFINE_V4";
OTHER_SWIFT_FLAGS = "$(inherited) -swift-version 4 -DLIBRARY_DEFINE_V4";
PRODUCT_NAME = _idx_SwiftLibraryV4_B3719410_ios_min10.0;
SDKROOT = iphoneos;
@@ -490,8 +494,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
- HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_BWRS)/_tulsi-includes/x/x/tulsi_e2e_swift/SubSwiftLibrary.modulemaps ";
+ HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_WR)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/tulsi_e2e_swift/SubSwiftLibrary.modulemaps ";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ OTHER_CFLAGS = "-DLIBRARY_DEFINE -DSUB_LIBRARY_DEFINE";
OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(TULSI_BWRS)/_tulsi-includes/x/x/tulsi_e2e_swift/SubSwiftLibrary.modulemaps/module.modulemap -DSUB_LIBRARY_DEFINE -DLIBRARY_DEFINE";
PRODUCT_NAME = _idx_SwiftLibrary_77A8D266_ios_min10.0;
SDKROOT = iphoneos;
@@ -557,7 +562,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1";
+ HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_WR)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/ ";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ OTHER_CFLAGS = "-DLIBRARY_DEFINE_V3";
OTHER_SWIFT_FLAGS = "$(inherited) -swift-version 3 -DLIBRARY_DEFINE_V3";
PRODUCT_NAME = _idx_SwiftLibraryV3_46A0CA4F_ios_min10.0;
SDKROOT = iphoneos;
@@ -569,7 +576,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1";
+ HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_WR)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/ ";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ OTHER_CFLAGS = "-DLIBRARY_DEFINE_V4";
OTHER_SWIFT_FLAGS = "$(inherited) -swift-version 4 -DLIBRARY_DEFINE_V4";
PRODUCT_NAME = _idx_SwiftLibraryV4_B3719410_ios_min10.0;
SDKROOT = iphoneos;
@@ -581,8 +590,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1";
- HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_BWRS)/_tulsi-includes/x/x/tulsi_e2e_swift/SubSwiftLibrary.modulemaps ";
+ HEADER_SEARCH_PATHS = "$(inherited) $(TULSI_WR)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/ $(TULSI_BWRS)/_tulsi-includes/x/x/tulsi_e2e_swift/SubSwiftLibrary.modulemaps ";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
+ OTHER_CFLAGS = "-DLIBRARY_DEFINE -DSUB_LIBRARY_DEFINE";
OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fmodule-map-file=$(TULSI_BWRS)/_tulsi-includes/x/x/tulsi_e2e_swift/SubSwiftLibrary.modulemaps/module.modulemap -DSUB_LIBRARY_DEFINE -DLIBRARY_DEFINE";
PRODUCT_NAME = _idx_SwiftLibrary_77A8D266_ios_min10.0;
SDKROOT = iphoneos;