Flutter Engine
The Flutter Engine
Classes | Functions | Variables
create_apk Namespace Reference

Classes

class  ChDir
 
class  RemoveFiles
 
class  SkQP_Build_Options
 

Functions

def print_cmd (cmd, o)
 
def check_call (cmd, **kwargs)
 
def find_name (searchpath, filename)
 
def check_ninja ()
 
def remove (p)
 
def makedirs (dst)
 
def make_symlinked_subdir (target, working_dir)
 
def accept_android_license (android_home)
 
def create_apk_impl (opts)
 
def create_apk (opts)
 
def main ()
 

Variables

dictionary skia_to_android_arch_name_map
 

Function Documentation

◆ accept_android_license()

def create_apk.accept_android_license (   android_home)

Definition at line 104 of file create_apk.py.

104def accept_android_license(android_home):
105 proc = subprocess.Popen(
106 [android_home + '/tools/bin/sdkmanager', '--licenses'],
107 stdin=subprocess.PIPE)
108 while proc.poll() is None:
109 proc.stdin.write('y\n')
110 time.sleep(1)
111
112# pylint: disable=bad-whitespace
def accept_android_license(android_home)
Definition: create_apk.py:104

◆ check_call()

def create_apk.check_call (   cmd,
**  kwargs 
)

Definition at line 56 of file create_apk.py.

56def check_call(cmd, **kwargs):
57 print_cmd(cmd, sys.stdout)
58 return subprocess.check_call(cmd, **kwargs)
59
def print_cmd(cmd, o)
Definition: create_apk.py:45
def check_call(cmd, **kwargs)
Definition: create_apk.py:56

◆ check_ninja()

def create_apk.check_ninja ( )

Definition at line 65 of file create_apk.py.

65def check_ninja():
66 with open(os.devnull, 'w') as devnull:
67 return subprocess.call(['ninja', '--version'],
68 stdout=devnull, stderr=devnull) == 0
69
def check_ninja()
Definition: create_apk.py:65

◆ create_apk()

def create_apk.create_apk (   opts)

Definition at line 190 of file create_apk.py.

190def create_apk(opts):
191 skia_dir = os.path.abspath(os.path.dirname(__file__) + '/../..')
192 assert os.path.exists(skia_dir)
193 with ChDir(skia_dir):
194 create_apk_impl(opts)
195
def create_apk_impl(opts)
Definition: create_apk.py:118
def create_apk(opts)
Definition: create_apk.py:190

◆ create_apk_impl()

def create_apk.create_apk_impl (   opts)

Definition at line 118 of file create_apk.py.

