mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Replaces the (temporary) compile-time option to pass engine switches with the ability to pass them temporarily at runtime via environment variables. This moves the recently-added code for doing this on Windows to a shared location for use by all desktop embeddings. This is enabled only for debug/profile to avoid potential issues with tampering with released applications, but if there is a need for that in the future it could be added (potentially with a whitelist, as is currently used for Dart VM flags). Temporarily adds a way to enable mirrors as a compile time option, as is already provided in the Linux embedding, to provide a migration path for the one remaining known need for compile-time options that has been raised in flutter/flutter#38569.
42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/shell/platform/common/cpp/engine_switches.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
|
|
namespace flutter {
|
|
|
|
std::vector<std::string> GetSwitchesFromEnvironment() {
|
|
std::vector<std::string> switches;
|
|
// Read engine switches from the environment in debug/profile. If release mode
|
|
// support is needed in the future, it should likely use a whitelist.
|
|
#ifndef FLUTTER_RELEASE
|
|
const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES";
|
|
const int kMaxSwitchCount = 50;
|
|
const char* switch_count_string = std::getenv(switch_count_key);
|
|
int switch_count = std::min(
|
|
kMaxSwitchCount, switch_count_string ? atoi(switch_count_string) : 0);
|
|
for (int i = 1; i <= switch_count; ++i) {
|
|
std::ostringstream switch_key;
|
|
switch_key << "FLUTTER_ENGINE_SWITCH_" << i;
|
|
const char* switch_value = std::getenv(switch_key.str().c_str());
|
|
if (switch_value) {
|
|
std::ostringstream switch_value_as_flag;
|
|
switch_value_as_flag << "--" << switch_value;
|
|
switches.push_back(switch_value_as_flag.str());
|
|
} else {
|
|
std::cerr << switch_count << " keys expected from " << switch_count_key
|
|
<< ", but " << switch_key.str() << " is missing." << std::endl;
|
|
}
|
|
}
|
|
#endif // !FLUTTER_RELEASE
|
|
return switches;
|
|
}
|
|
|
|
} // namespace flutter
|