Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
native_assets.cc
Go to the documentation of this file.
1// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
6
7#include "vm/hash_table.h"
8#include "vm/object_store.h"
9#include "vm/symbols.h"
10
11namespace dart {
12
13ArrayPtr GetNativeAssetsMap(Thread* thread) {
14 Zone* const zone = thread->zone();
15 ObjectStore* const object_store = thread->isolate_group()->object_store();
16 auto& native_assets_map =
17 Array::Handle(zone, object_store->native_assets_map());
18 if (!native_assets_map.IsNull()) {
19 return native_assets_map.ptr();
20 }
21
22#if defined(DART_PRECOMPILED_RUNTIME)
23 // For now not configuring native assets is supported.
24 return Array::null();
25#else // defined(DART_PRECOMPILED_RUNTIME)
26
27 const auto& native_assets_library =
28 Library::Handle(zone, object_store->native_assets_library());
29 if (native_assets_library.IsNull()) {
30 // For now not configuring native assets is supported.
31 return Array::null();
32 }
33
34 auto& pragma = Object::Handle(zone);
35 const bool pragma_found = native_assets_library.FindPragma(
36 thread, /*only_core=*/false, native_assets_library,
37 Symbols::vm_ffi_native_assets(),
38 /*multiple=*/false, &pragma);
39 ASSERT(pragma_found);
40
41 // This map is formatted as follows:
42 //
43 // '<target_string>': {
44 // '<asset_uri>': ['<path_type>', '<path (optional)>']
45 // }
46 //
47 // It is generated by: pkg/vm/lib/native_assets/synthesizer.dart
48 const auto& abi_map = Map::Cast(pragma);
49 const auto& current_abi = String::Handle(
50 zone, String::NewFormatted("%s_%s", kTargetOperatingSystemName,
51 kTargetArchitectureName));
52 Map::Iterator abi_iterator(abi_map);
53 auto& abi = String::Handle(zone);
54 auto& asset_map = Map::Handle(zone);
55 while (abi_iterator.MoveNext()) {
56 abi = String::RawCast(abi_iterator.CurrentKey());
57 if (abi.Equals(current_abi)) {
58 asset_map = Map::RawCast(abi_iterator.CurrentValue());
59 break;
60 }
61 }
62 const intptr_t asset_map_length = asset_map.IsNull() ? 0 : asset_map.Length();
64 HashTables::New<NativeAssetsMap>(asset_map_length, Heap::kOld));
65 if (!asset_map.IsNull()) {
66 String& asset = String::Handle(zone);
67 Array& path = Array::Handle(zone);
68 Map::Iterator iterator2(asset_map);
69 bool duplicate_asset = false;
70 while (iterator2.MoveNext()) {
71 asset = String::RawCast(iterator2.CurrentKey());
72 path = Array::RawCast(iterator2.CurrentValue());
73 duplicate_asset = map.UpdateOrInsert(asset, path);
74 ASSERT(!duplicate_asset);
75 }
76 }
77 native_assets_map = map.Release().ptr();
78 object_store->set_native_assets_map(native_assets_map);
79 return native_assets_map.ptr();
80
81#endif // defined(DART_PRECOMPILED_RUNTIME)
82}
83
84} // namespace dart
@ kOld
Definition heap.h:39
ObjectStore * object_store() const
Definition isolate.h:505
static const LinkedHashBase & Cast(const Object &obj)
Definition object.h:11984
ObjectPtr CurrentValue() const
Definition object.h:12129
ObjectPtr CurrentKey() const
Definition object.h:12127
static ObjectPtr null()
Definition object.h:433
static Object & Handle()
Definition object.h:407
static ObjectPtr RawCast(ObjectPtr obj)
Definition object.h:325
static StringPtr NewFormatted(const char *format,...) PRINTF_ATTRIBUTE(1
Definition object.cc:24083
Zone * zone() const
IsolateGroup * isolate_group() const
Definition thread.h:540
#define ASSERT(E)
ArrayPtr GetNativeAssetsMap(Thread *thread)