4
4
# Use of this source code is governed by a BSD-style license that can be
5
5
# found in the LICENSE file.
6
6
7
- """Creates a GYP include file for building FFmpeg from source.
7
+ """Creates a GN include file for building FFmpeg from source.
8
8
9
9
The way this works is a bit silly but it's easier than reverse engineering
10
- FFmpeg's configure scripts and Makefiles. It scans through build directories for
11
- object files then does a reverse lookup against the FFmpeg source tree to find
12
- the corresponding C or assembly file.
10
+ FFmpeg's configure scripts and Makefiles and manually maintaining chromium
11
+ build files. It scans through build directories for object files then does a
12
+ reverse lookup against the FFmpeg source tree to find the corresponding C or
13
+ assembly file.
13
14
14
- Running build_ffmpeg.sh on each supported platform for all architecture is
15
+ Running build_ffmpeg.py on each supported platform for all architectures is
15
16
required prior to running this script. See build_ffmpeg.py for details as well
16
17
as the documentation at:
17
18
18
- https://docs.google.com/document/d/14bqZ9NISsyEO3948wehhJ7wc9deTIz-yHUhF1MQp7Po/edit?pli=1#heading=h.x346hhrqw4lx
19
+ https://docs.google.com/document/d/14bqZ9NISsyEO3948wehhJ7wc9deTIz-yHUhF1MQp7Po/edit
19
20
20
21
Once you've built all platforms and architectures you may run this script.
21
-
22
- While this seems insane, reverse engineering and maintaining a gyp file by hand
23
- is significantly more painful.
24
22
"""
25
23
26
24
__author__ = '[email protected] (Andrew Scherkus)'
44
42
# Use of this source code is governed by a BSD-style license that can be
45
43
# found in the LICENSE file.
46
44
47
- # NOTE: this file is autogenerated by ffmpeg/chromium/scripts/generate_gyp .py
45
+ # NOTE: this file is autogenerated by ffmpeg/chromium/scripts/generate_gn .py
48
46
49
47
""" % (datetime .datetime .now ().year )
50
48
51
- GYP_HEADER = """
52
- {
53
- 'variables': {
54
- """
55
-
56
- GYP_FOOTER = """ },
57
- }
58
- """
59
-
60
-
61
- GYP_CONDITIONAL_BEGIN = """ 'conditions': [
62
- """
63
- GYP_CONDITIONAL_END = """ ], # conditions
64
- """
65
- GYP_CONDITIONAL_STANZA_BEGIN = """ ['%s', {
66
- """
67
- GYP_CONDITIONAL_STANZA_ITEM = """ '%s',
68
- """
69
- GYP_CONDITIONAL_STANZA_OUTPUT_ITEM = """ '<(shared_generated_dir)/%s',
70
- """
71
- GYP_CONDITIONAL_STANZA_END = """ }], # %s
72
- """
73
-
74
- GYP_CONDITIONAL_C_SOURCE_STANZA_BEGIN = """ 'c_sources': [
75
- """
76
- GYP_CONDITIONAL_ASM_SOURCE_STANZA_BEGIN = """ 'asm_sources': [
77
- """
78
- GYP_CONDITIONAL_ITEM_STANZA_END = """ ],
79
- """
80
-
81
49
GN_HEADER = """import("//build/config/arm.gni")
82
50
import("ffmpeg_options.gni")
83
51
103
71
GN_SOURCE_END = """]
104
72
"""
105
73
106
- # Controls GYP conditional stanza generation.
74
+ # Controls conditional stanza generation.
107
75
Attr = enum ('ARCHITECTURE' , 'TARGET' , 'PLATFORM' )
108
76
SUPPORT_MATRIX = {
109
77
Attr .ARCHITECTURE :
114
82
115
83
116
84
def NormalizeFilename (name ):
117
- """ Removes leading path separators in an attempt to normalize paths."""
85
+ """Removes leading path separators in an attempt to normalize paths."""
118
86
return string .lstrip (name , os .sep )
119
87
120
88
@@ -200,7 +168,7 @@ def GetSourceFiles(source_dir):
200
168
"""
201
169
202
170
def IsSourceDir (d ):
203
- return d not in [ '.git' , '.svn' ]
171
+ return d != '.git'
204
172
205
173
source_files = []
206
174
for root , dirs , files in os .walk (source_dir ):
@@ -345,80 +313,8 @@ def IsEmpty(self):
345
313
"""
346
314
return (len (self .sources ) == 0 or len (self .conditions ) == 0 )
347
315
348
- def GenerateGypStanza (self ):
349
- """Generates a gyp conditional stanza representing this source set.
350
-
351
- TODO(scherkus): Having all this special case condition optimizing logic in
352
- here feels a bit dirty, but hey it works. Perhaps refactor if it starts
353
- getting out of hand.
354
-
355
- Returns:
356
- A string of gyp code.
357
- """
358
-
359
- conjunctions = []
360
- for condition in self .conditions :
361
- if condition .ARCHITECTURE == '*' :
362
- arch_condition = None
363
- elif condition .ARCHITECTURE == 'arm-neon' :
364
- arch_condition = 'target_arch == "arm" and arm_neon == 1'
365
- else :
366
- arch_condition = 'target_arch == "%s"' % condition .ARCHITECTURE
367
-
368
- if condition .TARGET == '*' :
369
- target_condition = None
370
- else :
371
- target_condition = 'ffmpeg_branding == "%s"' % condition .TARGET
372
-
373
- if condition .PLATFORM == '*' :
374
- platform_condition = None
375
- else :
376
- platform_condition = 'OS == "%s"' % condition .PLATFORM
377
-
378
- conjunction_parts = filter (
379
- None , [platform_condition , arch_condition , target_condition ])
380
- conjunctions .append (' and ' .join (conjunction_parts ))
381
-
382
- # If there is more that one clause, wrap various conditions in parens
383
- # before joining.
384
- if len (conjunctions ) > 1 :
385
- conjunctions = ['(%s)' % x for x in conjunctions ]
386
-
387
- # Sort conjunctions to make order deterministic.
388
- joined_conjunctions = ' or ' .join (sorted (conjunctions ))
389
- if not joined_conjunctions :
390
- joined_conjunctions = '(1)'
391
-
392
- stanza = []
393
- stanza += GYP_CONDITIONAL_STANZA_BEGIN % (joined_conjunctions )
394
-
395
- self .sources = sorted (n .replace ('\\ ' , '/' ) for n in self .sources )
396
-
397
- # Write out all C sources.
398
- c_sources = filter (IsCFile , self .sources )
399
- if c_sources :
400
- stanza += GYP_CONDITIONAL_C_SOURCE_STANZA_BEGIN
401
- for name in c_sources :
402
- stanza += GYP_CONDITIONAL_STANZA_ITEM % (name )
403
- stanza += GYP_CONDITIONAL_ITEM_STANZA_END
404
-
405
- # Write out all assembly sources.
406
- asm_sources = filter (IsAssemblyFile , self .sources )
407
- if asm_sources :
408
- stanza += GYP_CONDITIONAL_ASM_SOURCE_STANZA_BEGIN
409
- for name in asm_sources :
410
- stanza += GYP_CONDITIONAL_STANZA_ITEM % (name )
411
- stanza += GYP_CONDITIONAL_ITEM_STANZA_END
412
-
413
- stanza += GYP_CONDITIONAL_STANZA_END % (joined_conjunctions )
414
- return '' .join (stanza )
415
-
416
316
def GenerateGnStanza (self ):
417
- """Generates a gyp conditional stanza representing this source set.
418
-
419
- TODO(scherkus): Having all this special case condition optimizing logic in
420
- here feels a bit dirty, but hey it works. Perhaps refactor if it starts
421
- getting out of hand.
317
+ """Generates a gn conditional stanza representing this source set.
422
318
"""
423
319
424
320
conjunctions = []
@@ -708,19 +604,6 @@ def ParseOptions():
708
604
return options , args
709
605
710
606
711
- def WriteGyp (fd , disjoint_sets ):
712
- fd .write (COPYRIGHT )
713
- fd .write (GYP_HEADER )
714
-
715
- # Generate conditional stanza for each disjoint source set.
716
- fd .write (GYP_CONDITIONAL_BEGIN )
717
- for s in disjoint_sets :
718
- fd .write (s .GenerateGypStanza ())
719
- fd .write (GYP_CONDITIONAL_END )
720
-
721
- fd .write (GYP_FOOTER )
722
-
723
-
724
607
def WriteGn (fd , disjoint_sets ):
725
608
fd .write (COPYRIGHT )
726
609
fd .write (GN_HEADER )
@@ -730,7 +613,7 @@ def WriteGn(fd, disjoint_sets):
730
613
fd .write (s .GenerateGnStanza ())
731
614
732
615
733
- # Lists of files that are exempt from searching in GetIncludeSources .
616
+ # Lists of files that are exempt from searching in GetIncludedSources .
734
617
IGNORED_INCLUDE_FILES = [
735
618
# Chromium generated files
736
619
'config.h' ,
@@ -1035,15 +918,11 @@ def main():
1035
918
print 'License checks passed.'
1036
919
UpdateCredits (sources_to_check , source_dir )
1037
920
1038
- def WriteOutputFile (outfile , func ):
1039
- output_name = os .path .join (options .source_dir , outfile )
1040
- print 'Output:' , output_name
1041
-
1042
- with open (output_name , 'w' ) as fd :
1043
- func (fd , sets )
921
+ gn_file_name = os .path .join (options .source_dir , 'ffmpeg_generated.gni' )
922
+ print 'Writing:' , gn_file_name
923
+ with open (gn_file_name , 'w' ) as fd :
924
+ WriteGn (fd , sets )
1044
925
1045
- WriteOutputFile ('ffmpeg_generated.gni' , WriteGn )
1046
- WriteOutputFile ('ffmpeg_generated.gypi' , WriteGyp )
1047
926
1048
927
if __name__ == '__main__' :
1049
928
main ()
0 commit comments