Class: Lynx::Library::Autolink
- Inherits:
-
Object
- Object
- Lynx::Library::Autolink
- Defined in:
- lib/lynx/library/autolink.rb
Constant Summary collapse
- REGISTRY_CLASS_NAME =
'LynxGeneratedLibraryRegistry'- ADDON_USE_SOURCE_NAME =
'LynxGeneratedNodeAPIAddonUse.mm'- ADDON_NAME_PATTERN =
/\A[A-Za-z_][A-Za-z0-9_]*\z/- PLUGIN_NAME =
'cocoapods-lynx-library'- DEFAULT_SOURCES =
[:node_modules, :pods].freeze
- KNOWN_SOURCES =
[:node_modules, :pods].freeze
Class Method Summary collapse
- .generate_registry(output_dir, libraries, write_podspec: true) ⇒ Object
- .install!(podfile, options = {}) ⇒ Object
- .scan(start_dir) ⇒ Object
- .scan_components(source_dir) ⇒ Object
-
.scan_installed_pods(context, target_label) ⇒ Object
Scan the pods installed for
target_labeland turn the ones carrying a lynx.lib.json into LibraryInfo entries.
Class Method Details
.generate_registry(output_dir, libraries, write_podspec: true) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lynx/library/autolink.rb', line 51 def generate_registry(output_dir, libraries, write_podspec: true) FileUtils.mkdir_p(output_dir) components = collect_components(libraries) node_api_addons = libraries.flat_map(&:node_api_addons) File.write(File.join(output_dir, "#{REGISTRY_CLASS_NAME}.h"), header_source) File.write(File.join(output_dir, "#{REGISTRY_CLASS_NAME}.m"), implementation_source(components)) File.write(File.join(output_dir, ADDON_USE_SOURCE_NAME), addon_use_source(node_api_addons)) if write_podspec File.write(File.join(output_dir, 'LynxLibraryRegistry.podspec'), podspec_source(node_api_addons)) end components end |
.install!(podfile, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lynx/library/autolink.rb', line 25 def install!(podfile, = {}) start_dir = File.([:root] || Dir.pwd) output_dir = File.([:output_dir] || 'generated/lynx-library', start_dir) sources = normalize_sources([:sources]) node_modules_libraries = sources.include?(:node_modules) ? scan(start_dir) : [] add_node_modules_pods(podfile, node_modules_libraries) # Generate the initial registry. In pods mode it may be a stub that the # post-install hook rewrites once the installed pods are available. generate_registry(output_dir, node_modules_libraries) podfile.pod 'LynxLibraryRegistry', :path => output_dir if sources.include?(:pods) register_pods_hook(output_dir, node_modules_libraries, current_target_label(podfile)) end node_modules_libraries end |
.scan(start_dir) ⇒ Object
45 46 47 48 49 |
# File 'lib/lynx/library/autolink.rb', line 45 def scan(start_dir) node_modules_dirs(start_dir).flat_map do |node_modules| manifest_files(node_modules).map { |manifest| parse_manifest(manifest) }.compact end.sort_by(&:npm_name) end |
.scan_components(source_dir) ⇒ Object
66 67 68 |
# File 'lib/lynx/library/autolink.rb', line 66 def scan_components(source_dir) source_files(source_dir).flat_map { |file| scan_source_file(file) } end |
.scan_installed_pods(context, target_label) ⇒ Object
Scan the pods installed for target_label and turn the ones carrying a
lynx.lib.json into LibraryInfo entries. Source location comes from the
pod's resolved source_files, not from the manifest's sourceDir.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/lynx/library/autolink.rb', line 127 def scan_installed_pods(context, target_label) sandbox = context.sandbox seen_manifests = {} pod_specs_for_target(context, target_label).map do |spec| pod_name = spec.root.name next if pod_name == 'LynxLibraryRegistry' pod_root = pod_source_root(sandbox, pod_name) unless pod_root log_warning("skipped pod '#{pod_name}': source directory not found in sandbox") next end manifest = File.join(pod_root, 'lynx.lib.json') next unless File.file?(manifest) canonical = File.realpath(manifest) if (owner = seen_manifests[canonical]) # Different pods reusing the same manifest is unexpected. if owner != pod_name log_warning("skipped pod '#{pod_name}': lynx.lib.json at #{canonical} " \ "already provided by '#{owner}'") end next end seen_manifests[canonical] = pod_name native_library_from_pod(spec, pod_root, manifest) end.compact.sort_by(&:npm_name) end |