Skip to content

Commit

Permalink
Add support to parse OTHER_LDFLAGS arg files using '@'
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed May 26, 2021
1 parent 907c817 commit d83ee02
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Add support to parse OTHER_LDFLAGS arg files using '@'
[dnkoutso](https:/dnkoutso)
[#820](https:/CocoaPods/Xcodeproj/pull/820)

* Allow accessing a Launch Action's Simulated Location (`LocationScenarioReference`)
[freak4pc](https:/freak4pc)
[#813](https:/CocoaPods/Xcodeproj/pull/813)
Expand Down
12 changes: 10 additions & 2 deletions lib/xcodeproj/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(xcconfig_hash_or_file = {})
@attributes = {}
@includes = []
@other_linker_flags = {}
[:simple, :frameworks, :weak_frameworks, :libraries, :force_load].each do |key|
[:simple, :frameworks, :weak_frameworks, :libraries, :arg_files, :force_load].each do |key|
@other_linker_flags[key] = Set.new
end
merge!(extract_hash(xcconfig_hash_or_file))
Expand Down Expand Up @@ -126,9 +126,10 @@ def to_hash(prefix = nil)
:frameworks => '-framework ',
:weak_frameworks => '-weak_framework ',
:libraries => '-l',
:arg_files => '@',
:force_load => '-force_load',
}
[:libraries, :frameworks, :weak_frameworks, :force_load].each do |key|
[:libraries, :frameworks, :weak_frameworks, :arg_files, :force_load].each do |key|
modifier = modifiers[key]
sorted = other_linker_flags[key].to_a.sort
if key == :force_load
Expand Down Expand Up @@ -181,6 +182,13 @@ def libraries
other_linker_flags[:libraries]
end

# @return [Set<String>] The list of the arg files required by this
# settings file.
#
def arg_files
other_linker_flags[:arg_files]
end

public

# @!group Merging
Expand Down
5 changes: 5 additions & 0 deletions lib/xcodeproj/config/other_linker_flags_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def self.parse(flags)
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -32,6 +33,8 @@ def self.parse(flags)
key = :weak_frameworks
when '-l'
key = :libraries
when '@'
key = :arg_files
when '-force_load'
key = :force_load
else
Expand All @@ -58,6 +61,8 @@ def self.split(flags)
flags.strip.shellsplit.flat_map do |string|
if string =~ /\A-l.+/
['-l', string[2..-1]]
elsif string =~ /\A@.+/
['@', string[1..-1]]
else
string
end
Expand Down
50 changes: 50 additions & 0 deletions spec/config/other_linker_flags_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:frameworks => ['Foundation'],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -23,6 +24,7 @@
:frameworks => ['Foundation'],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -34,6 +36,7 @@
:frameworks => [],
:weak_frameworks => ['Twitter'],
:libraries => [],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -45,6 +48,7 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => ['xml2.2.7.3'],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -56,6 +60,7 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => ['xml2.2.7.3'],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -67,6 +72,7 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => ['Pods-AFNetworking iOS Example-AFNetworking'],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -78,6 +84,7 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => ['Pods-AFNetworking iOS Example-AFNetworking'],
:arg_files => [],
:simple => [],
:force_load => [],
}
Expand All @@ -89,17 +96,55 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => ['-ObjC', '-fobjc-arc'],
:force_load => [],
}
end

it 'detects arg files' do
flags = '@ /path/to/file'
@parser.parse(flags).should == {
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => ['/path/to/file'],
:simple => [],
:force_load => [],
}
end

it 'detects arg files specified with quotes' do
flags = '@ "${PODS_ROOT}/Target Support Files/Target/other_ldflags"'
@parser.parse(flags).should == {
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => ['${PODS_ROOT}/Target Support Files/Target/other_ldflags'],
:simple => [],
:force_load => [],
}
end

it 'detects arg files specified with quotes without a space' do
flags = '@"${PODS_ROOT}/Target Support Files/Target/other_ldflags"'
@parser.parse(flags).should == {
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => ['${PODS_ROOT}/Target Support Files/Target/other_ldflags'],
:simple => [],
:force_load => [],
}
end

it 'strips unnecessary whitespace' do
flags = ' -ObjC '
@parser.parse(flags).should == {
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => ['-ObjC'],
:force_load => [],
}
Expand All @@ -111,6 +156,7 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => ['-finalize', '-prefinalized-library'],
:force_load => [],
}
Expand All @@ -123,12 +169,15 @@
flags << '-lxml2.2.7.3'
flags << '-l "Pods-AFNetworking iOS Example-AFNetworking"'
flags << '-l"Pods-AFNetworking iOS Example-AFNetworking"'
flags << '@"${PODS_ROOT}/Target Support Files/other_ldflags"'
flags << '@ "${PODS_ROOT}/Target Support Files/other_ldflags"'
flags << '-ObjC -fobjc-arc'
flags << '-finalize -prefinalized-library'
@parser.parse(flags.join(' ')).should == {
:frameworks => ['Foundation'],
:weak_frameworks => ['Twitter'],
:libraries => ['xml2.2.7.3', 'xml2.2.7.3', 'Pods-AFNetworking iOS Example-AFNetworking', 'Pods-AFNetworking iOS Example-AFNetworking'],
:arg_files => ['${PODS_ROOT}/Target Support Files/other_ldflags', '${PODS_ROOT}/Target Support Files/other_ldflags'],
:simple => ['-ObjC', '-fobjc-arc', '-finalize', '-prefinalized-library'],
:force_load => [],
}
Expand All @@ -140,6 +189,7 @@
:frameworks => [],
:weak_frameworks => [],
:libraries => [],
:arg_files => [],
:simple => ['-Objc', '-all_load', '-lsqlite3', '-lz'],
:force_load => [],
}
Expand Down
19 changes: 19 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@
config.libraries.to_a.should.be.equal %w(xml2.2.7.3)
end

it 'parses arg files with double quotes' do
hash = { 'OTHER_LDFLAGS' => '@"${PODS_ROOT}/Target Support Files/path/to/other_ldflags"' }
config = Xcodeproj::Config.new(hash)
config.arg_files.to_a.should.be.equal ['${PODS_ROOT}/Target Support Files/path/to/other_ldflags']
end

it 'parses arg files with shell escaping' do
hash = { 'OTHER_LDFLAGS' => '@${PODS_ROOT}/Target\ Support\ Files/path/to/other_ldflags' }
config = Xcodeproj::Config.new(hash)
config.arg_files.to_a.should.be.equal ['${PODS_ROOT}/Target Support Files/path/to/other_ldflags']
end

it 'can be serialized with #to_s' do
@config.to_s.should.be.equal "OTHER_LDFLAGS = -framework \"Foundation\"\n"
end
Expand Down Expand Up @@ -151,6 +163,13 @@
}
end

it 'appends a value for the same key when merging' do
@config.merge!('OTHER_LDFLAGS' => '-l xml2.2.7.3 @"${PODS_ROOT}/Target Support Files/other_ldflags"')
@config.to_hash.should == {
'OTHER_LDFLAGS' => '-l"xml2.2.7.3" -framework "Foundation" @"${PODS_ROOT}/Target Support Files/other_ldflags"',
}
end

it 'de-duplicates values when merging' do
@config << { 'FOO' => 'bar $(baz)' }
@config.merge!('FOO' => 'bar $(baz)')
Expand Down

0 comments on commit d83ee02

Please sign in to comment.