Class: Libpng::OHOS::NDK

Inherits:
Object
  • Object
show all
Defined in:
lib/libpng/ohos/ndk.rb

Overview

Pure-data handle to an extracted OHOS NDK installation. Discovers the four critical paths the build needs (toolchain cmake, clang, sysroot, binary-sign-tool), exposes them as Pathnames, and can invoke ext/ohos/setup-ndk.sh to populate the directory if missing.

Does NOT run any NDK binary itself -- that's the caller's job. This keeps the class testable without qemu/binfmt setup: specs just touch empty files at the expected paths and assert accessors.

Constant Summary collapse

ROOT_RELATIVE =
Pathname.new('ext/ohos/ndk').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: default_root) ⇒ NDK

Returns a new instance of NDK.



18
19
20
# File 'lib/libpng/ohos/ndk.rb', line 18

def initialize(root: default_root)
  @root = Pathname.new(root)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



53
54
55
# File 'lib/libpng/ohos/ndk.rb', line 53

def root
  @root
end

Instance Method Details

#clang_pathObject



33
34
35
# File 'lib/libpng/ohos/ndk.rb', line 33

def clang_path
  llvm_dir.join('bin/aarch64-unknown-linux-ohos-clang')
end

#clangxx_pathObject



37
38
39
# File 'lib/libpng/ohos/ndk.rb', line 37

def clangxx_path
  llvm_dir.join('bin/aarch64-unknown-linux-ohos-clang++')
end

#cmake_pathObject



49
50
51
# File 'lib/libpng/ohos/ndk.rb', line 49

def cmake_path
  sdk_dir.join('native/build-tools/cmake/bin/cmake')
end

#downloadObject

Downloads + extracts the NDK via ext/ohos/setup-ndk.sh. No-op if #exist?. Returns true on success, false otherwise.



57
58
59
60
61
62
# File 'lib/libpng/ohos/ndk.rb', line 57

def download
  return true if exist?

  script = recipe_root.join('ext/ohos/setup-ndk.sh')
  system(script.to_s, '--prefix', @root.to_s)
end

#exist?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/libpng/ohos/ndk.rb', line 22

def exist?
  toolchain_path.exist? &&
    clang_path.exist? &&
    sysroot_path.exist? &&
    sign_tool_path.exist?
end

#sign_tool_pathObject



45
46
47
# File 'lib/libpng/ohos/ndk.rb', line 45

def sign_tool_path
  sdk_dir.join('toolchains/lib/binary-sign-tool')
end

#sysroot_pathObject



41
42
43
# File 'lib/libpng/ohos/ndk.rb', line 41

def sysroot_path
  root.join('llvm-19/sysroot')
end

#toolchain_pathObject



29
30
31
# File 'lib/libpng/ohos/ndk.rb', line 29

def toolchain_path
  sdk_dir.join('native/build/cmake/ohos.toolchain.cmake')
end