plist_utils.dart 1.24 KB
Newer Older
1 2 3 4
// 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.

5
import '../base/file_system.dart';
6 7
import '../base/process.dart';

8 9
const String kCFBundleIdentifierKey = 'CFBundleIdentifier';
const String kCFBundleShortVersionStringKey = 'CFBundleShortVersionString';
10

11
// Prefer using [iosWorkflow.getPlistValueFromFile] to enable mocking.
12
String getValueFromFile(String plistFilePath, String key) {
Devon Carew's avatar
Devon Carew committed
13 14
  // 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.
15 16 17 18

  // Don't use PlistBuddy since that is not guaranteed to be installed.
  // 'defaults' requires the path to be absolute and without the 'plist'
  // extension.
19 20 21
  const String executable = '/usr/bin/defaults';
  if (!fs.isFileSync(executable))
    return null;
22
  if (!fs.isFileSync(plistFilePath))
Devon Carew's avatar
Devon Carew committed
23 24
    return null;

25
  final String normalizedPlistPath = fs.path.withoutExtension(fs.path.absolute(plistFilePath));
26 27

  try {
28
    final String value = runCheckedSync(<String>[
29
      executable, 'read', normalizedPlistPath, key
Devon Carew's avatar
Devon Carew committed
30
    ]);
31
    return value.isEmpty ? null : value;
32
  } catch (error) {
33
    return null;
34 35
  }
}