update.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. #!/usr/bin/env python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. import argparse
  6. import os
  7. import re
  8. import shutil
  9. import sys
  10. import subprocess
  11. from pprint import pprint
  12. from StringIO import StringIO
  13. PLATFORMS= [
  14. 'x86-win32-vs12',
  15. 'x86_64-win64-vs12',
  16. 'x86-linux-gcc',
  17. 'x86_64-linux-gcc',
  18. 'generic-gnu',
  19. 'x86-darwin9-gcc',
  20. 'x86_64-darwin9-gcc',
  21. 'armv7-android-gcc',
  22. 'x86-win32-gcc',
  23. 'x86_64-win64-gcc',
  24. ]
  25. mk_files = [
  26. 'vp8/vp8_common.mk',
  27. 'vp8/vp8cx.mk',
  28. 'vp8/vp8dx.mk',
  29. 'vp8/vp8cx_arm.mk',
  30. 'vp9/vp9_common.mk',
  31. 'vp9/vp9cx.mk',
  32. 'vp9/vp9dx.mk',
  33. 'vpx_dsp/vpx_dsp.mk',
  34. 'vpx_mem/vpx_mem.mk',
  35. 'vpx_ports/vpx_ports.mk',
  36. 'vpx_scale/vpx_scale.mk',
  37. 'vpx/vpx_codec.mk',
  38. ]
  39. extensions = ['.asm', '.c', '.h']
  40. MODULES = {
  41. 'SOURCES': [
  42. 'API_DOC_SRCS-$(CONFIG_VP8_DECODER)',
  43. 'API_DOC_SRCS-yes',
  44. 'API_EXPORTS',
  45. 'API_SRCS-$(CONFIG_VP8_DECODER)',
  46. 'API_SRCS-yes',
  47. 'DSP_SRCS-yes',
  48. 'DSP_SRCS-yes+$(CONFIG_ENCODERS)',
  49. 'MEM_SRCS-yes',
  50. 'PORTS_SRCS-yes',
  51. 'SCALE_SRCS-$(CONFIG_SPATIAL_RESAMPLING)',
  52. 'SCALE_SRCS-no',
  53. 'SCALE_SRCS-yes',
  54. 'VP8_COMMON_SRCS-yes',
  55. 'VP8_DX_EXPORTS',
  56. 'VP8_DX_SRCS-$(CONFIG_MULTITHREAD)',
  57. 'VP8_DX_SRCS-no',
  58. 'VP8_DX_SRCS_REMOVE-no',
  59. 'VP8_DX_SRCS_REMOVE-yes',
  60. 'VP8_DX_SRCS-yes',
  61. 'VP9_COMMON_SRCS-yes',
  62. 'VP9_DX_EXPORTS',
  63. 'VP9_DX_SRCS-no',
  64. 'VP9_DX_SRCS_REMOVE-no',
  65. 'VP9_DX_SRCS_REMOVE-yes',
  66. 'VP9_DX_SRCS-yes',
  67. 'API_DOC_SRCS-$(CONFIG_VP8_ENCODER)',
  68. 'API_SRCS-$(BUILD_LIBVPX)',
  69. 'API_SRCS-$(CONFIG_VP8_ENCODER)',
  70. 'API_SRCS-$(CONFIG_VP9_ENCODER)',
  71. 'VP8_CX_EXPORTS',
  72. 'VP8_CX_SRCS-$(CONFIG_MULTI_RES_ENCODING)',
  73. 'VP8_CX_SRCS-$(CONFIG_MULTITHREAD)',
  74. 'VP8_CX_SRCS-$(CONFIG_TEMPORAL_DENOISING)',
  75. 'VP8_CX_SRCS-no',
  76. 'VP8_CX_SRCS_REMOVE-no',
  77. 'VP8_CX_SRCS_REMOVE-yes',
  78. 'VP8_CX_SRCS_REMOVE-yes+$(CONFIG_REALTIME_ONLY)',
  79. 'VP8_CX_SRCS-yes',
  80. 'VP9_CX_EXPORTS',
  81. 'VP9_CX_SRCS-no',
  82. 'VP9_CX_SRCS_REMOVE-no',
  83. 'VP9_CX_SRCS_REMOVE-yes',
  84. 'VP9_CX_SRCS-yes',
  85. ],
  86. 'X86_ASM': [
  87. 'DSP_SRCS-$(HAVE_MMX)',
  88. 'DSP_SRCS-$(HAVE_MMX)+$(CONFIG_ENCODERS)',
  89. 'DSP_SRCS-$(HAVE_SSE2)',
  90. 'DSP_SRCS-$(HAVE_SSE2)+$(CONFIG_ENCODERS)',
  91. 'DSP_SRCS-$(HAVE_SSE3)+$(CONFIG_ENCODERS)',
  92. 'DSP_SRCS-$(HAVE_SSE4_1)+$(CONFIG_ENCODERS)',
  93. 'DSP_SRCS-$(HAVE_SSSE3)+$(CONFIG_ENCODERS)',
  94. 'PORTS_SRCS-$(BUILD_LIBVPX)',
  95. 'PORTS_SRCS-$(BUILD_LIBVPX)+$(ARCH_X86)$(ARCH_X86_64)',
  96. 'PORTS_SRCS-yes+$(ARCH_X86)$(ARCH_X86_64)',
  97. 'VP8_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
  98. 'VP8_COMMON_SRCS-$(HAVE_MMX)',
  99. 'VP8_COMMON_SRCS-$(HAVE_MMX)+$(CONFIG_POSTPROC)',
  100. 'VP8_COMMON_SRCS-$(HAVE_SSE2)',
  101. 'VP8_COMMON_SRCS-$(HAVE_SSE2)+$(CONFIG_POSTPROC)',
  102. 'VP8_COMMON_SRCS-$(HAVE_SSE3)',
  103. 'VP8_COMMON_SRCS-$(HAVE_SSE4_1)',
  104. 'VP8_COMMON_SRCS-$(HAVE_SSSE3)',
  105. 'VP8_CX_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
  106. 'VP8_CX_SRCS-$(HAVE_MMX)',
  107. 'VP8_CX_SRCS-$(HAVE_SSE2)',
  108. 'VP8_CX_SRCS-$(HAVE_SSE2)+$(CONFIG_TEMPORAL_DENOISING)',
  109. 'VP8_CX_SRCS-$(HAVE_SSE4_1)',
  110. 'VP8_CX_SRCS-$(HAVE_SSSE3)',
  111. 'VP8_CX_SRCS_REMOVE-$(HAVE_SSE2)',
  112. 'VP8_CX_SRCS_REMOVE-$(HAVE_SSE2)+$(CONFIG_REALTIME_ONLY)',
  113. 'VP9_COMMON_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
  114. 'VP9_COMMON_SRCS-$(HAVE_MMX)',
  115. 'VP9_COMMON_SRCS-$(HAVE_SSE2)',
  116. 'VP9_COMMON_SRCS-$(HAVE_SSE2)+$(CONFIG_USE_X86INC)',
  117. 'VP9_COMMON_SRCS-$(HAVE_SSSE3)',
  118. 'VP9_COMMON_SRCS-$(HAVE_SSSE3)+$(CONFIG_USE_X86INC)',
  119. 'VP9_CX_SRCS-$(ARCH_X86)$(ARCH_X86_64)',
  120. 'VP9_CX_SRCS-$(HAVE_MMX)',
  121. 'VP9_CX_SRCS-$(HAVE_MMX)+$(CONFIG_USE_X86INC)',
  122. 'VP9_CX_SRCS-$(HAVE_SSE2)',
  123. 'VP9_CX_SRCS-$(HAVE_SSE2)+$(CONFIG_USE_X86INC)',
  124. 'VP9_CX_SRCS-$(HAVE_SSE3)',
  125. 'VP9_CX_SRCS-$(HAVE_SSE4_1)',
  126. 'VP9_CX_SRCS-$(HAVE_SSSE3)',
  127. ],
  128. 'X86-64_ASM': [
  129. 'VP8_COMMON_SRCS-$(HAVE_SSE2)+$(ARCH_X86_64)',
  130. 'VP8_CX_SRCS-$(ARCH_X86_64)',
  131. 'VP9_COMMON_SRCS-$(HAVE_SSSE3)+$(ARCH_X86_64)',
  132. 'VP9_CX_SRCS-$(ARCH_X86_64)',
  133. 'VP9_CX_SRCS-$(HAVE_SSSE3)+$(ARCH_X86_64)',
  134. ],
  135. 'ARM_ASM': [
  136. 'DSP_SRCS-$(HAVE_MEDIA)',
  137. 'DSP_SRCS-$(HAVE_MEDIA)+$(CONFIG_ENCODERS)',
  138. 'DSP_SRCS-$(HAVE_NEON)',
  139. 'DSP_SRCS-$(HAVE_NEON)+$(CONFIG_ENCODERS)',
  140. 'PORTS_SRCS-$(ARCH_ARM)',
  141. 'SCALE_SRCS-$(HAVE_NEON)',
  142. 'VP8_COMMON_SRCS-$(ARCH_ARM)',
  143. 'VP8_COMMON_SRCS-$(HAVE_MEDIA)',
  144. 'VP8_COMMON_SRCS-$(HAVE_NEON)',
  145. 'VP9_COMMON_SRCS-$(HAVE_NEON)',
  146. 'VP9_COMMON_SRCS-$(HAVE_NEON_ASM)',
  147. 'VP9_COMMON_SRCS-yes+$(HAVE_NEON_ASM)',
  148. 'VP8_CX_SRCS-$(ARCH_ARM)',
  149. 'VP8_CX_SRCS-$(HAVE_EDSP)',
  150. 'VP8_CX_SRCS-$(HAVE_MEDIA)',
  151. 'VP8_CX_SRCS-$(HAVE_NEON)',
  152. 'VP8_CX_SRCS-$(HAVE_NEON_ASM)',
  153. 'VP9_CX_SRCS-$(HAVE_NEON)',
  154. ],
  155. 'ERROR_CONCEALMENT': [
  156. 'VP8_DX_SRCS-$(CONFIG_ERROR_CONCEALMENT)',
  157. ],
  158. 'AVX2': [
  159. 'DSP_SRCS-$(HAVE_AVX2)',
  160. 'DSP_SRCS-$(HAVE_AVX2)+$(CONFIG_ENCODERS)',
  161. 'VP9_COMMON_SRCS-$(HAVE_AVX2)',
  162. 'VP9_CX_SRCS-$(HAVE_AVX2)',
  163. ],
  164. 'VP8_POSTPROC': [
  165. 'VP8_COMMON_SRCS-$(CONFIG_POSTPROC)',
  166. ],
  167. 'VP9_POSTPROC': [
  168. 'VP9_COMMON_SRCS-$(CONFIG_VP9_POSTPROC)',
  169. 'VP9_COMMON_SRCS-$(HAVE_SSE2)+$(CONFIG_VP9_POSTPROC)',
  170. ]
  171. }
  172. DISABLED_MODULES = [
  173. 'API_SRCS-$(CONFIG_SPATIAL_SVC)',
  174. 'API_SRCS-$(CONFIG_SPATIAL_SVC)+$(CONFIG_VP9_ENCODER)',
  175. 'MEM_SRCS-$(CONFIG_MEM_MANAGER)',
  176. 'MEM_SRCS-$(CONFIG_MEM_TRACKER)',
  177. 'VP8_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER)',
  178. 'VP9_COMMON_SRCS-$(CONFIG_POSTPROC_VISUALIZER)',
  179. 'VP8_CX_SRCS-$(CONFIG_INTERNAL_STATS)',
  180. 'VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS)',
  181. 'VP9_CX_SRCS-$(CONFIG_INTERNAL_STATS)+$(CONFIG_VP9_POSTPROC)',
  182. 'VP9_CX_SRCS-$(CONFIG_VP9_TEMPORAL_DENOISING)',
  183. 'VP9_CX_SRCS-$(HAVE_SSE2)+$(CONFIG_VP9_TEMPORAL_DENOISING)',
  184. # VP9_HIGHBITDEPTH
  185. 'DSP_SRCS-$(HAVE_SSE2)+$(CONFIG_VP9_HIGHBITDEPTH)',
  186. 'VP9_COMMON_SRCS-$(HAVE_SSE2)+$(CONFIG_VP9_HIGHBITDEPTH)',
  187. 'VP9_CX_SRCS-$(HAVE_SSE2)+$(CONFIG_VP9_HIGHBITDEPTH)',
  188. # use asm implementations instead of intrinsics
  189. # neon exists as assembly and intrinsics implementations.
  190. # If both are available prefer assembly (HAVE_NEON_ASM)
  191. 'VP9_COMMON_SRCS-yes+$(HAVE_NEON)',
  192. # mips files are also ignored via ignored_folders
  193. 'SCALE_SRCS-$(HAVE_DSPR2)',
  194. 'VP8_COMMON_SRCS-$(HAVE_DSPR2)',
  195. 'VP9_COMMON_SRCS-$(HAVE_DSPR2)',
  196. 'VP8_CX_SRCS_REMOVE-$(HAVE_EDSP)',
  197. 'VP9_COMMON_SRCS-$(HAVE_MSA)',
  198. 'VP9_CX_SRCS-$(HAVE_MSA)',
  199. ]
  200. libvpx_files = [
  201. 'build/make/ads2gas.pl',
  202. 'build/make/thumb.pm',
  203. 'LICENSE',
  204. 'PATENTS',
  205. ]
  206. ignore_files = [
  207. 'vp8/common/context.c',
  208. 'vp8/common/textblit.c',
  209. 'vp8/encoder/ssim.c',
  210. 'vp8/encoder/x86/ssim_opt.asm',
  211. 'vp9/common/vp9_textblit.c',
  212. 'vp9/common/vp9_textblit.h',
  213. 'vp9/encoder/vp9_ssim.c',
  214. 'vp9/encoder/x86/vp9_ssim_opt.asm',
  215. 'vpx_mem/vpx_mem_tracker.c',
  216. 'vpx_scale/generic/bicubic_scaler.c',
  217. 'vpx_scale/win32/scaleopt.c',
  218. 'vpx_scale/win32/scalesystemdependent.c',
  219. ]
  220. ignore_folders = [
  221. 'examples/',
  222. 'googletest/',
  223. 'libmkv/',
  224. 'libyuv/',
  225. 'mips/',
  226. 'nestegg/',
  227. 'objdir/',
  228. 'ppc/',
  229. 'test/',
  230. 'vpx_mem/memory_manager/',
  231. ]
  232. rename_files = {
  233. #avoid clash between vpx_dsp/x86 and vp8/common/x86
  234. 'vp8/common/x86/variance_mmx.c': 'vp8/common/x86/vp8_variance_mmx.c',
  235. 'vp8/common/x86/variance_sse2.c': 'vp8/common/x86/vp8_variance_sse2.c',
  236. 'vp8/common/x86/variance_impl_mmx.asm': 'vp8/common/x86/vp8_variance_impl_mmx.asm',
  237. #avoid clash with common/arm/neon/vp9_avg_neon.c
  238. 'vp9/encoder/arm/neon/vp9_avg_neon.c': 'vp9/encoder/arm/neon/vp9enc_avg_neon.c',
  239. }
  240. files = {
  241. 'EXPORTS': [
  242. 'vpx_mem/include/vpx_mem_intrnl.h',
  243. 'vpx_mem/vpx_mem.h',
  244. 'vpx_ports/arm.h',
  245. 'vpx_ports/mem.h',
  246. 'vpx_ports/vpx_timer.h',
  247. 'vpx_ports/x86.h',
  248. 'vpx_scale/vpx_scale.h',
  249. 'vpx_scale/yv12config.h',
  250. 'vpx/vp8cx.h',
  251. 'vpx/vp8dx.h',
  252. 'vpx/vp8.h',
  253. 'vpx/vpx_codec.h',
  254. 'vpx/vpx_decoder.h',
  255. 'vpx/vpx_encoder.h',
  256. 'vpx/vpx_frame_buffer.h',
  257. 'vpx/vpx_image.h',
  258. 'vpx/vpx_integer.h',
  259. ],
  260. 'X86-64_ASM': [
  261. 'third_party/x86inc/x86inc.asm',
  262. ],
  263. 'SOURCES': [
  264. 'vp8/common/rtcd.c',
  265. 'vp8/encoder/bitstream.c',
  266. 'vp8/encoder/onyx_if.c',
  267. 'vp8/vp8_dx_iface.c',
  268. 'vp9/common/vp9_alloccommon.c',
  269. 'vp9/common/vp9_blockd.c',
  270. 'vp9/common/vp9_common_data.c',
  271. 'vp9/common/vp9_convolve.c',
  272. 'vp9/common/vp9_debugmodes.c',
  273. 'vp9/common/vp9_entropy.c',
  274. 'vp9/common/vp9_entropymode.c',
  275. 'vp9/common/vp9_entropymv.c',
  276. 'vp9/common/vp9_filter.c',
  277. 'vp9/common/vp9_frame_buffers.c',
  278. 'vp9/common/vp9_idct.c',
  279. 'vp9/common/vp9_loopfilter.c',
  280. 'vp9/common/vp9_loopfilter_filters.c',
  281. 'vp9/common/vp9_mvref_common.c',
  282. 'vp9/common/vp9_pred_common.c',
  283. 'vp9/common/vp9_prob.c',
  284. 'vp9/common/vp9_quant_common.c',
  285. 'vp9/common/vp9_reconinter.c',
  286. 'vp9/common/vp9_reconintra.c',
  287. 'vp9/common/vp9_rtcd.c',
  288. 'vp9/common/vp9_scale.c',
  289. 'vp9/common/vp9_scan.c',
  290. 'vp9/common/vp9_seg_common.c',
  291. 'vp9/common/vp9_tile_common.c',
  292. 'vp9/decoder/vp9_decodeframe.c',
  293. 'vp9/decoder/vp9_decodemv.c',
  294. 'vp9/decoder/vp9_detokenize.c',
  295. 'vp9/decoder/vp9_dsubexp.c',
  296. 'vp9/decoder/vp9_dthread.c',
  297. 'vp9/decoder/vp9_reader.c',
  298. 'vp9/encoder/vp9_bitstream.c',
  299. 'vp9/encoder/vp9_dct.c',
  300. 'vp9/encoder/vp9_encodeframe.c',
  301. 'vp9/encoder/vp9_encodemb.c',
  302. 'vp9/encoder/vp9_encodemv.c',
  303. 'vp9/encoder/vp9_extend.c',
  304. 'vp9/encoder/vp9_firstpass.c',
  305. 'vp9/encoder/vp9_lookahead.c',
  306. 'vp9/encoder/vp9_mbgraph.c',
  307. 'vp9/encoder/vp9_mcomp.c',
  308. 'vp9/encoder/vp9_picklpf.c',
  309. 'vp9/encoder/vp9_pickmode.c',
  310. 'vp9/encoder/vp9_quantize.c',
  311. 'vp9/encoder/vp9_ratectrl.c',
  312. 'vp9/encoder/vp9_rdopt.c',
  313. 'vp9/encoder/vp9_resize.c',
  314. 'vp9/encoder/vp9_segmentation.c',
  315. 'vp9/encoder/vp9_subexp.c',
  316. 'vp9/encoder/vp9_temporal_filter.c',
  317. 'vp9/encoder/vp9_tokenize.c',
  318. 'vp9/encoder/vp9_treewriter.c',
  319. 'vp9/encoder/vp9_variance.c',
  320. 'vp9/encoder/vp9_writer.c',
  321. 'vp9/vp9_cx_iface.c',
  322. 'vp9/vp9_dx_iface.c',
  323. 'vpx/src/vpx_encoder.c',
  324. 'vpx_mem/vpx_mem.c',
  325. 'vpx_scale/vpx_scale_rtcd.c',
  326. 'vpx_scale/generic/yv12config.c',
  327. 'vpx_scale/generic/yv12extend.c',
  328. ]
  329. }
  330. manual = [
  331. # special case in moz.build
  332. 'vp8/encoder/boolhuff.c',
  333. # These 64-bit only files end up in X86_ASM. Filter them out.
  334. 'vp8/common/x86/loopfilter_block_sse2.asm',
  335. 'vp9/encoder/x86/vp9_quantize_ssse3.asm',
  336. # offsets are special cased in Makefile.in
  337. 'vp8/encoder/vp8_asm_enc_offsets.c',
  338. 'vpx_scale/vpx_scale_asm_offsets.c',
  339. # ignore while vp9 postproc is not enabled
  340. 'vp9/common/x86/vp9_postproc_mmx.asm',
  341. 'vp9/common/x86/vp9_postproc_sse2.asm',
  342. # ssim_opt is not enabled
  343. 'vp8/encoder/x86/ssim_opt.asm',
  344. 'vp9/encoder/x86/vp9_ssim_opt.asm',
  345. # asm includes
  346. 'vpx_ports/x86_abi_support.asm',
  347. ]
  348. platform_files = [
  349. 'vp8_rtcd.h',
  350. 'vp9_rtcd.h',
  351. 'vpx_config.asm',
  352. 'vpx_config.h',
  353. 'vpx_scale_rtcd.h',
  354. 'vpx_dsp_rtcd.h',
  355. ]
  356. def prepare_upstream(prefix, commit=None):
  357. upstream_url = 'https://chromium.googlesource.com/webm/libvpx'
  358. if os.path.exists(prefix):
  359. os.chdir(prefix)
  360. subprocess.call(['git', 'fetch', 'origin'])
  361. else:
  362. subprocess.call(['git', 'clone', upstream_url, prefix])
  363. os.chdir(prefix)
  364. if commit:
  365. subprocess.call(['git', 'checkout', commit])
  366. else:
  367. p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
  368. stdout, stderr = p.communicate()
  369. commit = stdout.strip()
  370. for target in PLATFORMS:
  371. target_objdir = os.path.join(prefix, 'objdir', target)
  372. if not os.path.exists(target_objdir):
  373. os.makedirs(target_objdir)
  374. os.chdir(target_objdir)
  375. configure = ['../../configure', '--target=%s' % target,
  376. '--disable-examples', '--disable-install-docs',
  377. '--enable-multi-res-encoding',
  378. '--size-limit=8192x4608'
  379. ]
  380. if 'darwin9' in target:
  381. configure += ['--enable-pic']
  382. if 'linux' in target:
  383. configure += ['--enable-pic']
  384. # x86inc.asm is not compatible with pic 32bit builds
  385. if target == 'x86-linux-gcc':
  386. configure += ['--disable-use-x86inc']
  387. if target == 'armv7-android-gcc':
  388. configure += ['--sdk-path=%s' % ndk_path]
  389. print "\n" + target_objdir
  390. print " ".join(configure)
  391. sys.stdout.flush()
  392. subprocess.call(configure)
  393. make_targets = [f for f in platform_files if not os.path.exists(f)]
  394. if make_targets:
  395. print " ".join(['make'] + make_targets)
  396. sys.stdout.flush()
  397. subprocess.call(['make'] + make_targets)
  398. for f in make_targets:
  399. if not os.path.exists(f):
  400. print "%s missing from %s, check toolchain" % (f, target)
  401. sys.exit(1)
  402. os.chdir(base)
  403. return commit
  404. def cleanup_upstream():
  405. shutil.rmtree(os.path.join(base, 'upstream/objdir'))
  406. def get_module(key):
  407. for module in MODULES:
  408. if key in MODULES[module]:
  409. return module
  410. def get_libvpx_files(prefix):
  411. for root, folders, files in os.walk(prefix):
  412. for f in files:
  413. f = os.path.join(root, f)[len(prefix):]
  414. if os.path.splitext(f)[-1] in extensions \
  415. and os.sep in f \
  416. and f not in ignore_files \
  417. and not any(folder in f for folder in ignore_folders):
  418. libvpx_files.append(f)
  419. return libvpx_files
  420. def get_sources(prefix):
  421. source = {}
  422. unknown = {}
  423. disabled = {}
  424. for mk in mk_files:
  425. with open(os.path.join(prefix, mk)) as f:
  426. base = os.path.dirname(mk)
  427. extra = ''
  428. for l in f:
  429. m = re.compile('ifeq +\((.*?\)), *yes\)').findall(l)
  430. if m:
  431. extra = '+' + m[0]
  432. if extra and l.startswith('else') or l.startswith('endif'):
  433. extra = ''
  434. if '+=' in l:
  435. l = l.split('+=')
  436. key = l[0].strip()
  437. key += extra
  438. value = l[1].strip().replace('$(ASM)', '.asm')
  439. value = os.path.join(base, value)
  440. if not key.startswith('#') and os.path.splitext(value)[-1] in extensions:
  441. if key not in source:
  442. source[key] = []
  443. source[key].append(value)
  444. for key in source:
  445. for f in source[key]:
  446. f = rename_files.get(f, f)
  447. if key.endswith('EXPORTS') and f.endswith('.h'):
  448. files['EXPORTS'].append(f)
  449. if os.path.splitext(f)[-1] in ('.c', '.asm') and not f in manual:
  450. module = get_module(key)
  451. if module:
  452. if not module in files:
  453. files[module] = []
  454. t = files[module]
  455. elif key in DISABLED_MODULES:
  456. if not key in disabled:
  457. disabled[key] = []
  458. t = disabled[key]
  459. else:
  460. if not key in unknown:
  461. unknown[key] = []
  462. t = unknown[key]
  463. t.append(f)
  464. for key in files:
  465. files[key] = list(sorted(set(files[key])))
  466. return source, files, disabled, unknown
  467. def update_sources_mozbuild(files, sources_mozbuild):
  468. f = StringIO()
  469. pprint(files, stream=f)
  470. sources_mozbuild_new = "files = {\n %s\n}\n" % f.getvalue().strip()[1:-1]
  471. if sources_mozbuild != sources_mozbuild_new:
  472. print 'updating sources.mozbuild'
  473. with open('sources.mozbuild', 'w') as f:
  474. f.write(sources_mozbuild_new)
  475. def get_current_files():
  476. current_files = []
  477. for root, folders, files in os.walk('.'):
  478. for f in files:
  479. f = os.path.join(root, f)[len('.%s'%os.sep):]
  480. if 'upstream%s'%os.sep in f or not os.sep in f:
  481. continue
  482. if os.path.splitext(f)[-1] in extensions:
  483. current_files.append(f)
  484. return current_files
  485. def is_new(a, b):
  486. return not os.path.exists(a) \
  487. or not os.path.exists(b) \
  488. or open(a).read() != open(b).read()
  489. def get_sources_mozbuild():
  490. with open('sources.mozbuild') as f:
  491. sources_mozbuild = f.read()
  492. exec(sources_mozbuild)
  493. return sources_mozbuild, files
  494. def update_and_remove_files(prefix, libvpx_files, files):
  495. current_files = get_current_files()
  496. def copy(src, dst):
  497. print ' ', dst
  498. shutil.copy(src, dst)
  499. # Update files
  500. first = True
  501. for f in libvpx_files:
  502. fdir = os.path.dirname(f)
  503. if fdir and not os.path.exists(fdir):
  504. os.makedirs(fdir)
  505. s = os.path.join(prefix, f)
  506. f = rename_files.get(f, f)
  507. if is_new(f, s):
  508. if first:
  509. print "Copy files:"
  510. first = False
  511. copy(s, f)
  512. # Copy configuration files for each platform
  513. for target in PLATFORMS:
  514. first = True
  515. for f in platform_files:
  516. t = os.path.splitext(f)
  517. t = '%s_%s%s' % (t[0], target, t[1])
  518. f = os.path.join(prefix, 'objdir', target, f)
  519. if is_new(f, t):
  520. if first:
  521. print "Copy files for %s:" % target
  522. first = False
  523. copy(f, t)
  524. # Copy vpx_version.h from one of the build targets
  525. s = os.path.join(prefix, 'objdir/x86-linux-gcc/vpx_version.h')
  526. f = 'vpx_version.h'
  527. if is_new(s, f):
  528. copy(s, f)
  529. # Remove unknown files from tree
  530. removed_files = [f for f in current_files if f not in libvpx_files and f not in rename_files.values()]
  531. for f in rename_files:
  532. if os.path.exists(f) and os.path.exists(rename_files[f]) and not f in removed_files:
  533. removed_files.append(f)
  534. if removed_files:
  535. print "Remove files:"
  536. for f in removed_files:
  537. os.unlink(f)
  538. print ' ', f
  539. def apply_patches():
  540. # Patch to permit vpx users to specify their own <stdint.h> types.
  541. os.system("patch -p0 < stdint.patch")
  542. # Patch to fix a crash caused by MSVC 2013
  543. os.system("patch -p3 < bug1137614.patch")
  544. # Bug 1176730 - Don't use pthread for libvpx in mingw builds.
  545. os.system("patch -p3 < disable_pthread_on_mingw.patch")
  546. # Cherry pick https://chromium-review.googlesource.com/#/c/276889/
  547. # to fix crash on 32bit
  548. os.system("patch -p1 < vp9_filter_restore_aligment.patch")
  549. # Patch win32 vpx_once.
  550. os.system("patch -p3 < vpx_once.patch")
  551. # Bug 1224363 - Clamp seg_lvl also in abs-value mode.
  552. os.system("patch -p3 < clamp_abs_lvl_seg.patch")
  553. # Bug 1224361 - Clamp QIndex also in abs-value mode.
  554. os.system("patch -p3 < clamp-abs-QIndex.patch")
  555. # Bug 1233983 - Make libvpx build with clang-cl
  556. os.system("patch -p3 < clang-cl.patch")
  557. # Bug 1224371 - Cast uint8_t to uint32_t before shift
  558. os.system("patch -p3 < cast-char-to-uint-before-shift.patch")
  559. # Bug 1237848 - Check lookahead ctx
  560. os.system("patch -p3 < 1237848-check-lookahead-ctx.patch")
  561. # Bug 1263384 - Check input frame resolution
  562. os.system("patch -p3 < input_frame_validation.patch")
  563. # Bug 1315288 - Check input frame resolution for vp9
  564. os.system("patch -p3 < input_frame_validation_vp9.patch")
  565. # Cherrypick fix from upstream
  566. os.system("patch -p3 < bug1480092.patch")
  567. def update_readme(commit):
  568. with open('README_MOZILLA') as f:
  569. readme = f.read()
  570. if 'The git commit ID used was' in readme:
  571. new_readme = re.sub('The git commit ID used was [a-f0-9]+',
  572. 'The git commit ID used was %s' % commit, readme)
  573. else:
  574. new_readme = "%s\n\nThe git commit ID used was %s\n" % (readme, commit)
  575. if readme != new_readme:
  576. with open('README_MOZILLA', 'w') as f:
  577. f.write(new_readme)
  578. def print_info(source, files, disabled, unknown, moz_build_files):
  579. for key in moz_build_files:
  580. if key not in files:
  581. print key, 'MISSING'
  582. else:
  583. gone = set(moz_build_files[key]) - set(files[key])
  584. new = set(files[key]) - set(moz_build_files[key])
  585. if gone:
  586. print key, 'GONE:'
  587. print ' '+ '\n '.join(gone)
  588. if new:
  589. print key, 'NEW:'
  590. print ' '+ '\n '.join(new)
  591. if unknown:
  592. print "Please update this script, the following modules are unknown"
  593. pprint(unknown)
  594. if DEBUG:
  595. print "===== SOURCE"
  596. pprint(source)
  597. print "===== FILES"
  598. pprint(files)
  599. print "===== DISABLED"
  600. pprint(disabled)
  601. print "===== UNKNOWN"
  602. pprint(unknown)
  603. if __name__ == '__main__':
  604. parser = argparse.ArgumentParser(description='''This script only works on Mac OS X since the OS X Toolchain is not available on other platforms.
  605. In addition you need XCode and the Android NDK installed.
  606. If commit hash is not provided, current git master is used.''')
  607. parser.add_argument('--debug', dest='debug', action="store_true")
  608. parser.add_argument('--ndk', dest='ndk', type=str)
  609. parser.add_argument('--commit', dest='commit', type=str, default=None)
  610. args = parser.parse_args()
  611. if sys.platform != 'darwin' or not args.ndk:
  612. parser.print_help()
  613. sys.exit(1)
  614. ndk_path = args.ndk
  615. commit = args.commit
  616. DEBUG = args.debug
  617. base = os.path.abspath(os.curdir)
  618. prefix = os.path.join(base, 'upstream/')
  619. commit = prepare_upstream(prefix, commit)
  620. libvpx_files = get_libvpx_files(prefix)
  621. source, files, disabled, unknown = get_sources(prefix)
  622. sources_mozbuild, moz_build_files = get_sources_mozbuild()
  623. print_info(source, files, disabled, unknown, moz_build_files)
  624. update_sources_mozbuild(files, sources_mozbuild)
  625. update_and_remove_files(prefix, libvpx_files, files)
  626. apply_patches()
  627. update_readme(commit)
  628. cleanup_upstream()