@@ -119,17 +119,19 @@ def GetDefinition(var, source, step=30):
119
119
return definition , len (code_points )
120
120
121
121
122
- def AddModule (filename , definitions , initializers ):
122
+ def AddModule (root , filename , definitions , initializers ):
123
123
code = ReadFile (filename )
124
- name = NormalizeFileName (filename )
124
+ name = NormalizeFileName (root , filename )
125
125
slug = SLUGGER_RE .sub ('_' , name )
126
126
var = slug + '_raw'
127
127
definition , size = GetDefinition (var , code )
128
128
initializer = INITIALIZER .format (name , var , size )
129
129
definitions .append (definition )
130
130
initializers .append (initializer )
131
131
132
- def NormalizeFileName (filename ):
132
+ def NormalizeFileName (root , filename ):
133
+ if root :
134
+ filename = os .path .relpath (filename , root )
133
135
split = filename .split ('/' )
134
136
if split [0 ] == 'deps' :
135
137
split = ['internal' ] + split
@@ -140,15 +142,15 @@ def NormalizeFileName(filename):
140
142
return os .path .splitext (filename )[0 ]
141
143
142
144
143
- def JS2C (source_files , target ):
145
+ def JS2C (root , source_files , target ):
144
146
# Build source code lines
145
147
definitions = []
146
148
initializers = []
147
149
148
150
for filename in source_files ['.js' ]:
149
- AddModule (filename , definitions , initializers )
151
+ AddModule (root , filename , definitions , initializers )
150
152
for filename in source_files ['.mjs' ]:
151
- AddModule (filename , definitions , initializers )
153
+ AddModule (root , filename , definitions , initializers )
152
154
153
155
config_def , config_size = handle_config_gypi (source_files ['config.gypi' ])
154
156
definitions .append (config_def )
@@ -215,6 +217,10 @@ def main():
215
217
'--directory' ,
216
218
default = None ,
217
219
help = 'input file directory' )
220
+ parser .add_argument (
221
+ '--root' ,
222
+ default = None ,
223
+ help = 'root directory containing the sources' )
218
224
parser .add_argument ('--verbose' , action = 'store_true' , help = 'output file' )
219
225
parser .add_argument ('sources' , nargs = '*' , help = 'input files' )
220
226
options = parser .parse_args ()
@@ -231,9 +237,10 @@ def main():
231
237
# Should have exactly 3 types: `.js`, `.mjs` and `.gypi`
232
238
assert len (source_files ) == 3
233
239
# Currently config.gypi is the only `.gypi` file allowed
234
- assert source_files ['.gypi' ] == ['config.gypi' ]
240
+ assert len (source_files ['.gypi' ]) == 1
241
+ assert os .path .basename (source_files ['.gypi' ][0 ]) == 'config.gypi'
235
242
source_files ['config.gypi' ] = source_files .pop ('.gypi' )[0 ]
236
- JS2C (source_files , options .target )
243
+ JS2C (options . root , source_files , options .target )
237
244
238
245
239
246
if __name__ == "__main__" :
0 commit comments