Skip to content

Commit eee684e

Browse files
committed
Add assume_valid: to skip a redundant plutil -lint
`L10nHelper.strings_file_type` gains an opt-in `assume_valid:` flag that skips the `plutil -lint` validity check when the caller has already parsed the file, avoiding a redundant `plutil` invocation. Default behavior is unchanged for every existing caller.
1 parent 199bb5a commit eee684e

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _None_
1818

1919
### Internal Changes
2020

21-
_None_
21+
- `L10nHelper.strings_file_type` (and `StringsFileValidationHelper.scan_for_duplicate_keys`) accept `assume_valid:` to skip a redundant `plutil -lint` when the caller has already parsed the file. [#____]
2222

2323
## 14.7.0
2424

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_l10n_helper.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ class L10nHelper
1515
# Returns the type of a `.strings` file (XML, binary or ASCII)
1616
#
1717
# @param [String] path The path to the `.strings` file to check
18+
# @param [Boolean] assume_valid Skip the `plutil -lint` validity check when the caller has already
19+
# confirmed the file parses (e.g. via `read_strings_file_as_hash`), avoiding a redundant
20+
# `plutil` invocation. Only the format detection (`file`) then runs.
1821
# @return [Symbol] The file format used by the `.strings` file. Can be one of:
1922
# - `:text` for the ASCII-plist file format (containing typical `"key" = "value";` lines)
2023
# - `:xml` for XML plist file format (can be used if machine-generated, especially since there's no official way/tool to generate the ASCII-plist file format as output)
2124
# - `:binary` for binary plist file format (usually only true for `.strings` files converted by Xcode at compile time and included in the final `.app`/`.ipa`)
2225
# - `nil` if the file does not exist or is neither of those format (e.g. not a `.strings` file at all)
2326
#
24-
def self.strings_file_type(path:)
27+
def self.strings_file_type(path:, assume_valid: false)
2528
return :text if File.empty?(path) # If completely empty file, consider it as a valid `.strings` files in textual format
2629

27-
# Start by checking it seems like a valid property-list file (and not e.g. an image or plain text file)
28-
_, status = Open3.capture2('/usr/bin/plutil', '-lint', path)
29-
return nil unless status.success?
30+
# Start by checking it seems like a valid property-list file (and not e.g. an image or plain text file).
31+
# A caller that has already parsed the file can skip this redundant check via `assume_valid: true`.
32+
unless assume_valid
33+
_, status = Open3.capture2('/usr/bin/plutil', '-lint', path)
34+
return nil unless status.success?
35+
end
3036

3137
# If it is a valid property-list file, determine the actual format used
3238
format_desc, status = Open3.capture2('/usr/bin/file', path)

spec/ios_l10n_helper_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def file_encoding(path)
3939
expect(File).to exist(invalid_fixture)
4040
expect(described_class.strings_file_type(path: invalid_fixture)).to be_nil
4141
end
42+
43+
it 'skips the redundant `plutil -lint` check when `assume_valid: true`, still detecting the format' do
44+
text_fixture = fixture('Localizable-utf16.strings')
45+
allow(Open3).to receive(:capture2).and_call_original
46+
expect(Open3).not_to receive(:capture2).with('/usr/bin/plutil', '-lint', anything)
47+
48+
expect(described_class.strings_file_type(path: text_fixture, assume_valid: true)).to eq(:text)
49+
end
4250
end
4351

4452
describe '#merge_strings' do

0 commit comments

Comments
 (0)