Changeset ef56087 for tests/pybin


Ignore:
Timestamp:
Mar 7, 2022, 7:38:52 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
5baa33c
Parents:
fc01219
Message:

Fixed test.py to support -j.
(unlimited jobs)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    rfc01219 ref56087  
    322322        # tell make about the pipes
    323323        os.environ["MAKEFLAGS"] = os.environ["MFLAGS"] = " ".join(make_flags)
    324         print(os.environ["MFLAGS"])
    325324
    326325        # make sure pass the pipes to our children
     
    328327
    329328        return make_flags
     329
     330def prep_unlimited_recursive_make():
     331        # prep the flags for make
     332        make_flags = ["-j"]
     333
     334        # tell make about the pipes
     335        os.environ["MAKEFLAGS"] = os.environ["MFLAGS"] = "-j"
     336
     337        return make_flags
     338
     339
     340def eval_hardware():
     341        # we can create as many things as we want
     342        # how much hardware do we have?
     343        if settings.distribute:
     344                # remote hardware is allowed
     345                # how much do we have?
     346                ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
     347                return int(jstr.strip()) if ret == 0 else multiprocessing.cpu_count()
     348        else:
     349                # remote isn't allowed, use local cpus
     350                return multiprocessing.cpu_count()
    330351
    331352# count number of jobs to create
     
    375396                                sys.exit(1)
    376397
    377                         # we can create as many things as we want
    378                         # how much hardware do we have?
    379                         if settings.distribute:
    380                                 # remote hardware is allowed
    381                                 # how much do we have?
    382                                 ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
    383                                 options.jobs = int(jstr.strip()) if ret == 0 else multiprocessing.cpu_count()
    384                         else:
    385                                 # remote isn't allowed, use local cpus
    386                                 options.jobs = multiprocessing.cpu_count()
    387 
    388                         make_flags = prep_recursive_make(options.jobs)
     398                        options.jobs = eval_hardware()
     399                        flags = prep_unlimited_recursive_make()
    389400
    390401
     
    397408
    398409        # Arguments are calling the shots, fake the top level make
    399         elif options.jobs:
     410        elif options.jobs :
     411
    400412                # make sure we have a valid number of jobs that corresponds to user input
    401                 if options.jobs <= 0 :
     413                if options.jobs < 0 :
    402414                        print('ERROR: Invalid number of jobs', file=sys.stderr)
    403415                        sys.exit(1)
    404416
    405417                flags = prep_recursive_make(options.jobs)
     418
     419        # Arguments are calling the shots, fake the top level make, but 0 is a special case
     420        elif options.jobs == 0:
     421                options.jobs = eval_hardware()
     422                flags = prep_unlimited_recursive_make()
    406423
    407424        # No one says to run in parallel, then don't
     
    412429        # Make sure we call make as expected
    413430        settings.update_make_cmd( flags )
     431        print(flags)
     432        print(os.environ.get('MAKEFLAGS'))
    414433
    415434        # return the job count
Note: See TracChangeset for help on using the changeset viewer.