MCPcopy Index your code
hub / github.com/nodejs/node / Main

Function Main

deps/v8/tools/locs.py:370–454  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

368
369
370def Main():
371 out = sys.stdout
372 if ARGS['json']:
373 out = sys.stderr
374
375 compile_commands_file, ninja_deps_file = GenerateCompileCommandsAndBuild(
376 ARGS['build_dir'], out)
377
378 result = Results()
379 status = StatusLine()
380
381 try:
382 with open(compile_commands_file) as file:
383 compile_commands = json.load(file)
384 with open(ninja_deps_file) as file:
385 source_dependencies, header_dependents = parse_ninja_deps(file)
386 result.addHeaderDeps(source_dependencies, header_dependents)
387 except FileNotFoundError:
388 print("Error: Cannot read '{}'. Consult --help to get started.".format(
389 ninja_deps_file))
390 exit(1)
391
392 cmd_splitter = CommandSplitter()
393
394 def count_lines_of_unit(ikey):
395 i, key = ikey
396 if not result.track(key['file']):
397 return
398 message = "[{}/{}] Counting LoCs of {}".format(
399 i, len(compile_commands), key['file'])
400 status.print(message, file=out)
401 clangcmd, infilename, infile, outfilename = cmd_splitter.process(key)
402 if not infile.is_file():
403 return
404
405 clangcmd = clangcmd + " -E -P " + \
406 str(infile) + " -o /dev/stdout | sed '/^\\s*$/d' | wc -lc"
407 loccmd = ("cat {} | sed '\\;^\\s*//;d' | sed '\\;^/\\*;d'"
408 " | sed '/^\\*/d' | sed '/^\\s*$/d' | wc -lc")
409 loccmd = loccmd.format(infile)
410 runcmd = " {} ; {}".format(clangcmd, loccmd)
411 if ARGS['echocmd']:
412 print(runcmd)
413 process = subprocess.Popen(
414 runcmd, shell=True, cwd=key['directory'], stdout=subprocess.PIPE)
415 p = {'process': process, 'infile': infilename, 'outfile': outfilename}
416 output, _ = p['process'].communicate()
417 expanded, expanded_bytes, loc, in_bytes = list(map(int, output.split()))
418 result.recordFile(p['infile'], p['outfile'], loc,
419 in_bytes, expanded, expanded_bytes)
420
421 with tempfile.TemporaryDirectory(dir='/tmp/', prefix="locs.") as temp:
422 start = time.time()
423
424 with ThreadPoolExecutor(max_workers=ARGS['jobs']) as executor:
425 list(executor.map(count_lines_of_unit, enumerate(compile_commands)))
426
427 end = time.time()

Callers 1

locs.pyFile · 0.70

Calls 15

addHeaderDepsMethod · 0.95
printMethod · 0.95
printGroupResultsMethod · 0.95
printSortedMethod · 0.95
ResultsClass · 0.85
StatusLineClass · 0.85
parse_ninja_depsFunction · 0.85
CommandSplitterClass · 0.85
ratioMethod · 0.80
printFunction · 0.70
formatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…