Skip to content

Commit

Permalink
Update to newer version of the FTL. (flutter#3804)
Browse files Browse the repository at this point in the history
  • Loading branch information
pylaligand authored Jun 20, 2017
1 parent 63ef135 commit 76397e9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ deps = {
# and not have to specific specific hashes.

'src/lib/ftl':
Var('fuchsia_git') + '/ftl' + '@' + 'f1357b6eaa9a23cffec1645dfeba610b5f926b1d',
Var('fuchsia_git') + '/ftl' + '@' + '81aa1ca480c99caffbc2965deb0a6f7ac7f59f1c',

'src/lib/tonic':
Var('fuchsia_git') + '/tonic' + '@' + '5b3d521980ca00274ad7e67f9f8b203cd4b20039',
Expand Down
12 changes: 7 additions & 5 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
#include <sstream>
#include <string>

#include "lib/ftl/strings/string_view.h"

// Include once for the default enum definition.
#include "flutter/shell/common/switches.h"

#undef SHELL_COMMON_SWITCHES_H_

struct SwitchDesc {
shell::Switch sw;
const char* flag;
const ftl::StringView flag;
const char* help;
};

Expand Down Expand Up @@ -46,7 +48,7 @@ void PrintUsage(const std::string& executable_name) {
uint32_t max_width = 2;
for (uint32_t i = 0; i < flags_count; i++) {
auto desc = gSwitchDescs[i];
max_width = std::max<uint32_t>(strlen(desc.flag) + 2, max_width);
max_width = std::max<uint32_t>(desc.flag.size() + 2, max_width);
}

const uint32_t help_width = column_width - max_width - 3;
Expand All @@ -56,7 +58,7 @@ void PrintUsage(const std::string& executable_name) {
auto desc = gSwitchDescs[i];

std::cerr << std::setw(max_width)
<< std::string("--") + std::string(desc.flag) << " : ";
<< std::string("--") + desc.flag.ToString() << " : ";

std::istringstream stream(desc.help);
int32_t remaining = help_width;
Expand All @@ -78,13 +80,13 @@ void PrintUsage(const std::string& executable_name) {
std::cerr << std::string(column_width, '-') << std::endl;
}

const char* FlagForSwitch(Switch swtch) {
const ftl::StringView FlagForSwitch(Switch swtch) {
for (uint32_t i = 0; i < static_cast<uint32_t>(Switch::Sentinel); i++) {
if (gSwitchDescs[i].sw == swtch) {
return gSwitchDescs[i].flag;
}
}
return nullptr;
return ftl::StringView();
}

} // namespace shell
4 changes: 3 additions & 1 deletion shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "lib/ftl/strings/string_view.h"

#ifndef SHELL_COMMON_SWITCHES_H_
#define SHELL_COMMON_SWITCHES_H_

Expand Down Expand Up @@ -101,7 +103,7 @@ DEF_SWITCHES_END

void PrintUsage(const std::string& executable_name);

const char* FlagForSwitch(Switch sw);
const ftl::StringView FlagForSwitch(Switch sw);

} // namespace shell

Expand Down
17 changes: 9 additions & 8 deletions shell/platform/darwin/common/platform_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "flutter/shell/common/tracing_controller.h"
#include "flutter/sky/engine/wtf/MakeUnique.h"
#include "lib/ftl/command_line.h"
#include "lib/ftl/strings/string_view.h"

namespace shell {

Expand Down Expand Up @@ -91,7 +92,7 @@ static bool FlagsValidForCommandLineLaunch(const std::string& bundle_path,
return true;
}

static std::string ResolveCommandLineLaunchFlag(const char* name) {
static std::string ResolveCommandLineLaunchFlag(const ftl::StringView name) {
const auto& command_line = shell::Shell::Shared().GetCommandLine();

std::string command_line_option;
Expand All @@ -100,7 +101,7 @@ static bool FlagsValidForCommandLineLaunch(const std::string& bundle_path,
}

const char* saved_default =
[[NSUserDefaults standardUserDefaults] stringForKey:@(name)].UTF8String;
[[NSUserDefaults standardUserDefaults] stringForKey:@(name.data())].UTF8String;

if (saved_default != NULL) {
return saved_default;
Expand All @@ -121,9 +122,9 @@ bool AttemptLaunchFromCommandLineSwitches(Engine* engine) {
// one go. We dont want to end up in a situation where we take one value
// from the command line and the others from user defaults. In case, any
// new flags are specified, forget about all the old ones.
[defaults removeObjectForKey:@(FlagForSwitch(Switch::FLX))];
[defaults removeObjectForKey:@(FlagForSwitch(Switch::MainDartFile))];
[defaults removeObjectForKey:@(FlagForSwitch(Switch::Packages))];
[defaults removeObjectForKey:@(FlagForSwitch(Switch::FLX).data())];
[defaults removeObjectForKey:@(FlagForSwitch(Switch::MainDartFile).data())];
[defaults removeObjectForKey:@(FlagForSwitch(Switch::Packages).data())];

[defaults synchronize];
}
Expand All @@ -139,9 +140,9 @@ bool AttemptLaunchFromCommandLineSwitches(Engine* engine) {
// Save the newly resolved dart main file and the package root to user
// defaults so that the next time the user launches the application in the
// simulator without the tooling, the application boots up.
[defaults setObject:@(bundle_path.c_str()) forKey:@(FlagForSwitch(Switch::FLX))];
[defaults setObject:@(main.c_str()) forKey:@(FlagForSwitch(Switch::MainDartFile))];
[defaults setObject:@(packages.c_str()) forKey:@(FlagForSwitch(Switch::Packages))];
[defaults setObject:@(bundle_path.c_str()) forKey:@(FlagForSwitch(Switch::FLX).data())];
[defaults setObject:@(main.c_str()) forKey:@(FlagForSwitch(Switch::MainDartFile).data())];
[defaults setObject:@(packages.c_str()) forKey:@(FlagForSwitch(Switch::Packages).data())];

[defaults synchronize];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
#include "flutter/shell/common/switches.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartSource.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h"
#include "lib/ftl/strings/string_view.h"

static NSURL* URLForSwitch(const char* name) {
static NSURL* URLForSwitch(const ftl::StringView name) {
const auto& cmd = shell::Shell::Shared().GetCommandLine();
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];

std::string switch_value;
if (cmd.GetOptionValue(name, &switch_value)) {
auto url = [NSURL fileURLWithPath:@(switch_value.c_str())];
[defaults setURL:url forKey:@(name)];
[defaults setURL:url forKey:@(name.data())];
[defaults synchronize];
return url;
}

return [defaults URLForKey:@(name)];
return [defaults URLForKey:@(name.data())];
}

@implementation FlutterDartProject {
Expand Down
8 changes: 7 additions & 1 deletion travis/licenses_golden/licenses_lib
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Signature: 4dcd5e5c7ba17499b85da8a9b3fa6637
Signature: 8ce9795a1571ef4554479f407125b26e

UNUSED LICENSES:

Expand Down Expand Up @@ -78,6 +78,7 @@ FILE: ../../../lib/ftl/files/symlink.h
FILE: ../../../lib/ftl/files/symlink_posix.cc
FILE: ../../../lib/ftl/files/unique_fd.cc
FILE: ../../../lib/ftl/files/unique_fd.h
FILE: ../../../lib/ftl/functional/auto_call.h
FILE: ../../../lib/ftl/functional/closure.h
FILE: ../../../lib/ftl/functional/make_copyable.h
FILE: ../../../lib/ftl/functional/make_copyable_unittest.cc
Expand Down Expand Up @@ -224,6 +225,11 @@ ORIGIN: ../../../lib/ftl/files/path_win.cc + ../../../lib/ftl/LICENSE
TYPE: LicenseType.bsd
FILE: ../../../lib/ftl/files/path_win.cc
FILE: ../../../lib/ftl/files/symlink_win.cc
FILE: ../../../lib/ftl/functional/apply.h
FILE: ../../../lib/ftl/functional/apply_unittest.cc
FILE: ../../../lib/ftl/functional/auto_call_unittest.cc
FILE: ../../../lib/ftl/functional/cancelable_callback.h
FILE: ../../../lib/ftl/functional/cancelable_callback_unittest.cc
FILE: ../../../lib/ftl/inttypes.h
FILE: ../../../lib/ftl/portable_unistd.h
FILE: ../../../lib/ftl/random/rand_unittest.cc
Expand Down

0 comments on commit 76397e9

Please sign in to comment.