From 7087b58281c3d9e8e98d7078ba1b205e669993ae Mon Sep 17 00:00:00 2001 From: Sergey Khliustin Date: Fri, 15 Jul 2022 14:14:02 +0200 Subject: [PATCH] Fixed duplicates in `srcs` when subspecs contain overlapping sources --- lib/cocoapods/bazel/target.rb | 8 +- spec/integration.rb | 1 + .../Frameworks/DuplicatedSrcs/BUILD.bazel | 85 ++++++++++++++++++ .../Frameworks/DuplicatedSrcs/App/main.swift | 1 + .../DuplicatedSrcs/DuplicatedSrcs.podspec | 51 +++++++++++ .../Sources/Internal/a_Internal.h | 1 + .../Frameworks/DuplicatedSrcs/Sources/a.h | 1 + .../Frameworks/DuplicatedSrcs/Sources/a.m | 1 + .../Frameworks/DuplicatedSrcs/Sources/a.swift | 1 + .../Frameworks/DuplicatedSrcs/Sources/b.swift | 1 + .../Frameworks/DuplicatedSrcs/Tests/aTests.m | 0 .../DuplicatedSrcs/Tests/a_tests.swift | 0 .../Frameworks/DuplicatedSrcs/BUILD.bazel | 90 +++++++++++++++++++ .../Frameworks/DuplicatedSrcs/App/main.swift | 1 + .../DuplicatedSrcs/DuplicateSrcs.podspec | 51 +++++++++++ .../Sources/Internal/a_Internal.h | 1 + .../Frameworks/DuplicatedSrcs/Sources/a.h | 1 + .../Frameworks/DuplicatedSrcs/Sources/a.m | 1 + .../Frameworks/DuplicatedSrcs/Sources/a.swift | 1 + .../Frameworks/DuplicatedSrcs/Sources/b.swift | 1 + .../Frameworks/DuplicatedSrcs/Tests/aTests.m | 0 .../DuplicatedSrcs/Tests/a_tests.swift | 0 22 files changed, 294 insertions(+), 4 deletions(-) create mode 100644 spec/integration/experimental_features/after/Frameworks/DuplicatedSrcs/BUILD.bazel create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/App/main.swift create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/DuplicatedSrcs.podspec create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.h create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.m create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.swift create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/b.swift create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Tests/aTests.m create mode 100644 spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Tests/a_tests.swift create mode 100644 spec/integration/monorepo/after/Frameworks/DuplicatedSrcs/BUILD.bazel create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/App/main.swift create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/DuplicateSrcs.podspec create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.h create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.m create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.swift create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/b.swift create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Tests/aTests.m create mode 100644 spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Tests/a_tests.swift diff --git a/lib/cocoapods/bazel/target.rb b/lib/cocoapods/bazel/target.rb index 37c10a4..93b3aac 100644 --- a/lib/cocoapods/bazel/target.rb +++ b/lib/cocoapods/bazel/target.rb @@ -330,10 +330,10 @@ def to_rule_kwargs end return [] if h.empty? - h.map do |excludes, globs| - excludes = excludes.empty? ? {} : { exclude: excludes.flat_map(&method(:expand_glob)) } - starlark { function_call(:glob, globs.uniq, **excludes) } - end.reduce(&:+) + globs = h.values.reduce(:+).uniq + excludes = h.keys.reduce(:+).uniq + excludes = excludes.empty? ? {} : { exclude: excludes.flat_map(&method(:expand_glob)) } + starlark { function_call(:glob, globs, **excludes) } end kwargs[:srcs] = m[srcs] diff --git a/spec/integration.rb b/spec/integration.rb index 8b9d1bb..c9c1349 100644 --- a/spec/integration.rb +++ b/spec/integration.rb @@ -71,6 +71,7 @@ def match(path) c.temp_path = c.spec_path + 'tmp' c.ignores BuildFileMatcher.new('_unused') + c.include_hidden_files = false c.hook_into :bacon end diff --git a/spec/integration/experimental_features/after/Frameworks/DuplicatedSrcs/BUILD.bazel b/spec/integration/experimental_features/after/Frameworks/DuplicatedSrcs/BUILD.bazel new file mode 100644 index 0000000..bc81bdd --- /dev/null +++ b/spec/integration/experimental_features/after/Frameworks/DuplicatedSrcs/BUILD.bazel @@ -0,0 +1,85 @@ +load("@build_bazel_rules_ios//rules:app.bzl", "ios_application") +load("@build_bazel_rules_ios//rules:framework.bzl", "apple_framework") +load("@build_bazel_rules_ios//rules:test.bzl", "ios_unit_test") + +apple_framework( + name = "DuplicatedSrcs", + srcs = glob( + [ + "Sources/**/*.h", + "Sources/**/*.m", + "Sources/**/*.swift", + ], + exclude = [ + "Sources/a.swift", + "Sources/b.swift", + ], + ), + infoplists = [{"CFBundleShortVersionString": "1.0.0"}], + platforms = {"ios": "11.0"}, + private_headers = glob( + ["Sources/Internal/**/*.h"], + exclude = [ + "Sources/a.swift", + "Sources/b.swift", + "Sources/a.swift", + ], + ), + swift_version = "5.2", + visibility = ["//visibility:public"], +) + +ios_unit_test( + name = "DuplicatedSrcs-Unit-Tests", + srcs = glob([ + "Tests/**/*.h", + "Tests/**/*.m", + "Tests/**/*.swift", + ]), + minimum_os_version = "11.0", + module_name = "DuplicatedSrcs_Unit_Tests", + swift_version = "5.2", + deps = [":DuplicatedSrcs"], +) + +ios_application( + name = "DuplicatedSrcs-App", + srcs = glob([ + "App/**/*.h", + "App/**/*.m", + "App/**/*.swift", + ]), + bundle_id = "org.cocoapods.DuplicatedSrcs-App", + families = [ + "iphone", + "ipad", + ], + linkopts = ["-all_load"], + minimum_os_version = "11.0", + module_name = "DuplicatedSrcs_App", + objc_copts = [ + "-Wno-conversion", + "-Wno-error=at-protocol", + "-I/Headers/Private", + ], + swift_copts = [ + "-DDEBUG", + "-Xcc", + "-I/Headers/Private", + ], + swift_version = "5.2", + xcconfig = { + "ARCHS": [ + "arm64", + "x86", + ], + "VERSIONING_SYSTEM": "apple-generic", + "SWIFT_OPTIMIZATION_LEVEL_Debug": "-Onone", + "SWIFT_OPTIMIZATION_LEVEL_Release": "-Owholemodule", + }, + xcconfig_by_build_setting = { + "//Pods/cocoapods-bazel:debug": {"SWIFT_OPTIMIZATION_LEVEL": "-Onone"}, + "//Pods/cocoapods-bazel:release": {"SWIFT_OPTIMIZATION_LEVEL": "-Owholemodule"}, + }, + deps = [":DuplicatedSrcs"], +) diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/App/main.swift b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/App/main.swift new file mode 100644 index 0000000..3186612 --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/App/main.swift @@ -0,0 +1 @@ +func main() {} diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/DuplicatedSrcs.podspec b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/DuplicatedSrcs.podspec new file mode 100644 index 0000000..77d098d --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/DuplicatedSrcs.podspec @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +Pod::Spec.new do |s| + s.name = 'DuplicatedSrcs' + s.version = '1.0.0.LOCAL' + + s.authors = %w[Square] + s.homepage = 'https://github.com/Square/cocoapods-generate' + s.source = { git: 'https://github.com/Square/cocoapods-generate' } + s.summary = 'Testing pod' + + s.swift_versions = %w[5.2] + s.ios.deployment_target = '11.0' + + s.source_files = 'Sources/**/*.{h,m,swift}' + s.private_header_files = 'Sources/Internal/**/*.h' + + s.info_plist = { + 'CFBundleShortVersionString' => '1.0.0' + } + + s.test_spec 'Tests' do |ts| + ts.source_files = 'Tests/**/*.{h,m,swift}' + end + + s.subspec 'Sub' do |subsp| + subsp.source_files = 'Sources/**/*.{h,m,swift}' + subsp.exclude_files = 'Sources/a.swift', 'Sources/b.swift' + end + + s.subspec 'Sub2' do |subsp| + subsp.source_files = 'Sources/**/*.{h,m,swift}' + subsp.exclude_files = 'Sources/a.swift' + end + + s.app_spec 'App' do |as| + as.source_files = 'App/**/*.{h,m,swift}' + + as.pod_target_xcconfig = { + 'ARCHS' => 'arm64 x86', + 'HEADER_SEARCH_PATHS'=> "${PODS_ROOT}/Headers/Private", + 'OTHER_CFLAGS' => '-Wno-conversion -Wno-error=at-protocol', + 'OTHER_LDFLAGS' => '-all_load', + 'OTHER_SWIFT_FLAGS' => '-DDEBUG', + 'VERSIONING_SYSTEM' => 'apple-generic', + 'SWIFT_OPTIMIZATION_LEVEL' => "$(SWIFT_OPTIMIZATION_LEVEL_$(CONFIGURATION))", + 'SWIFT_OPTIMIZATION_LEVEL_Debug' => '-Onone', + 'SWIFT_OPTIMIZATION_LEVEL_Release' => '-Owholemodule' + } + end +end diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h new file mode 100644 index 0000000..0c722f4 --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h @@ -0,0 +1 @@ +// a Internal header \ No newline at end of file diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.h b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.h new file mode 100644 index 0000000..3d9be43 --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.h @@ -0,0 +1 @@ +// a Header \ No newline at end of file diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.m b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.m new file mode 100644 index 0000000..1b42921 --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.m @@ -0,0 +1 @@ +// a Implementation \ No newline at end of file diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.swift b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.swift new file mode 100644 index 0000000..75155e2 --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/a.swift @@ -0,0 +1 @@ +// a Swift \ No newline at end of file diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/b.swift b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/b.swift new file mode 100644 index 0000000..fac62e9 --- /dev/null +++ b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Sources/b.swift @@ -0,0 +1 @@ +// b Swift \ No newline at end of file diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Tests/aTests.m b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Tests/aTests.m new file mode 100644 index 0000000..e69de29 diff --git a/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Tests/a_tests.swift b/spec/integration/experimental_features/before/Frameworks/DuplicatedSrcs/Tests/a_tests.swift new file mode 100644 index 0000000..e69de29 diff --git a/spec/integration/monorepo/after/Frameworks/DuplicatedSrcs/BUILD.bazel b/spec/integration/monorepo/after/Frameworks/DuplicatedSrcs/BUILD.bazel new file mode 100644 index 0000000..afd4c67 --- /dev/null +++ b/spec/integration/monorepo/after/Frameworks/DuplicatedSrcs/BUILD.bazel @@ -0,0 +1,90 @@ +""" +Test docstring +that takes two lines +""" + +load("@build_bazel_rules_ios//rules:app.bzl", "ios_application") +load("@build_bazel_rules_ios//rules:framework.bzl", "apple_framework") +load("@build_bazel_rules_ios//rules:test.bzl", "ios_unit_test") + +apple_framework( + name = "DuplicatedSrcs", + srcs = glob( + [ + "Sources/**/*.h", + "Sources/**/*.m", + "Sources/**/*.swift", + ], + exclude = [ + "Sources/a.swift", + "Sources/b.swift", + ], + ), + infoplists = [{"CFBundleShortVersionString": "1.0.0"}], + platforms = {"ios": "11.0"}, + private_headers = glob( + ["Sources/Internal/**/*.h"], + exclude = [ + "Sources/a.swift", + "Sources/b.swift", + "Sources/a.swift", + ], + ), + swift_version = "5.2", + visibility = ["//visibility:public"], +) + +ios_unit_test( + name = "DuplicatedSrcs-Unit-Tests", + srcs = glob([ + "Tests/**/*.h", + "Tests/**/*.m", + "Tests/**/*.swift", + ]), + minimum_os_version = "11.0", + module_name = "DuplicatedSrcs_Unit_Tests", + swift_version = "5.2", + deps = [":DuplicatedSrcs"], +) + +ios_application( + name = "DuplicatedSrcs-App", + srcs = glob([ + "App/**/*.h", + "App/**/*.m", + "App/**/*.swift", + ]), + bundle_id = "org.cocoapods.DuplicatedSrcs-App", + families = [ + "iphone", + "ipad", + ], + linkopts = ["-all_load"], + minimum_os_version = "11.0", + module_name = "DuplicatedSrcs_App", + objc_copts = [ + "-Wno-conversion", + "-Wno-error=at-protocol", + "-I/Headers/Private", + ], + swift_copts = [ + "-DDEBUG", + "-Xcc", + "-I/Headers/Private", + ], + swift_version = "5.2", + xcconfig = { + "ARCHS": [ + "arm64", + "x86", + ], + "VERSIONING_SYSTEM": "apple-generic", + "SWIFT_OPTIMIZATION_LEVEL_Debug": "-Onone", + "SWIFT_OPTIMIZATION_LEVEL_Release": "-Owholemodule", + }, + xcconfig_by_build_setting = { + "//Pods/cocoapods-bazel:debug": {"SWIFT_OPTIMIZATION_LEVEL": "-Onone"}, + "//Pods/cocoapods-bazel:release": {"SWIFT_OPTIMIZATION_LEVEL": "-Owholemodule"}, + }, + deps = [":DuplicatedSrcs"], +) diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/App/main.swift b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/App/main.swift new file mode 100644 index 0000000..3186612 --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/App/main.swift @@ -0,0 +1 @@ +func main() {} diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/DuplicateSrcs.podspec b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/DuplicateSrcs.podspec new file mode 100644 index 0000000..77d098d --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/DuplicateSrcs.podspec @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +Pod::Spec.new do |s| + s.name = 'DuplicatedSrcs' + s.version = '1.0.0.LOCAL' + + s.authors = %w[Square] + s.homepage = 'https://github.com/Square/cocoapods-generate' + s.source = { git: 'https://github.com/Square/cocoapods-generate' } + s.summary = 'Testing pod' + + s.swift_versions = %w[5.2] + s.ios.deployment_target = '11.0' + + s.source_files = 'Sources/**/*.{h,m,swift}' + s.private_header_files = 'Sources/Internal/**/*.h' + + s.info_plist = { + 'CFBundleShortVersionString' => '1.0.0' + } + + s.test_spec 'Tests' do |ts| + ts.source_files = 'Tests/**/*.{h,m,swift}' + end + + s.subspec 'Sub' do |subsp| + subsp.source_files = 'Sources/**/*.{h,m,swift}' + subsp.exclude_files = 'Sources/a.swift', 'Sources/b.swift' + end + + s.subspec 'Sub2' do |subsp| + subsp.source_files = 'Sources/**/*.{h,m,swift}' + subsp.exclude_files = 'Sources/a.swift' + end + + s.app_spec 'App' do |as| + as.source_files = 'App/**/*.{h,m,swift}' + + as.pod_target_xcconfig = { + 'ARCHS' => 'arm64 x86', + 'HEADER_SEARCH_PATHS'=> "${PODS_ROOT}/Headers/Private", + 'OTHER_CFLAGS' => '-Wno-conversion -Wno-error=at-protocol', + 'OTHER_LDFLAGS' => '-all_load', + 'OTHER_SWIFT_FLAGS' => '-DDEBUG', + 'VERSIONING_SYSTEM' => 'apple-generic', + 'SWIFT_OPTIMIZATION_LEVEL' => "$(SWIFT_OPTIMIZATION_LEVEL_$(CONFIGURATION))", + 'SWIFT_OPTIMIZATION_LEVEL_Debug' => '-Onone', + 'SWIFT_OPTIMIZATION_LEVEL_Release' => '-Owholemodule' + } + end +end diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h new file mode 100644 index 0000000..0c722f4 --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/Internal/a_Internal.h @@ -0,0 +1 @@ +// a Internal header \ No newline at end of file diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.h b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.h new file mode 100644 index 0000000..3d9be43 --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.h @@ -0,0 +1 @@ +// a Header \ No newline at end of file diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.m b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.m new file mode 100644 index 0000000..1b42921 --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.m @@ -0,0 +1 @@ +// a Implementation \ No newline at end of file diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.swift b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.swift new file mode 100644 index 0000000..75155e2 --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/a.swift @@ -0,0 +1 @@ +// a Swift \ No newline at end of file diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/b.swift b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/b.swift new file mode 100644 index 0000000..fac62e9 --- /dev/null +++ b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Sources/b.swift @@ -0,0 +1 @@ +// b Swift \ No newline at end of file diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Tests/aTests.m b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Tests/aTests.m new file mode 100644 index 0000000..e69de29 diff --git a/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Tests/a_tests.swift b/spec/integration/monorepo/before/Frameworks/DuplicatedSrcs/Tests/a_tests.swift new file mode 100644 index 0000000..e69de29