1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../base/file_system.dart';
import '../base/process.dart';
const String kCFBundleIdentifierKey = 'CFBundleIdentifier';
const String kCFBundleShortVersionStringKey = 'CFBundleShortVersionString';
const String kCFBundleExecutable = 'CFBundleExecutable';
// Prefer using [iosWorkflow.getPlistValueFromFile] to enable mocking.
String getValueFromFile(String plistFilePath, String key) {
// TODO(chinmaygarde): For now, we only need to read from plist files on a mac
// host. If this changes, we will need our own Dart plist reader.
// Don't use PlistBuddy since that is not guaranteed to be installed.
// 'defaults' requires the path to be absolute and without the 'plist'
// extension.
const String executable = '/usr/bin/defaults';
if (!fs.isFileSync(executable))
return null;
if (!fs.isFileSync(plistFilePath))
return null;
final String normalizedPlistPath = fs.path.withoutExtension(fs.path.absolute(plistFilePath));
try {
final List<String> args = <String>[
executable, 'read', normalizedPlistPath,
];
if (key != null && key.isNotEmpty) {
args.add(key);
}
final String value = runCheckedSync(args);
return value.isEmpty ? null : value;
} catch (error) {
return null;
}
}