Bugfix and tests: otherCFlags should not discard duplicate flags

The otherCFlags param is a NSMutableOrderedSet while it should be NSMutableArray so that it does not mistakenly discard flags considering them duplicates.
Also added a Test for the same

Refer to issue: https://github.com/bazelbuild/tulsi/issues/75

\cc @DavidGoldman @reinhillmann @dierksen @ob

Change-Id: Ie2aef33fc54a0889e7a361b11076ecedb87e8b11

Closes #76.

PiperOrigin-RevId: 229754969
diff --git a/src/TulsiGenerator/PBXTargetGenerator.swift b/src/TulsiGenerator/PBXTargetGenerator.swift
index d9bf2d1..6300510 100644
--- a/src/TulsiGenerator/PBXTargetGenerator.swift
+++ b/src/TulsiGenerator/PBXTargetGenerator.swift
@@ -556,7 +556,7 @@
 
       var localPreprocessorDefines = defines
       let localIncludes = includes.mutableCopy() as! NSMutableOrderedSet
-      let otherCFlags = NSMutableOrderedSet()
+      let otherCFlags = NSMutableArray()
       let swiftIncludePaths = NSMutableOrderedSet()
       let otherSwiftFlags = NSMutableArray()
       addLocalSettings(ruleEntry, localDefines: &localPreprocessorDefines, localIncludes: localIncludes,
@@ -618,7 +618,7 @@
                                       dependencies: ruleEntry.dependencies,
                                       resolvedDependencies: Set(resolvedDependecies),
                                       preprocessorDefines: localPreprocessorDefines,
-                                      otherCFlags: otherCFlags.array as! [String],
+                                      otherCFlags: otherCFlags as! [String],
                                       otherSwiftFlags: otherSwiftFlags as! [String],
                                       includes: resolvedIncludes,
                                       frameworkSearchPaths: frameworkSearchPaths.array as! [String],
@@ -1248,7 +1248,7 @@
   private func addLocalSettings(_ ruleEntry: RuleEntry,
                                 localDefines: inout Set<String>,
                                 localIncludes: NSMutableOrderedSet,
-                                otherCFlags: NSMutableOrderedSet,
+                                otherCFlags: NSMutableArray,
                                 swiftIncludePaths: NSMutableOrderedSet,
                                 otherSwiftFlags: NSMutableArray) {
     if let swiftc_opts = ruleEntry.attributes[.swiftc_opts] as? [String], !swiftc_opts.isEmpty {
@@ -1318,7 +1318,7 @@
     includes.add("$(\(PBXTargetGenerator.BazelWorkspaceSymlinkVarName))/tools/cpp/gcc3")
     addIncludes(ruleEntry, toSet: includes)
     addLocalSettings(ruleEntry, localDefines: &defines, localIncludes: includes,
-                     otherCFlags: NSMutableOrderedSet(), swiftIncludePaths: NSMutableOrderedSet(),
+                     otherCFlags: NSMutableArray(), swiftIncludePaths: NSMutableOrderedSet(),
                      otherSwiftFlags: NSMutableArray())
     addSwiftIncludes(ruleEntry, toSet: swiftIncludePaths)
     addOtherSwiftFlags(ruleEntry, toArray: otherSwiftFlags)
diff --git a/src/TulsiGeneratorTests/PBXTargetGeneratorTests.swift b/src/TulsiGeneratorTests/PBXTargetGeneratorTests.swift
index abb6059..b182bab 100644
--- a/src/TulsiGeneratorTests/PBXTargetGeneratorTests.swift
+++ b/src/TulsiGeneratorTests/PBXTargetGeneratorTests.swift
@@ -2614,6 +2614,36 @@
                           inTargets: targets)
   }
 
+  func testIndexerCFlags() {
+    let package = "test/package"
+
+    let swiftTargetName = "SwiftTarget"
+    let swiftTargetBuildLabel = BuildLabel("\(package):\(swiftTargetName)")
+    let swiftTargetCOpts = ["-iquote", "foo/bar", "-iquote", "."] as AnyObject
+
+    let swiftLibraryRule = makeTestRuleEntry(swiftTargetBuildLabel,
+                                             type: "swift_library",
+                                             attributes: ["copts": swiftTargetCOpts,
+                                                          "has_swift_info": true as AnyObject],
+                                             sourceFiles: sourceFileNames)
+
+    var processedEntries = [RuleEntry: (NSOrderedSet)]()
+    let indexerTargetName = String(format: "_idx_\(swiftTargetName)_%08X_ios_min9.0", swiftTargetBuildLabel.hashValue)
+    targetGenerator.registerRuleEntryForIndexer(swiftLibraryRule,
+                                                ruleEntryMap: RuleEntryMap(),
+                                                pathFilters: pathFilters,
+                                                processedEntries: &processedEntries)
+    targetGenerator.generateIndexerTargets()
+
+    let targets = project.targetByName
+    XCTAssertEqual(targets.count, 1)
+    validateIndexerTarget(indexerTargetName,
+                          sourceFileNames: sourceFileNames,
+                          otherCFlags: "-iquote foo/bar -iquote .",
+                          isSwift: true,
+                          inTargets: targets)
+  }
+
   // MARK: - Helper methods
 
   private func debugBuildSettingsFromSettings(_ settings: [String: String]) -> [String: String] {
@@ -2898,6 +2928,7 @@
                                      bridgingHeader: String? = nil,
                                      swiftLanguageVersion: String? = nil,
                                      swiftIncludePaths: String? = nil,
+                                     otherCFlags: String? = nil,
                                      otherSwiftFlags: String? = nil,
                                      isSwift: Bool = false,
                                      inTargets targets: Dictionary<String, PBXTarget> = Dictionary<String, PBXTarget>(),
@@ -2923,6 +2954,9 @@
     if let swiftIncludePaths = swiftIncludePaths {
       expectedBuildSettings["SWIFT_INCLUDE_PATHS"] = swiftIncludePaths
     }
+    if let otherCFlags = otherCFlags {
+      expectedBuildSettings["OTHER_CFLAGS"] = otherCFlags
+    }
     if let otherSwiftFlags = otherSwiftFlags {
       expectedBuildSettings["OTHER_SWIFT_FLAGS"] = otherSwiftFlags
     }
@@ -3010,5 +3044,3 @@
                    "Validation count mismatch in target '\(target.name)'")
   }
 }
-
-