118def create_apk_impl(opts):
119 build_dir, final_output_dir = opts.build_dir, opts.final_output_dir
120
121 assert os.path.exists('bin/gn') # Did you `tools/git-syc-deps`?
122
123 for d in [build_dir, final_output_dir]:
124 makedirs(d)
125
126 apps_dir = 'platform_tools/android/apps'
127 app = 'skqp'
128 lib = 'lib%s_jni.so' % app
129
130 # These are the locations in the tree where the gradle needs or will create
131 # not-checked-in files. Treat them specially to keep the tree clean.
132 remove(build_dir + '/libs')
133 build_paths = [apps_dir + '/.gradle',
134 apps_dir + '/' + app + '/build',
135 apps_dir + '/' + app + '/src/main/libs']
136 for path in build_paths:
137 remove(path)
138 try:
139 make_symlinked_subdir(path, build_dir)
140 except OSError:
141 sys.stderr.write('failed to create symlink "%s"\n' % path)
142
143 lib_dir = '%s/%s/src/main/libs' % (apps_dir, app)
144 apk_build_dir = '%s/%s/build/outputs/apk' % (apps_dir, app)
145 for d in [lib_dir, apk_build_dir]:
146 shutil.rmtree(d, True) # force rebuild
147
148 with RemoveFiles(*build_paths):
149 for arch in opts.architectures:
150 build = os.path.join(build_dir, arch)
151 gn_args = opts.gn_args(arch)
152 args = ' '.join('%s=%s' % (k, v) for k, v in gn_args.items())
153 check_call(['bin/gn', 'gen', build, '--args=' + args])
154 try:
155 check_call(['ninja', '-C', build, lib])
156 except subprocess.CalledProcessError:
157 check_call(['ninja', '-C', build, '-t', 'clean'])
158 check_call(['ninja', '-C', build, lib])
159 dst = '%s/%s' % (lib_dir, skia_to_android_arch_name_map[arch])
160 makedirs(dst)
161 shutil.copy(os.path.join(build, lib), dst)
162
163 accept_android_license(opts.android_home)
164 env_copy = os.environ.copy()
165 env_copy['ANDROID_HOME'] = opts.android_home
166 env_copy['ANDROID_NDK_HOME'] = opts.android_ndk
167 # Why does gradlew need to be called from this directory?
168 check_call(['apps/gradlew', '-p' 'apps/' + app,
169 '-P', 'suppressNativeBuild',
170 ':%s:assembleUniversalDebug' % app],
171 env=env_copy, cwd='platform_tools/android')
172
173 apk_name = app + "-universal-debug.apk"
174
175 apk_list = list(find_name(apk_build_dir, apk_name))
176 assert len(apk_list) == 1
177
178 out = os.path.join(final_output_dir, apk_name)
179 shutil.move(apk_list[0], out)
180 sys.stdout.write(out + '\n')
181
182 arches = '_'.join(sorted(opts.architectures))
183 copy = os.path.join(final_output_dir, "%s-%s-debug.apk" % (app, arches))
184 shutil.copyfile(out, copy)
185 sys.stdout.write(copy + '\n')
186
187 sys.stdout.write('* * * COMPLETE * * *\n\n')
188
189
def makedirs(dst)
Definition: create_apk.py:77
def find_name(searchpath, filename)
Definition: create_apk.py:60
def remove(p)
Definition: create_apk.py:70
def make_symlinked_subdir(target, working_dir)
Definition: create_apk.py:99
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ find_name()

def create_apk.find_name (   searchpath,
  filename 
)

Definition at line 60 of file create_apk.py.

60def find_name(searchpath, filename):
61 for dirpath, _, filenames in os.walk(searchpath):
62 if filename in filenames:
63 yield os.path.join(dirpath, filename)
64

◆ main()

def create_apk.main ( )

Definition at line 232 of file create_apk.py.

232def main():
233 options = SkQP_Build_Options()
234 if options.error:
235 sys.stderr.write(options.error + __doc__)
236 sys.exit(1)
237 options.write(sys.stdout)
238 create_apk(options)
239
def main()
Definition: create_apk.py:232

◆ make_symlinked_subdir()

def create_apk.make_symlinked_subdir (   target,
  working_dir 
)

Definition at line 99 of file create_apk.py.

99def make_symlinked_subdir(target, working_dir):
100 newdir = os.path.join(working_dir, os.path.basename(target))
101 makedirs(newdir)
102 os.symlink(os.path.relpath(newdir, os.path.dirname(target)), target)
103

◆ makedirs()

def create_apk.makedirs (   dst)

Definition at line 77 of file create_apk.py.

77def makedirs(dst):
78 if not os.path.exists(dst):
79 os.makedirs(dst)
80

◆ print_cmd()

def create_apk.print_cmd (   cmd,
  o 
)

Definition at line 45 of file create_apk.py.

45def print_cmd(cmd, o):
46 m = re.compile('[^A-Za-z0-9_./-]')
47 o.write('+ ')
48 for c in cmd:
49 if m.search(c) is not None:
50 o.write(repr(c) + ' ')
51 else:
52 o.write(c + ' ')
53 o.write('\n')
54 o.flush()
55

◆ remove()

def create_apk.remove (   p)

Definition at line 70 of file create_apk.py.

70def remove(p):
71 if not os.path.islink(p) and os.path.isdir(p):
72 shutil.rmtree(p)
73 elif os.path.lexists(p):
74 os.remove(p)
75 assert not os.path.exists(p)
76

Variable Documentation

◆ skia_to_android_arch_name_map

dictionary create_apk.skia_to_android_arch_name_map
Initial value:
1= {'arm' : 'armeabi-v7a',
2 'arm64': 'arm64-v8a' ,
3 'x86' : 'x86' ,
4 'x64' : 'x86_64' }

Definition at line 113 of file create_apk.py.