initial commit

Change-Id: I6fc3fd7babab231f4389689f9166e04ffba70136
This commit is contained in:
Mark Charney
2016-12-15 14:25:06 -05:00
commit 52ceb3152e
51 changed files with 9183 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.pyc
*~
*#
.#*

178
LICENSE.txt Normal file
View File

@@ -0,0 +1,178 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

2
MANIFEST.in Normal file
View File

@@ -0,0 +1,2 @@
include m*.py
include __init__.py

13
README.md Normal file
View File

@@ -0,0 +1,13 @@
MBUILD USER INFO
-----------------
See:
https://intelxed.github.io/
and
https://github.com/intelxed/mbuild
Documentation generation manual:
http://epydoc.sourceforge.net/epydoc.html
To generate documentation from a check'ed out source tree, see "build-doc"

10
build-doc Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/csh
seet webdir=/var/www/html/mjcharne/mbuild
epydoc -v --simple-term --no-private --html -o epydoc-out --name mbuild --url 'http://mjc.intel.com/mjcharne/mbuild' mbuild/__init__.py
rm -rf $webdir/epydoc.old
mv $webdir/epydoc $webdir/epydoc.old
mkdir -p $webdir/epydoc
cp epydoc-out/* $webdir/epydoc
make-web-accessible $webdir/epydoc

7
do-dist Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/csh -f
#
# edit setup.py, set the version number
python setup.py sdist --formats=gztar,zip
cp dist/* /home/mjcharne/www/mbuild/download
make-web-accessible /home/mjcharne/www/mbuild/download

139
mbuild/__init__.py Executable file
View File

@@ -0,0 +1,139 @@
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
# __init__.py
# Mark Charney
"""This is mbuild: a simple portable dependence-based build-system
written in python.
mbuild is a python-based build system very similar to scons with some
philosophical features of make. mbuild exposes the scan and build phases
allowing them to be repeated as necessary. Multiple DAGs can be
built, one during each scan phase.
Conceptually there are 3 major components to mbuild:
- The environment L{env_t}
- The directed acyclic graph L{dag_t}
- The work queue L{work_queue_t}
Using the environment L{env_t} you customize your build configuration
and construct names for your source files, object files, executables,
etc. The environment contains builder methods that create L{plan_t}
objects. There are builders for C, C++, static and dynamic libraries,
assembly files and linking programs. The environment and builders
support string substitution.
The L{plan_t} objects are passed to the L{dag_t} which stores the
dependences that order execution. The L{plan_t} objects describe work
that needs to be done. Plans typically contain a command line strings
(with all substitutions done), but can also be python functions that
will be executed during the build.
Using the L{plan_t} objects, the L{dag_t} creates L{command_t}
objects that are passed to the L{work_queue_t} to ultimately build the
target or targets.
Your build file can have multiple environments, DAGS and work queues.
Using the environment dictionary
================================
You can bind or augmenting environment variables from the command
line. For example, one can say C{build_cpu=ia32} on an x86-64 system
to change the default compilation behavior. Similarly, one can say
C{CXXFLAGS+=-g} to add the C{-g} flag to the existing C{CXXFLAGS}
variable.
Dynamic substitution is also used. Patterns of the form %(I{string})s
will substitute I{string} dynamically before it is used. The
expansion can happen directly from the environment and is
recursive. The expansion can also use dictionaries that are variables
in the environment. A dictionary in the environment is really a tuple
of the key-variable and the dictionary itself.
For example::
env['opt_flag'] = ( 'opt', {'noopt':'',
'0':'%(OPTOPT)s0',
'1':'%(OPTOPT)s1',
'2':'%(OPTOPT)s2',
'3':'%(OPTOPT)s3',
'4':'%(OPTOPT)s4'} )
env['OPTOPT'] = ( 'compiler', { 'gnu':'-O',
'ms':'/O'})
env['CXXFLAGS'] += ' %(opt_flag)s'
The C{OPTOPT} variable depends on C{env['compiler']}.
If C{env['compiler']='gnu'} then C{env['OPTOPT']} expands to C{-O}.
If C{env['compiler']='ms'} then C{env['OPTOPT']} expands to C{/O}.
If the C{opt} variable is set "C{opt=3}" on the command line, or equivalently
if C{env['opt']='3'} is
set in the script,
then if the C{env['compiler']='gnu'} in the environment at the time of expansion,
then the flag in the
C{CXXFLAGS} will be C{-O3}. If C{env['compiler']='ms'} at the time of expansion,
then the optimiation
flag would be C{/O3}. If C{opt=noopt} (on the command line) then there will be no
optimization flag in the C{CXXFLAGS}.
Introspection
=============
The L{command_t} that are executed during the build have their output
(stdout/stderr) stored in the L{dag_t}. After a build it is possible
to collect the commands using the L{dag_t.results} function and analyze the
output. This is very handy for test and validation suites.
"""
from base import *
from dag import *
from work_queue import *
from env import *
from util import *
from plan import *
from arar import *
from doxygen import doxygen_run, doxygen_args, doxygen_env
from header_tag import *
__all__ = [ 'base',
'dag',
'work_queue',
'env',
'util',
'plan',
'msvs',
'arar',
'doxygen',
'dfs',
'header_tag' ]
import time
def mbuild_exit():
"""mbuild's exit function"""
#print "SLEEPING"
#time.sleep(0.5)
#print "EXITING"
import atexit
atexit.register(mbuild_exit)

80
mbuild/arar.py Executable file
View File

@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- python -*-
# Repackage a bunch of static libs as one big static library.
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import os
import sys
import shutil
import re
class arar_error(Exception):
def __init__(self, value):
self.value = value
def _str__(self):
return repr(self.value)
def repack(files, ar='ar', target='liball.a', verbose=False):
"""For linux only. Repackage the list of files using ar as the
archiver program. The input files list can contain .a or .o
files. The output library name is supplied by the target keyword
argument. This will raise an exception arar_error in the event of
a problem, setting the exception value field with an explanation."""
import glob
pid= os.getpid()
#error=os.system(ar + " --version")
tdir = 'tmp.arar.%d' % (pid)
if os.path.exists(tdir):
raise arar_error('Conflict with existing temporary directory: %s' % \
(tdir))
os.mkdir(tdir)
# work in a temporary subdirectory
os.chdir(tdir)
doto = []
for arg in files:
if re.search(r'[.]o$', arg):
if arg[0] == '/':
doto.append(arg)
else:
doto.append(os.path.join('..',arg))
continue
if arg[0] == '/':
cmd = "%s x %s" % (ar,arg)
else:
cmd = "%s x ../%s" % (ar,arg)
if verbose:
print "EXTRACTING %s" % (cmd)
error= os.system(cmd)
if error:
raise arar_error('Extract failed for command %s' % (cmd))
files = glob.glob('*.o') + doto
local_target = os.path.basename(target)
cmd = "%s rcv %s %s" % (ar, local_target, " ".join(files))
if verbose:
print "RECOMBINING %s" % (cmd)
error=os.system(cmd)
if error:
raise arar_error('Recombine failed')
os.chdir('..')
os.rename(os.path.join(tdir,local_target), target)
if verbose:
print "CREATED %s" % (target)
shutil.rmtree(tdir)

191
mbuild/base.py Executable file
View File

@@ -0,0 +1,191 @@
#!/usr/bin/env python
# -*- python -*-
# Mark Charney
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
"""Base functionality: messages, verbosity, python version checking"""
import os
import sys
import traceback
_mbuild_verbose_level = 1
def verbose(level=0):
"""Return True if the configured message level supplied is >= the
level arguement
@param level: int
@param level: the verbosity level at which this function should return True
@rtype: bool
@return: True iff the level argument is >= current verbosity level
"""
global _mbuild_verbose_level
if _mbuild_verbose_level >= level:
return True
return False
def set_verbosity(v):
"""Set the global verbosity level. 0=quiet, 99=very very noisy"""
global _mbuild_verbose_level
_mbuild_verbose_level = v
def get_verbosity():
"""Return the global verbosity level. 0=quiet, 99=very very noisy"""
global _mbuild_verbose_level
return _mbuild_verbose_level
def bracket(s,m=''):
"""add a bracket around s and append m.
@rtype: string
@return: a bracketed string s and a suffixed message m
"""
return '[%s] %s' % (s,str(m))
def error_msg(s,t):
"""Emit '[s] t' to stderr with a newline"""
sys.stderr.write(bracket(s,t) + "\n")
def msg(s, pad=''):
"""Emit s to stdout with a newline"""
sys.stdout.write(pad)
sys.stdout.write(s)
sys.stdout.write("\n")
def msgn(s, pad=''):
"""Emit s to stdout without a newline"""
sys.stdout.write(pad)
sys.stdout.write(s)
def msgb(s,t='',pad=''):
"""a bracketed string s sent to stdout, followed by a string t"""
msg(bracket(s,t), pad=pad)
def vmsgb(v,s,t='',pad=''):
"""If verbosity v is sufficient, emit a bracketed string s sent to
stdout, followed by a string t"""
if verbose(v):
msg(bracket(s,t),pad=pad)
def cond_die(v, cmd, msg):
"""Conditionally die, if v is not zero. Print the msg and the cmd.
@type v: int
@param v: we die if v is not 0
@type cmd: string
@param cmd: a command to print
@type msg: string
@param msg: a message to print before the command
"""
if v != 0:
s = msg + "\n [CMD] " + cmd
die(s)
def die(m,s=''):
"""Emit an error message m (and optionally s) and exit with a return value 1"""
msgb("MBUILD ERROR", "%s %s\n\n" % (m,s) )
traceback.print_exc(file=sys.stdout)
sys.exit(1)
def warn(m):
"""Emit an warning message"""
msgb("MBUILD WARNING", m)
def get_python_version():
"""Return the python version as an integer
@rtype: int
@return: major * 100000 + minor + 1000 + fixlevel
"""
tuple = sys.version_info
major = int(tuple[0])
minor = int(tuple[1])
fix = int(tuple[2])
vnum = major *100000 + minor * 1000 + fix
return vnum
def get_python_version_tuple():
"""Return the python version as a tuple (major,minor,fixlevel)
@rtype: tuple
@return: (major,minor,fixlevel)
"""
tuple = sys.version_info
major = int(tuple[0])
minor = int(tuple[1])
fix = int(tuple[2])
return (major,minor,fix)
def check_python_version(maj,minor,fix=0):
"""Return true if the current python version at least the one
specified by the arguments.
@rtype: bool
@return: True/False
"""
t = get_python_version_tuple()
if t[0] > maj:
return True
if t[0] == maj and t[1] > minor:
return True
if t[0] == maj and t[1] == minor and t[2] >= fix:
return True
return False
try:
if check_python_version(2,4) == False:
die("MBUILD error: Need Python version 2.4 or later.")
except:
die("MBUILD error: Need Python version 2.4 or later.")
import platform # requires python 2.3
_on_mac = False
_on_native_windows = False
_on_windows = False # cygwin or native windows
_on_cygwin = False
_on_linux = False
_on_freebsd = False
_operating_system_name = platform.system()
if _operating_system_name.find('CYGWIN') != -1:
_on_cygwin = True
_on_windows = True
elif _operating_system_name == 'Microsoft' or _operating_system_name == 'Windows':
_on_native_windows = True
_on_windows = True
elif _operating_system_name == 'Linux':
_on_linux = True
elif _operating_system_name == 'FreeBSD':
_on_freebsd = True
elif _operating_system_name == 'Darwin':
_on_mac = True
else:
die("Could not detect operating system type: " + _operating_system_name)
def on_native_windows():
"""
@rtype: bool
@return: True iff on native windows win32/win64
"""
global _on_native_windows
return _on_native_windows
def on_windows():
"""
@rtype: bool
@return: True iff on windows cygwin/win32/win64
"""
global _on_windows
return _on_windows

450
mbuild/build_env.py Executable file
View File

@@ -0,0 +1,450 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
"""Setup functions for the ms/gnu compiler environment"""
import os
import sys
import platform
from base import *
from util import *
from env import *
import msvs
def set_compiler_env_common(env):
"""Set up some common stuff that depends heavily on the compiler setting"""
# This whole section was really an experiment in how dynamically I
# could do substitutions.
env['debug_flag'] = ( 'debug', { True: '%(DEBUGFLAG)s',
False:''})
env['debug_flag_link'] = ( 'debug', { True: '%(DEBUGFLAG_LINK)s',
False:''})
win_shared_compile_dict = ( 'compiler', { 'ms': '/MD',
'icl': '/MD',
'otherwise': '',
})
shared_compile_dict = ( 'host_os', { 'android': '-fPIC',
'lin': '-fPIC',
'win': win_shared_compile_dict,
'bsd': '-fPIC',
'otherwise': '',
})
env['shared_compile_flag'] = ( 'shared', { True: shared_compile_dict,
False:''})
shared_link_dict = ('compiler', { 'ms':'/dll',
'icl':'/dll',
'icc':'-shared',
'gnu':'-shared'})
env['shared_link'] = ( 'shared', { True: shared_link_dict,
False:''})
env['OPTOPT'] = ( 'compiler', { 'gnu':'-O',
'clang':'-O',
'iclang':'-O',
'icc':'-O',
'icl':'/O',
'ms':'/O'})
env['nologo'] = ( 'compiler', { 'gnu':'',
'clang':'',
'iclang':'',
'icc':'',
'icl':'/nologo',
'ms':'/nologo'})
flags = ''
flags += ' %(debug_flag)s'
flags += ' %(nologo)s'
flags += ' %(opt_flag)s'
flags += ' %(shared_compile_flag)s'
env['CCFLAGS'] = flags
env['CXXFLAGS'] = flags
env['LINKFLAGS'] += ' %(debug_flag_link)s'
def add_gnu_arch_flags(d):
"""Accept a dictionary, return a string"""
if d['compiler'] in ['gnu','clang'] and d['gcc_version'] != '2.96': # FIXME: iclang?
if d['host_cpu'] == 'x86-64':
return '-m64'
elif d['host_cpu'] == 'ia32':
return '-m32'
return ''
def set_env_gnu(env):
"""Example of setting up the GNU GCC environment for compilation"""
set_compiler_env_common(env)
env['opt_flag'] = ( 'opt', {'noopt':'',
's':'%(OPTOPT)ss',
'0':'%(OPTOPT)s0',
'1':'%(OPTOPT)s1',
'2':'%(OPTOPT)s2',
'3':'%(OPTOPT)s3',
'4':'%(OPTOPT)s4'} )
# lazy toolchain and other env var (f) expansion
mktool = lambda(f): "%(toolchain)s%(" + f + ")s"
if env['CXX_COMPILER'] == '':
env['CXX_COMPILER'] = ( 'compiler', { 'gnu':'g++',
'icc':'icpc',
'iclang':'icl++',
'clang':'clang++'})
if env['CC_COMPILER'] == '':
env['CC_COMPILER'] = ( 'compiler', { 'gnu':'gcc',
'icc':'icc',
'iclang':'icl',
'clang':'clang' })
if env['ASSEMBLER'] == '':
env['ASSEMBLER'] = ( 'compiler', { 'gnu':'gcc',
'icc':'icc',
'iclang':'icl',
'clang':'yasm' })
if env['LINKER'] == '':
env['LINKER'] = '%(CXX_COMPILER)s' # FIXME C++ or C?
if env['ARCHIVER'] == '':
env['ARCHIVER'] = ( 'compiler', { 'gnu': 'ar', # or GAR??
'icc' : 'xiar',
'iclang' : 'xiar',
'clang':'ar' })
if env['RANLIB_CMD'] == '':
env['RANLIB_CMD'] = 'ranlib'
if env['CC'] == '':
env['CC'] = mktool('CC_COMPILER')
if env['CXX'] == '':
env['CXX'] = mktool('CXX_COMPILER')
if env['AS'] == '':
env['AS'] = mktool('ASSEMBLER')
if env['LINK'] == '':
env['LINK'] = mktool('LINKER')
if env['AR'] == '':
env['AR'] = mktool('ARCHIVER')
if env['RANLIB'] == '':
env['RANLIB'] = mktool('RANLIB_CMD')
# if using gcc to compile include -c. If using gas, omit the -c
env['ASFLAGS'] = ' -c'
env['ARFLAGS'] = "rcv"
env['STATIC'] = ( 'static', { True : "-static",
False : "" } )
env['LINKFLAGS'] += " %(STATIC)s"
env['GNU64'] = add_gnu_arch_flags # dynamically called function during variable expansion!
s = ' %(GNU64)s'
env['CCFLAGS'] += s
env['CXXFLAGS'] += s
env['LINKFLAGS'] += s
# if using gcc to compile use -m64, otherwise if gas is used, omit the -m64.
env['ASFLAGS'] += s
env['DEBUGFLAG'] = '-g'
env['DEBUGFLAG_LINK'] = '-g'
env['COPT'] = '-c'
env['DOPT'] = '-D'
env['ASDOPT'] = '-D'
env['IOPT'] = '-I'
env['ISYSOPT'] = '-isystem ' # trailing space required
env['LOPT'] = '-L'
env['COUT'] = '-o '
env['ASMOUT'] = '-o '
env['LIBOUT'] = ' ' # nothing when using gar/ar
env['LINKOUT'] = '-o '
env['EXEOUT'] = '-o '
if env.on_mac():
env['DLLOPT'] = '-shared' # '-dynamiclib'
else:
env['DLLOPT'] = '-shared -Wl,-soname,%(SOLIBNAME)s'
env['OBJEXT'] = '.o'
if env.on_windows():
env['EXEEXT'] = '.exe'
env['DLLEXT'] = '.dll'
env['LIBEXT'] = '.lib'
env['PDBEXT'] = '.pdb'
elif env.on_mac():
env['EXEEXT'] = ''
env['DLLEXT'] = '.dylib'
env['LIBEXT'] = '.a'
env['PDBEXT'] = ''
else:
env['EXEEXT'] = ''
env['DLLEXT'] = '.so'
env['LIBEXT'] = '.a'
env['PDBEXT'] = ''
def find_ms_toolchain(env):
if env['msvs_version']:
env['setup_msvc']=True
if env['vc_dir'] == '' and not env['setup_msvc']:
if 'MSVCDir' in os.environ:
vs_dir = os.environ['MSVCDir']
if os.path.exists(vs_dir):
env['vc_dir'] = vs_dir
elif 'VCINSTALLDIR' in os.environ:
vc_dir = os.environ['VCINSTALLDIR']
if os.path.exists(vc_dir):
env['vc_dir'] = vc_dir
msvs7 = os.path.join(env['vc_dir'],"Vc7")
if os.path.exists(msvs7):
env['vc_dir'] = msvs7
elif 'VSINSTALLDIR' in os.environ:
vs_dir = os.environ['VSINSTALLDIR']
if os.path.exists(vs_dir):
env['vc_dir'] = os.path.join(vs_dir, 'VC')
elif 'MSVCDIR' in os.environ:
vs_dir = os.environ['MSVCDIR']
if os.path.exists(vs_dir):
env['vc_dir'] = vs_dir
if env['vc_dir'] == '' or env['setup_msvc']:
env['vc_dir'] = msvs.set_msvs_env(env)
# toolchain is the bin directory of the compiler with a trailing slash
if env['toolchain'] == '' and env['vc_dir'] and env['compiler']=='ms':
toolchain = ''
if env['build_cpu'] == 'ia32' and env['host_cpu'] == 'ia32':
toolchain = os.path.join(env['vc_dir'], 'bin', '')
elif env['build_cpu'] == 'ia32' and env['host_cpu'] == 'x86-64':
toolchain = os.path.join(env['vc_dir'], 'bin', 'x86_amd64', '')
elif env['build_cpu'] == 'x86-64' and env['host_cpu'] == 'x86-64':
toolchain = os.path.join(env['vc_dir'], 'bin', 'amd64', '')
elif env['build_cpu'] == 'x86-64' and env['host_cpu'] == 'ia32':
toolchain = os.path.join(env['vc_dir'], 'bin', '')
elif env['compiler'] == 'ms':
die("Unknown build/target combination. build cpu=%s, " +
"host_cpu=%s" % ( env['build_cpu'], env['host_cpu']))
env['toolchain'] = toolchain # default toolchain that we discover
def set_env_ms(env):
"""Example of setting up the MSVS environment for compilation"""
set_compiler_env_common(env)
# FIXME: allow combinations of options
env['opt_flag'] = ( 'opt', {'noopt':'',
'0':'%(OPTOPT)sd',
'1':'%(OPTOPT)s1',
'2':'%(OPTOPT)s2',
'3':'%(OPTOPT)s2', # map O3 and O4 to O2
'4':'%(OPTOPT)s2', # map O3 and O4 to O2
'b':'%(OPTOPT)sb',
'i':'%(OPTOPT)si',
's':'%(OPTOPT)ss',
'x':'%(OPTOPT)sx',
'd':'%(OPTOPT)sd',
'g':'%(OPTOPT)sg'} )
env['ASFLAGS'] = '/c /nologo '
env['LINKFLAGS'] += ' /nologo'
env['ARFLAGS'] = '/nologo'
env['link_prefix'] = ('use_compiler_to_link', { True:'/link',
False:'' })
if env['host_cpu'] == 'ia32':
env['LINKFLAGS'] += ' %(link_prefix)s /MACHINE:X86'
env['ARFLAGS'] += ' /MACHINE:X86'
elif env['host_cpu'] == 'x86-64':
env['LINKFLAGS'] += ' %(link_prefix)s /MACHINE:X64'
env['ARFLAGS'] += ' /MACHINE:X64'
env['favor'] = ( 'compiler', { 'ms' : ' /favor:EM64T',
'otherwise' : '' })
env['CXXFLAGS'] += ' %(favor)s'
env['CCFLAGS'] += ' %(favor)s'
elif env['host_cpu'] == 'ipf':
env['LINKFLAGS'] += ' %(link_prefix)s /MACHINE:IA64'
env['ARFLAGS'] += ' /MACHINE:IA64'
env['COPT'] = '/c'
env['DOPT'] = '/D'
env['ASDOPT'] = '/D'
# I use '-I' instead of '/I' because it simplifies use of YASM
# which requires -I for includes.
env['IOPT'] = '-I' # -I or /I works with MSVS8.
env['ISYSOPT'] = '-I' # MSVS has not -isystem so we use -I
env['LOPT'] = '%(link_prefix)s /LIBPATH:'
# Some options differ when using the compiler to link programs.
# Note: /Zi has parallel-build synchronization bugs
env['DEBUGFLAG'] = '/Z7'
env['DEBUGFLAG_LINK'] = ('use_compiler_to_link', { True:'/Z7', # of /Zi
False:'/debug'})
env['COUT'] = '/Fo'
env['ASMOUT'] = '/Fo'
env['LIBOUT'] = '/out:'
env['EXEOUT'] = '/Fe'
env['LINKOUT'] = ('use_compiler_to_link',{ True:'/Fo',
False:'/OUT:'})
env['DLLOPT'] = '/dll'
env['OBJEXT'] = '.obj'
env['LIBEXT'] = '.lib'
env['DLLEXT'] = '.dll'
env['EXEEXT'] = '.exe'
env['PDBEXT'] = '.pdb'
env['PDBEXT'] = '.pdb'
env['RCEXT'] = '.rc'
env['RESEXT'] = '.res'
find_ms_toolchain(env)
if env['ASSEMBLER'] == '':
if env['host_cpu'] == 'ia32':
env['ASSEMBLER'] = 'ml.exe'
elif env['host_cpu'] == 'x86-64':
env['ASSEMBLER'] = 'ml64.exe'
if env['CXX_COMPILER'] == '':
env['CXX_COMPILER'] = ( 'compiler', { 'ms':'cl.exe',
'icl':'icl.exe' })
if env['CC_COMPILER'] == '':
env['CC_COMPILER'] = ( 'compiler', { 'ms':'cl.exe',
'icl':'icl.exe' })
if env['LINKER'] == '':
env['LINKER'] = ( 'compiler', { 'ms': 'link.exe',
'icl' : 'xilink.exe'})
# old versions of RC do not accept the /nologo switch
env['rcnologo'] = ( 'msvs_version', { 'otherwise':' /nologo',
'6':'',
'7':'',
'8':'',
'9':'' })
env['RCFLAGS'] = " %(rcnologo)s"
# Finding the rc executable is a bit of a nightmare.
#
# In MSVS2005(VC8):
# C:/Program Files (x86)/Microsoft Visual Studio 8/VC
# bin/rc.exe
# or
# PlatformSDK/Bin/win64/AMD64/rc.exe
# which is $VCINSTALLDIR/bin or
# $VCINSTALLDIR/PlatformSDK/bin/win64/AMD64
# We do not bother attempting to find that version of rc.
# Put it on your path or set env['RC_CMD'] if you need it.
#
# In MSVS2008(VC9), MSVS2010 (VC10) and MSVS2012 (VC11):
# have rc.exe in the SDK directory, though the location varies
# a little for the 32b version.
if env['RC_CMD'] == '':
if 'WindowsSdkDir' in env:
sdk = env['WindowsSdkDir']
elif 'WindowsSdkDir' in os.environ:
sdk = os.environ['WindowsSdkDir']
else:
sdk = 'unknown-sdk-dir'
# and hope the user puts it on their PATH
env['RC_CMD'] = 'rc'
# if we have no valid sdk dir, we won't die trying to
# find the rc.exe.
if sdk != 'unknown-sdk-dir':
if env['host_cpu'] == 'x86-64':
env['RC_CMD'] = os.path.join(sdk,'bin','x64','rc.exe')
if not os.path.exists(env.expand('%(RC_CMD)s')):
die("Could not find 64b RC command in SDK directory")
else:
env['RC_CMD'] = os.path.join(sdk,'bin','x86','rc.exe')
if not os.path.exists(env.expand('%(RC_CMD)s')):
env['RC_CMD'] = os.path.join(sdk,'bin','rc.exe')
if not os.path.exists(env.expand('%(RC_CMD)s')):
die("Could not find 32b RC command in SDK directory")
# RC lives in the SDK. Counting on the msvs.py setup to
# put it on the PATH. FIXME
if env['RC'] == '':
env['RC'] = quote('%(RC_CMD)s')
if env['ARCHIVER'] == '':
env['ARCHIVER'] =( 'compiler', { 'ms': 'lib.exe',
'icl' : 'xilib.exe'})
# lazy toolchain and other env var (f) expansion
mktool = lambda(f): "%(toolchain)s%(" + f + ")s"
if env['CXX'] == '':
env['CXX'] = quote(mktool('CXX_COMPILER'))
if env['CC'] == '':
env['CC'] = quote(mktool('CC_COMPILER'))
if env['AS'] == '':
env['AS'] = quote(mktool('ASSEMBLER'))
if env['LINK'] == '':
env['LINK'] = quote(mktool('LINKER'))
if env['AR'] == '':
env['AR'] = quote(mktool('ARCHIVER'))
def yasm_support(env):
"""Initialize the YASM support based on the env's host_os and host_cpu"""
# FIXME: android???
yasm_formats={}
yasm_formats['win'] = { 'ia32': 'win32', 'x86-64': 'win64'}
yasm_formats['lin'] = { 'ia32': 'elf32', 'x86-64': 'elf64'}
yasm_formats['bsd'] = { 'ia32': 'elf32', 'x86-64': 'elf64'}
yasm_formats['mac'] = { 'ia32': 'macho32', 'x86-64': 'macho64'}
env['ASDOPT']='-D'
try:
env['ASFLAGS'] = ' -f' + yasm_formats[env['host_os']][env['host_cpu']]
env['ASMOUT'] = '-o '
env['AS'] = 'yasm'
except:
die("YASM does not know what format to use for build O/S: %s and target CPU: %s" %
(env['host_os'], env['host_cpu']))
def set_env_clang(env):
set_env_gnu(env)
def set_env_icc(env):
"""Example of setting up the Intel ICC environment for compilation"""
set_env_gnu(env)
def set_env_iclang(env):
"""Example of setting up the Intel iclang (aka mac icl) environment for compilation"""
set_env_gnu(env)
def set_env_icl(env):
"""Example of setting up the Intel ICL (windows) environment for compilation"""
set_env_ms(env)

1136
mbuild/dag.py Executable file

File diff suppressed because it is too large Load Diff

161
mbuild/dfs.py Executable file
View File

@@ -0,0 +1,161 @@
#!/usr/bin/env python
# FILE: dfs.py
# AUTHOR: Mark Charney <mark.charney@intel.com>
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
"""This file provides a node_t type and a dfs() routine that prints out
cycles found in a graph represented as a list of node_t objects.
"""
_dfs_verbose = False
class node_t(object):
def __init__(self,name='no-name-for-node'):
self.name = name
self.afters = []
self.befores = []
self.zero()
# The colors are:
# 0 = white (unvisited),
# 1=grey (discovered, visiting),
# 2=black (finalized)
self.color = 0
self.discover = 0
self.finalize = 0
self.predecessor = None
def zero(self):
self.color = 0
def add_successor(self, s):
self.afters.append(s)
s.befores.append(self)
def add_ancestor(self, s):
self.befores.append(s)
s.afters.append(self)
def __str__(self):
s = []
s.append("TARGET: %s\n\t" % self.name)
s.append("discovered %d finalized %d\n\t" % (self.discover, self.finalize))
s.extend(map(lambda(x): "\t\n%s" % x.name, self.afters))
return ''.join(s)
def _print_cycle(last_visit, grey_loop_closer):
pad = ''
p = last_visit
while 1:
print pad, p.name
if p == grey_loop_closer:
break
p = p.predecessor
pad += ' '
def _visit(n):
global _dfs_time
n.color = 1
n.discover = _dfs_time
if _dfs_verbose:
print "visiting %s" % str(n)
_dfs_time += 1
retval = False
for a in n.afters:
if a.color == 0:
a.predecessor = n
retval |= _visit(a)
elif a.color == 1:
# a back-edge
print "cycle"
_print_cycle(n,a)
retval = True
n.color = 2
n.finalize = _dfs_time
_dfs_time += 1
return retval
def dfs(nodes):
"""Depth first search a list of node_t objects. Print out cycles.
@rtype: bool
@return: True if cycles were detected.
"""
global _dfs_time
_dfs_time = 0
for t in nodes:
t.zero()
cycle = False
for n in nodes:
if n.color == 0:
cycle |= _visit(n)
return cycle
#######################################################
# stuff for a strongly connected components algorithm -- currently
# unused.
def _node_cmp(aa,bb):
return aa.finalize.__cmp__(bb.finalize)
def _visit_transpose(n):
global _dfs_time
n.color = 1
if _dfs_verbose:
print "visiting %s" % str(n)
for a in n.befores:
if a.color == 0:
_visit_transpose(a)
n.color = 2
def dfs_transpose(nodes):
global _dfs_time
_dfs_time = 0
for t in nodes:
t.zero()
nodes.sort(cmp=_node_cmp)
for n in nodes:
if n.color == 0:
_visit_transpose(n)
if _dfs_verbose:
print "===="
####################################################
def _test_dfs():
node1 = node_t('1')
node2 = node_t('2')
node3 = node_t('3')
node4 = node_t('4')
node1.add_successor(node2)
node1.add_successor(node3)
node3.add_successor(node4)
node4.add_successor(node1)
nodes = [ node1, node2, node3, node4 ]
cycle = dfs(nodes)
if cycle:
print "CYCLE DETECTED"
#print "VISIT TRANSPOSE"
#dfs_transpose(nodes)
# print "NODES\n", "\n".join(map(str,nodes))
if __name__ == '__main__':
_test_dfs()

357
mbuild/doxygen.py Executable file
View File

@@ -0,0 +1,357 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
############################################################################
## START OF IMPORTS SETUP
############################################################################
import sys
import os
import re
import copy
import glob
import types
try:
import mbuild
except:
s = "\nXED ERROR: mfile.py could not find mbuild." + \
" Should be a sibling of the xed2 directory.\n\n"
sys.stderr.write(s)
sys.exit(1)
###########################################################################
## DOXYGEN SUPPORT
###########################################################################
def _doxygen_version_okay(s, want_major, want_minor, want_fix):
values = s.split('.')
maj =int(values[0])
minor = int(values[1])
fix = 0
if len(values) > 2:
# remove everything after the dash for things like: 'Doxygen
# 1.5.1-p1'
values[2] = re.sub(r'-.*$','',values[2])
try:
fix = int(values[2])
except ValueError:
pass
if (maj > 1) or \
(maj == want_major and minor > want_minor) or \
(maj == want_major and minor == want_minor and fix >= want_fix):
return True
return False
def _find_doxygen(env):
"""Find the right version of doxygen. Return a tuple of the
command name and a boolean indicating whether or not the version
checked out."""
if env['doxygen_cmd'] == '':
doxygen_cmd_intel = "/usr/intel/bin/doxygen"
doxygen_cmd_cygwin = "C:/cygwin/bin/doxygen"
doxygen_cmd_mac = \
"/Applications/Doxygen.app/Contents/Resources/doxygen"
doxygen_cmd = "doxygen"
if env['build_os'] == 'win':
if os.path.exists(doxygen_cmd_cygwin):
doxygen_cmd = doxygen_cmd_cygwin
else:
mbuild.msgb('DOXYGEN',"Could not find cygwin's doxygen," +
"trying doxygen from PATH")
elif env['build_os'] == 'lin':
if mbuild.verbose(1):
mbuild.msgb("CHECKING FOR", doxygen_cmd_intel)
if os.path.exists(doxygen_cmd_intel):
doxygen_cmd = doxygen_cmd_intel
elif env['build_os'] == 'mac':
if mbuild.verbose(1):
mbuild.msgb("CHECKING FOR", doxygen_cmd_mac)
if os.path.exists(doxygen_cmd_mac):
doxygen_cmd = doxygen_cmd_mac
else:
doxygen_cmd = env['doxygen_cmd']
doxygen_cmd = env.escape_string(doxygen_cmd)
doxygen_okay = False
if mbuild.verbose(1):
mbuild.msgb('Checking doxygen version','...')
if mbuild.check_python_version(2,4):
try:
(retval, output, error_output) = \
mbuild.run_command(doxygen_cmd + " --version")
if retval==0:
if len(output) > 0:
first_line = output[0].strip()
if mbuild.verbose(1):
mbuild.msgb("Doxygen version", first_line)
doxygen_okay = _doxygen_version_okay(first_line, 1,4,6)
else:
for o in output:
mbuild.msgb("Doxygen-version-check STDOUT", o)
if error_output:
for line in error_output:
mbuild.msgb("STDERR ",line.rstrip())
except:
mbuild.die("Doxygen required by the command line options " +
"but no doxygen found")
return (doxygen_cmd, doxygen_okay)
def _replace_match(istring, mtch, newstring, group_name):
"""This is a lame way of avoiding regular expression backslashing
issues"""
x1= mtch.start(group_name)
x2= mtch.end(group_name)
ostring = istring[0:x1] + newstring + istring[x2:]
return ostring
def _customize_doxygen_file(env, subs):
"""Change the $(*) strings to the proper value in the config file.
Returns True on success"""
# doxygen wants quotes around paths with spaces
for k,s in subs.iteritems():
if re.search(' ',s):
if not re.search('^".*"$',s):
mbuild.die("Doxygen requires quotes around strings with spaces: [%s]->[%s]" %
( k,s))
return False
# input and output files
try:
lines = file(env['doxygen_config']).readlines()
except:
mbuild.msgb("Could not open input file: " + env['doxygen_config'])
return False
env['doxygen_config_customized'] = \
env.build_dir_join(os.path.basename(env['doxygen_config']) + '.customized')
try:
ofile = open(env['doxygen_config_customized'],'w')
except:
mbuild.msgb("Could not open output file: " + env['doxygen_config_customized'])
return False
# compile the patterns
rsubs = {}
for k,v in subs.iteritems():
rsubs[k]=re.compile(r'(?P<tag>[$][(]' + k + '[)])')
olines = []
for line in lines:
oline = line
for k,p in rsubs.iteritems():
#print 'searching for', k, 'to replace it with', subs[k]
m = p.search(oline)
while m:
#print 'replacing', k, 'with', subs[k]
oline = _replace_match(oline, m, subs[k], 'tag')
m = p.search(oline)
olines.append(oline)
try:
for line in olines:
ofile.write(line)
except:
ofile.close()
mbuild.msgb("Could not write output file: " + env['doxygen_config_customized'])
return False
ofile.close()
return True
def _build_doxygen_main(args, env):
"""Customize the doxygen input file. Run the doxygen command, copy
in any images, and put the output in the right place."""
if type(args) is types.ListType:
if len(args) < 2:
mbuild.die("Need subs dictionary and dummy file arg for the doxygen command " +
"to indicate its processing")
else:
mbuild.die("Need a list for _build_doxygen_main with the subs " +
"dictionary and the dummy file name")
(subs,dummy_file) = args
(doxygen_cmd, doxygen_okay) = _find_doxygen(env)
if not doxygen_okay:
msg = 'No good doxygen available on this system; ' + \
'Your command line arguments\n\trequire it to be present. ' + \
'Consider dropping the "doc" and "doc-build" options\n\t or ' + \
'specify a path to doxygen with the --doxygen knob.\n\n\n'
return (1, [msg]) # failure
else:
env['DOXYGEN'] = doxygen_cmd
try:
okay = _customize_doxygen_file(env, subs)
except:
mbuild.die("CUSTOMIZE DOXYGEN INPUT FILE FAILED")
if not okay:
return (1, ['Doxygen customization failed'])
cmd = env['DOXYGEN'] + ' ' + \
env.escape_string(env['doxygen_config_customized'])
if mbuild.verbose(1):
mbuild.msgb("RUN DOXYGEN", cmd)
(retval, output, error_output) = mbuild.run_command(cmd)
for line in output:
mbuild.msgb("DOX",line.rstrip())
if error_output:
for line in error_output:
mbuild.msgb("DOX-ERROR",line.rstrip())
if retval != 0:
mbuild.msgb("DOXYGEN FAILED")
mbuild.die("Doxygen run failed. Retval=", str(retval))
mbuild.touch(dummy_file)
mbuild.msgb("DOXYGEN","succeeded")
return (0, []) # success
###########################################################################
# Doxygen build
###########################################################################
def _empty_dir(d):
"""return True if the directory d does not exist or if it contains no
files/subdirectories."""
if not os.path.exists(d):
return True
for (root, subdirs, subfiles) in os.walk(d):
if len(subfiles) or len(subdirs):
return False
return True
def _make_doxygen_reference_manual(env, doxygen_inputs, subs, work_queue,
hash_file_name='dox'):
"""Install the doxygen reference manual the doyxgen_output_dir
directory. doxygen_inputs is a list of files """
dox_dag = mbuild.dag_t(hash_file_name,env=env)
# so that the scanner can find them
dirs = {}
for f in doxygen_inputs:
dirs[os.path.dirname(f)]=True
for d in dirs.iterkeys():
env.add_include_dir(d)
# make sure the config and top file are in the inptus list
doxygen_inputs.append(env['doxygen_config'])
doxygen_inputs.append(env['doxygen_top_src'])
dummy = env.build_dir_join('dummy-doxygen-' + hash_file_name)
# Run it via the builder to make it dependence driven
run_always = False
if _empty_dir(env['doxygen_install']):
run_always = True
if run_always:
_build_doxygen_main([subs,dummy], env)
else:
c1 = mbuild.plan_t(command=_build_doxygen_main,
args= [subs,dummy],
env= env,
input= doxygen_inputs,
output= dummy)
dox1 = dox_dag.add(env,c1)
okay = work_queue.build(dag=dox_dag)
phase = "DOXYGEN"
if not okay:
mbuild.die("[%s] failed. dying..." % phase)
if mbuild.verbose(1):
mbuild.msgb(phase, "build succeeded")
############################################################
def doxygen_env(env):
"""Add the doxygen variables to the environment"""
doxygen_defaults = dict( doxygen_config='',
doxygen_top_src='',
doxygen_install='',
doxygen_cmd='' )
env.update_dict(doxygen_defaults)
def doxygen_args(env):
"""Add the knobs to the command line knobs parser"""
env.parser.add_option("--doxygen-install",
dest="doxygen_install",
action="store",
default='',
help="Doxygen installation directory")
env.parser.add_option("--doxygen-config",
dest="doxygen_config",
action="store",
default='',
help="Doxygen config file")
env.parser.add_option("--doxygen-top-src",
dest="doxygen_top_src",
action="store",
default='',
help="Doxygen top source file")
env.parser.add_option("--doxygen-cmd",
dest="doxygen_cmd",
action="store",
default='',
help="Doxygen command name")
def doxygen_run(env, inputs, subs, work_queue, hash_file_name='dox'):
"""Run doxygen assuming certain values are in the environment env.
@type env: env_t
@param env: the environment
@type inputs: list
@param inputs: list of input files to scan for dependences
@type subs: dictionary
@param subs: replacements in the config file
@type work_queue: work_queue_t
@param work_queue: a work queue for the build
@type hash_file_name: string
@param hash_file_name: used for the dummy file and mbuild hash suffix
"""
_make_doxygen_reference_manual(env, inputs, subs, work_queue, hash_file_name)

2088
mbuild/env.py Executable file

File diff suppressed because it is too large Load Diff

175
mbuild/header_tag.py Executable file
View File

@@ -0,0 +1,175 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import sys
import os
import re
from stat import *
def _get_mode(fn):
"get the mode of the file named fn, suitable for os.chmod() or open() calls"
mode = os.stat(fn)[ST_MODE]
cmode = S_IMODE(mode)
return cmode
def _replace_original_with_new_file(file,newfile):
"Replace file with newfile"
# os.system(" mv -f %s %s" % ( newfile, file))
os.unlink(file)
os.rename(newfile,file)
def _remove_existing_header(contents,prefix="#"):
"remove existing legal header, if any"
retval = []
skipping = False
start_pattern = re.compile(r"^(/[*]BEGIN_LEGAL)|(" + prefix + "BEGIN_LEGAL)")
stop_pattern = re.compile(r"^[ ]*(END_LEGAL[ ]?[*]/)|(" + prefix + "[ ]*END_LEGAL)")
for line in contents:
if start_pattern.match(line):
skipping = True
if skipping == False:
retval.append(line)
if stop_pattern.match(line):
skipping = False
return retval
def _prepend_script_comment(header,prefix="#"):
"Apply script comment marker to each line"
retval = []
for line in header:
retval.append( prefix + line )
return retval
def apply_header_to_source_file(header, file):
"apply header to file using C++ comment style"
f = open(file,"r")
mode = _get_mode(file)
contents = f.readlines()
f.close()
trimmed_contents = _remove_existing_header(contents)
newfile = file + ".new"
o = open(newfile,"w")
o.write("/*BEGIN_LEGAL \n")
o.writelines(header)
o.write("END_LEGAL */\n")
o.writelines(trimmed_contents)
o.close()
os.chmod(newfile,mode)
_replace_original_with_new_file(file,newfile)
# FIXME: this will flag files that have multiline C-style comments
# with -*- in them even though the splitter will not look for the
# comment properly
def _shell_script(lines):
"""return true if the lines are the start of shell script or
something that needs a mode comment at the top"""
first = ""
second = ""
if len(lines) > 0:
first = lines[0];
if len(lines) > 1:
second = lines[1];
if re.match("#!",first):
#print "\t\t First script test true"
return True
if re.search("-\*-",first) or re.search("-\*-",second):
#print "\t\t Second script test true"
return True
return False
def _split_script(lines):
"Return a tuple of (header, body) for shell scripts, based on an input line list"
header = []
body = []
f = lines.pop(0)
while re.match("#",f) or re.search("-\*-",f):
header.append(f)
f = lines.pop(0)
# tack on the first non matching line from the above loop
body.append(f);
body.extend(lines);
return (header,body)
def _write_script_header(o,lines,prefix="#"):
"Write the file header for a script"
o.write(prefix+"BEGIN_LEGAL\n")
o.writelines(lines)
o.write(prefix+"END_LEGAL\n")
def apply_header_to_data_file(header, file, prefix="#"):
"apply header to file using script comment style"
f = open(file,"r")
mode = _get_mode(file)
#print "file: " + file + " mode: " + "%o" % mode
contents = f.readlines()
f.close()
trimmed_contents = _remove_existing_header(contents, prefix)
newfile = file + ".new"
o = open(newfile,"w")
augmented_header = _prepend_script_comment(header,prefix)
if _shell_script(trimmed_contents):
(script_header, script_body) = _split_script(trimmed_contents)
o.writelines(script_header)
_write_script_header(o, augmented_header, prefix)
o.writelines(script_body)
else:
_write_script_header(o,augmented_header,prefix)
o.writelines(trimmed_contents)
o.close()
os.chmod(newfile,mode)
_replace_original_with_new_file(file,newfile)
####################################################################
### MAIN
####################################################################
if __name__ == '__main__':
if len(sys.argv) < 4:
print "Usage " + sys.argv[0] + " [-s|-t] legal-header file-name [file-name...]\n"
sys.exit(1)
type = sys.argv[1]
header_file = sys.argv[2]
if not os.path.exists(header_file):
print "Could not find header file: [%s]\n" % (header_file)
sys.exit(1)
files_to_tag = sys.argv[3:]
f = open(header_file,"r")
header = f.readlines()
f.close()
sources = files_to_tag
if type == "-s":
for file in sources:
if re.search(".svn",file) == None and re.search(".new$",file) == None:
apply_header_to_source_file(header, file.strip())
elif type == "-t":
for file in sources:
if re.search(".svn",file) == None and re.search(".new$",file) == None:
apply_header_to_data_file(header, file.strip())
else:
print "2nd argument must be -s or -t\n"
sys.exit(1)

903
mbuild/msvs.py Normal file
View File

@@ -0,0 +1,903 @@
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
# TESTING MATRIX
# ('e' is for express)
#
# 32 32/64 64
# 6 ok ? N/A
# 7 ok ok N/A
# 8 ? ok ok
# 8e ? ? ?
# 9 ? ok ok
# 9e ok ? ?
# 10 ? ? ?
#
"""Environment setup for Microsoft Visual Studio. Set INCLUDE,
LIBPATH, LIB, PATH, VCINSTALLDIR, VS80COMNTOOLS, VSINSTALLDIR, etc.
"""
import os
import sys
import platform
from base import *
from util import *
from env import *
########################################################################
def set_env(v,s):
"""Add v=s to the shell environment"""
if v in os.environ:
orig = os.environ[v]
else:
orig = ''
# We have had issues on windows were we attempt to make the
# environment too long. This catches the error and prints a nice
# error msg.
try:
os.environ[v]=s
except Exception, e:
sys.stderr.write( str(e) + '\n')
sys.stderr.write("Env Variable [%s]\n" % (v))
sys.stderr.write("Original was [%s]\n" % (orig))
sys.stderr.write("New value was [%s]\n" % (s))
sys.exit(1)
def set_env_list(v,slist):
set_env(v,";".join(slist))
def add_to_front(v,s):
"""Add v=s+old_v to the shell environment"""
set_env(v,s + ';' + os.environ[v])
def add_to_front_list(v,s):
add_to_front(v,';'.join(s))
def add_env(v,s):
"""Add v=v;old_vs to the shell environment. Inserts at front"""
v.insert(0,s)
########################################################################
def _find_dir_list(lst):
for dir in lst:
if os.path.exists(dir):
return dir
return None
def _set_msvs_dev6(env, x64_host, x64_target): # VC 98
vc_prefixes = [ "C:/VC98",
"C:/Program Files (x86)/Microsoft Visual Studio",
"C:/Program Files/Microsoft Visual Studio" ]
msdev_prefixes = [
"C:/Program Files/Microsoft Visual Studio/Common" ]
vc_prefix = _find_dir_list(vc_prefixes)
msdev_prefix = _find_dir_list(msdev_prefixes)
if not vc_prefix:
die("Could not find VC98")
if not msdev_prefix:
die("Could not find VC98 MSDEV")
i = []
add_env(i, vc_prefix + "/VC98/ATL/INCLUDE")
add_env(i, vc_prefix + "/VC98/INCLUDE")
add_env(i, vc_prefix + "/VC98/MFC/INCUDE")
set_env_list("INCLUDE",i)
lib = []
add_env(lib, vc_prefix + "/VC98/LIB")
add_env(lib, vc_prefix + "/VC98/MFC/LIB")
set_env_list("LIB",lib)
path=[]
add_env(path, msdev_prefix + "/msdev98/Bin")
add_env(path, vc_prefix + "/VC98/Bin")
add_env(path, msdev_prefix + "/TOOLS/WINNT")
add_env(path, msdev_prefix + "/TOOLS")
add_to_front_list('PATH', path)
set_env("MSDevDir", msdev_prefix + "/msdev98")
set_env("MSVCDir", vc_prefix + "/VC98")
return vc_prefix + "/VC98"
def _set_msvs_dev7(env, x64_host, x64_target): # .NET 2003
prefixes = [ "c:/Program Files/Microsoft Visual Studio .NET 2003",
"c:/Program Files (x86)/Microsoft Visual Studio .NET 2003"]
prefix = _find_dir_list(prefixes)
if not prefix:
die("Could not find MSVS7 .NET 2003")
inc = []
add_env(inc, prefix + '/VC7/ATLMFC/INCLUDE')
add_env(inc, prefix + '/VC7/include')
add_env(inc, prefix + '/VC7/PlatformSDK/include/prerelease')
add_env(inc, prefix + '/VC7/PlatformSDK/include')
add_env(inc, prefix + '/SDK/v1.1/include')
add_env(inc, prefix + '/SDK/v1.1/include/')
set_env_list("INCLUDE",inc)
lib = []
add_env(lib, prefix + '/VC7/ATLMFC/LIB')
add_env(lib, prefix + '/VC7/LIB')
add_env(lib, prefix + '/VC7/PlatformSDK/lib/prerelease')
add_env(lib, prefix + '/VC7/PlatformSDK/lib')
add_env(lib, prefix + '/SDK/v1.1/lib')
add_env(lib, prefix + '/SDK/v1.1/Lib/')
set_env_list("LIB",lib)
path = []
add_env(path, prefix + "/Common7/IDE")
add_env(path, prefix + "/VC7/bin")
add_env(path, prefix + "/Common7/Tools")
add_env(path, prefix + "/Common7/Tools/bin/prerelease")
add_env(path, prefix + "/Common7/Tools/bin")
add_env(path, prefix + "/SDK/v1.1/bin")
add_to_front_list('PATH', path)
set_env("VCINSTALLDIR", prefix)
set_env("VC71COMNTOOLS", prefix + "/Common7/Tools/")
set_env("VSINSTALLDIR", prefix + '/Common7/IDE')
set_env("MSVCDir", prefix + '/VC7')
set_env("FrameworkVersion","v1.1.4322")
set_env("FrameworkSDKDir", prefix + "/SDK/v1.1")
set_env("FrameworkDir", "C:/WINDOWS/Microsoft.NET/Framework")
# DevEnvDir has a trailing slash
set_env("DevEnvDir", prefix + "/Common7/IDE/")
return prefix + "/VC7"
def _set_msvs_dev8(env, x64_host, x64_target, regv=None): # VS 2005
if regv:
prefix = regv
else:
prefixes = ["c:/Program Files (x86)/Microsoft Visual Studio 8",
"c:/Program Files/Microsoft Visual Studio 8"]
prefix = _find_dir_list(prefixes)
if not os.path.exists(prefix):
die("Could not find MSVC8 (2005)")
set_env('VCINSTALLDIR', prefix + '/VC')
set_env('VS80COMNTOOLS', prefix + "/Common7/Tools")
set_env('VSINSTALLDIR', prefix)
i =[]
add_env(i, prefix + "/VC/ATLMFC/INCLUDE")
add_env(i, prefix + "/VC/INCLUDE")
add_env(i, prefix + "/VC/PlatformSDK/include")
add_env(i, prefix + "/SDK/v2.0/include")
set_env_list('INCLUDE', i)
set_env('FrameworkDir','C:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkVersion', 'v2.0.50727')
set_env('FrameworkSDKDir', prefix +'/SDK/v2.0')
# DevEnvDir has a trailing slash
set_env("DevEnvDir", prefix +'/Common7/IDE/')
lp = []
path=[]
lib=[]
if x64_host and x64_target:
add_env(lp, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(lib, prefix + "/VC/ATLMFC/LIB/amd64")
add_env(lib, prefix + "/VC/LIB/amd64")
add_env(lib, prefix + "/VC/PlatformSDK/lib/amd64")
add_env(lib, prefix + "/SDK/v2.0/LIBAMD64")
add_env(path, prefix + "/VC/bin/amd64")
add_env(path, prefix + "/VC/PlatformSDK/bin/win64/amd64")
add_env(path, prefix + "/VC/PlatformSDK/bin")
add_env(path, prefix + "/VC/VCPackages")
add_env(path, prefix + "/Common7/IDE")
add_env(path, prefix + "/Common7/Tools")
add_env(path, prefix + "/Common7/Tools/bin")
add_env(path, prefix + "/SDK/v2.0/bin")
add_env(path, prefix + "C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727")
elif not x64_target:
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix + '/Common7/Tools')
add_env(path, prefix + '/Common7/Tools/bin')
add_env(path, prefix + '/VC/PlatformSDK/bin')
add_env(path, prefix + '/SDK/v2.0/bin')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727')
add_env(lib, prefix + '/VC/ATLMFC/LIB')
add_env(lib, prefix + '/VC/LIB')
add_env(lib, prefix + '/VC/PlatformSDK/lib')
add_env(lib, prefix + '/SDK/v2.0/lib')
add_env(lp, prefix + '/VC/ATLMFC/LIB')
add_env(lp, 'C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727')
add_to_front_list('PATH', path)
set_env_list('LIB',lib)
set_env_list('LIBPATH', lp)
return prefix + "/VC"
def _set_msvs_dev9(env, x64_host, x64_target, regv=None): # VS 2008
if regv:
prefix = regv
else:
prefixes = ['C:/Program Files (x86)/Microsoft Visual Studio 9.0',
'C:/Program Files/Microsoft Visual Studio 9.0']
prefix = _find_dir_list(prefixes)
set_env('VSINSTALLDIR', prefix)
set_env('VS90COMNTOOLS', prefix + '/Common7/Tools')
set_env('VCINSTALLDIR', prefix +'/VC')
set_env('FrameworkDir', 'C:/WINDOWS/Microsoft.NET/Framework')
set_env('Framework35Version','v3.5')
set_env('FrameworkVersion','v2.0.50727')
set_env('FrameworkSDKDir', prefix +'/SDK/v3.5')
set_env('WindowsSdkDir','C:/Program Files/Microsoft SDKs/Windows/v6.0A')
# DevEnvDir has a trailing slash
set_env('DevEnvDir', prefix + '/Common7/IDE/')
inc = []
add_env(inc, prefix + 'VC/ATLMFC/INCLUDE')
add_env(inc, prefix + '/VC/INCLUDE')
add_env(inc, 'C:/Program Files/Microsoft SDKs/Windows/v6.0A/include')
set_env_list('INCLUDE',inc)
path = []
lib = []
libpath = []
if x64_target: # FIXME! 64b!!!!
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix + '/Common7/Tools')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, 'C:/Program Files/Microsoft SDKs/Windows/v6.0A/bin')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v3.5')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727')
add_env(lib, prefix +'/VC/ATLMFC/LIB/amdt64')
add_env(lib, prefix +'/VC/LIB/amd64')
add_env(lib, 'C:/Program Files/Microsoft SDKs/Windows/v6.0A/lib/x64')
add_env(libpath, 'C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727')
add_env(libpath, 'C:/WINDOWS/Microsoft.NET/Framework64/v3.5')
add_env(libpath, 'C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727')
add_env(libpath, 'C:/WINDOWS/Microsoft.NET/Framework64/v2.0.50727')
add_env(libpath, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(libpath, prefix + '/VC/LIB/amd64')
else:
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix + '/Common7/Tools')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, 'C:/Program Files/Microsoft SDKs/Windows/v6.0A/bin')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v3.5')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727')
add_env(lib, prefix +'/VC/LIB')
add_env(lib, prefix +'/VC/ATLMFC/LIB')
add_env(lib, 'C:/Program Files/Microsoft SDKs/Windows/v6.0A/lib')
add_env(libpath, 'C:/WINDOWS/Microsoft.NET/Framework/v3.5')
add_env(libpath, 'C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727')
add_env(libpath, prefix + '/VC/ATLMFC/LIB')
add_env(libpath, prefix + '/VC/LIB')
set_env_list('LIBPATH',libpath)
set_env_list('LIB',lib)
add_to_front_list('PATH',path)
return prefix + "/VC"
def _set_msvs_dev10(env, x64_host, x64_target, regv=None): # VS 2010
if regv:
prefix = regv
else:
prefix = 'C:/Program Files (x86)/Microsoft Visual Studio 10.0'
path = []
lib = []
libpath = []
inc = []
add_env(inc, prefix + '/VC/INCLUDE')
add_env(inc, prefix + '/VC/ATLMFC/INCLUDE')
add_env(inc, 'c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include')
set_env_list('INCLUDE',inc)
set_env('Framework35Version','v3.5')
set_env('FrameworkVersion', 'v4.0.20728')
set_env('FrameworkVersion32', 'v4.0.20728')
set_env('VCINSTALLDIR', prefix + '/VC')
set_env('VS100COMNTOOLS', prefix + '/Common7/Tools')
set_env('VSINSTALLDIR' , prefix)
set_env('WindowsSdkDir', 'c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A')
# DevEnvDir has a trailing slash
set_env('DevEnvDir', prefix + '/Common7/IDE/')
if x64_target:
set_env('FrameworkDir','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkDIR64','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkVersion64', 'v4.0.20728')
set_env('Platform','X64')
add_env(lib, prefix + '/VC/LIB/amd64')
add_env(lib, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(lib, 'c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/lib/x64')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.20728')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework64/v3.5')
add_env(libpath, prefix + '/VC/LIB/amd64')
add_env(libpath, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(path, prefix + '/VC/BIN/amd64')
add_env(path, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.20728')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework64/v3.5')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Program Files (x86)/HTML Help Workshop')
add_env(path, 'C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/' +
'bin/NETFX 4.0 Tools/x64')
add_env(path, 'C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin/x64')
add_env(path, 'C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin')
else:
set_env('FrameworkDir', 'c:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkDIR32', 'c:/WINDOWS/Microsoft.NET/Framework')
add_env(lib, prefix + '/VC/LIB')
add_env(lib, prefix + '/VC/ATLMFC/LIB')
add_env(lib, 'c:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/lib')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework/v4.0.20728')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework/v3.5')
add_env(libpath, prefix + '/VC/LIB')
add_env(libpath, prefix + '/VC/ATLMFC/LIB')
add_env(path, prefix + '/Common7/IDE/')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix +'/Common7/Tools')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v4.0.20728')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework/v3.5')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, 'C:/Program Files (x86)/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, 'C;/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/' +
'bin/NETFX 4.0 Tools')
add_env(path, 'C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/bin')
set_env_list('LIBPATH',libpath)
set_env_list('LIB',lib)
add_to_front_list('PATH',path)
return prefix + "/VC"
def _set_msvs_dev11(env, x64_host, x64_target, regv=None): # msvs2012
progfi = 'C:/Program Files (x86)'
if regv:
prefix = regv
else:
prefix = progfi + '/Microsoft Visual Studio 11.0'
sdkdir = progfi + '/Microsoft SDKs/Windows/v8.0'
sdk8 = progfi + '/Microsoft SDKs/Windows/v8.0A'
sdk7 = progfi + '/Microsoft SDKs/Windows/v7.0A'
winkit = progfi + '/Windows Kits/8.0'
path = []
lib = []
libpath = []
inc = []
add_env(inc, prefix + '/VC/INCLUDE')
add_env(inc, prefix + '/VC/ATLMFC/INCLUDE')
add_env(inc, winkit + '/include')
add_env(inc, winkit + '/include/um')
add_env(inc, winkit + '/include/shared')
add_env(inc, winkit + '/include/winrt')
set_env_list('INCLUDE',inc)
set_env('Framework35Version','v3.5')
set_env('FrameworkVersion', 'v4.0.30319')
set_env('FrameworkVersion32', 'v4.0.30319')
set_env('VCINSTALLDIR', prefix + '/VC/')
set_env('VS110COMNTOOLS', prefix + '/Common7/Tools')
set_env('VSINSTALLDIR' , prefix)
set_env('WindowsSdkDir', winkit)
if x64_target:
set_env('FrameworkDir','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkDIR64','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkVersion64', 'v4.0.30319')
set_env('Platform','X64')
add_env(lib, prefix + '/VC/LIB/amd64')
add_env(lib, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(lib, winkit + '/lib/win8/um/x64')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.30319')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework64/v3.5')
add_env(libpath, prefix + '/VC/LIB/amd64')
add_env(libpath, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(libpath, winkit + '/References/CommonConfiguration/Neutral')
add_env(libpath, sdkdir + 'ExtensionSDKs/Microsoft.VCLibs/11.0/' +
'References/CommonConfiguration/neutral')
add_env(path, prefix + '/VC/BIN/amd64')
add_env(path, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.30319')
add_env(path, 'C:/WINDOWS/Microsoft.NET/Framework64/v3.5')
add_env(path, prefix + '/Common7/IDE/CommonExtensions/Microsoft/TestWindow')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Program Files (x86)/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools/x64')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, winkit + '/8.0/bin/x64')
add_env(path, sdk8 + '/bin/NETFX 4.0 Tools/x64')
add_env(path, sdk7 + '/Bin/x64')
add_env(path, sdk8 + '/bin/NETFX 4.0 Tools')
add_env(path, sdk7 + '/Bin')
add_env(path, winkit + '/Windows Performance Toolkit')
add_env(path, 'C:/Program Files/Microsoft SQL Server/110/Tools/Binn')
else:
set_env('FrameworkDir', 'c:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkDIR32', 'c:/WINDOWS/Microsoft.NET/Framework')
add_env(lib, prefix + '/VC/LIB')
add_env(lib, prefix + '/VC/ATLMFC/LIB')
add_env(lib, winkit + '/lib/win8/um/x86')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework/v3.5')
add_env(libpath, prefix + '/VC/LIB')
add_env(libpath, prefix + '/VC/ATLMFC/LIB')
add_env(libpath, winkit + '/References/CommonConfiguration/Neutral')
add_env(libpath, sdkdir + '/ExtensionSDKs/Microsoft.VCLibs/11.0/' +
'References/CommonConfiguration/neutral')
add_env(path, prefix + '/Common7/IDE/CommonExtensions/Microsoft/TestWindow')
add_env(path, 'C:/Program Files (x86)/Microsoft SDKs/F#/3.0/Framework/v4.0')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Windows/Microsoft.NET/Framework/v4.0.30319')
add_env(path, 'C:/Windows/Microsoft.NET/Framework/v3.5')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, 'C:/Program Files (x86)/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, winkit + '/bin/x86')
add_env(path, sdk8 + '/bin/NETFX 4.0 Tools')
add_env(path, sdk7 + '/Bin')
add_env(path, winkit + '/Windows Performance Toolkit')
add_env(path, 'C:/Program Files/Microsoft SQL Server/110/Tools/Binn')
set_env_list('LIBPATH',libpath)
set_env_list('LIB',lib)
add_to_front_list('PATH',path)
return prefix + "/VC"
def _set_msvs_dev12(env, x64_host, x64_target, regv=None): # msvs2013
progfi = 'C:/Program Files (x86)'
if regv:
prefix = regv
else:
prefix = progfi + '/Microsoft Visual Studio 12.0'
sdk81a = progfi + '/Microsoft SDKs/Windows/v8.1A'
sdk81 = progfi + '/Microsoft SDKs/Windows/v8.1'
winkit = progfi + '/Windows Kits/8.1'
path = []
lib = []
libpath = []
inc = []
add_env(inc, prefix + '/VC/INCLUDE')
add_env(inc, prefix + '/VC/ATLMFC/INCLUDE')
add_env(inc, winkit + '/include') # not used in msvs12
add_env(inc, winkit + '/include/um')
add_env(inc, winkit + '/include/shared')
add_env(inc, winkit + '/include/winrt')
set_env_list('INCLUDE',inc)
set_env('Framework40Version','v4.0')
set_env('FrameworkVersion', 'v4.0.30319')
set_env('ExtensionSdkDir',
sdk81 + '/ExtensionSDKs')
set_env('VCINSTALLDIR', prefix + '/VC/')
set_env('VS120COMNTOOLS', prefix + '/Common7/Tools')
set_env('VSINSTALLDIR' , prefix)
set_env('WindowsSdkDir', winkit)
set_env('VisualStudioVersion','12.0')
set_env('WindowsSDK_ExecutablePath_x86',
sdk81a + '/bin/NETFX 4.5.1 Tools/')
if x64_target:
set_env('WindowsSDK_ExecutablePath_x64',
sdk81a +'/bin/NETFX 4.5.1 Tools/x64/')
set_env('FrameworkDir','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkDIR64','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkVersion64', 'v4.0.30319')
set_env('Platform','X64')
add_env(lib, prefix + '/VC/LIB/amd64')
add_env(lib, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(lib, winkit + '/lib/winv6.3/um/x64')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.30319')
add_env(libpath, prefix + '/VC/LIB/amd64')
add_env(libpath, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(libpath, winkit + '/References/CommonConfiguration/Neutral')
add_env(libpath, sdk81 + '/ExtensionSDKs/Microsoft.VCLibs/12.0/' +
'References/CommonConfiguration/neutral')
add_env(path, prefix + '/Common7/IDE/CommonExtensions/Microsoft/TestWindow')
add_env(path, prefix + '/VC/BIN/amd64')
add_env(path, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.30319')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Program Files (x86)/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools/x64')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, winkit + '/8.1/bin/x64')
add_env(path, winkit + '/8.1/bin/x86')
add_env(path, sdk81a + '/bin/NETFX 4.5.1 Tools/x64')
add_env(path, winkit + '/Windows Performance Toolkit')
else:
set_env('FrameworkDir', 'c:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkDIR32', 'c:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkVersion32','v4.0.30319')
add_env(lib, prefix + '/VC/LIB')
add_env(lib, prefix + '/VC/ATLMFC/LIB')
add_env(lib, winkit + '/lib/winv6.3/um/x86')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319')
add_env(libpath, prefix + '/VC/LIB')
add_env(libpath, prefix + '/VC/ATLMFC/LIB')
add_env(libpath, winkit + '/References/CommonConfiguration/Neutral')
add_env(libpath, sdk81 + '/ExtensionSDKs/Microsoft.VCLibs/12.0/' +
'References/CommonConfiguration/neutral')
add_env(path, prefix + '/Common7/IDE/CommonExtensions/Microsoft/TestWindow')
add_env(path, progfi + '/Microsoft SDKs/F#/3.1/Framework/v4.0')
add_env(path, progfi + '/MSBuild/12.0/bin')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Windows/Microsoft.NET/Framework/v4.0.30319')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, progfi + '/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, winkit + '/bin/x86')
add_env(path, sdk81a + '/bin/NETFX 4.5.1 Tools')
add_env(path, winkit + '/Windows Performance Toolkit')
set_env_list('LIBPATH',libpath)
set_env_list('LIB',lib)
add_to_front_list('PATH',path)
return prefix + "/VC"
def _set_msvs_dev14(env, x64_host, x64_target, regv=None): # msvs 2015
progfi = 'C:/Program Files (x86)'
if regv:
prefix = regv
else:
prefix = progfi + '/Microsoft Visual Studio 14.0'
sdk81a = progfi + '/Microsoft SDKs/Windows/v8.1A'
sdk81 = progfi + '/Microsoft SDKs/Windows/v8.1'
winkit = progfi + '/Windows Kits/8.1'
winkit10 = progfi + '/Windows Kits/10'
# Find the UCRT Version. Could not locate a registry entry with
# the information. Preview version of msvs2015/dev14 did not set
# the env var. Poke around in the directory system as a last
# resort. Could make this configrable
winkit10version = None
if 'UCRTVersion' in os.environ:
winkit10version = os.environ['UCRTVersion']
if not winkit10version:
# use glob and find youngest directory
ctime = 0
for g in glob(winkit10 + '/include/*'):
if os.path.exists('{}/ucrt'.format(g)):
gtime = os.path.getctime(g)
if gtime > ctime:
winkit10version = os.path.basename(g)
ctime = gtime
if not winkit10version:
die("Did not find winkit 10 version")
msgb("UCRT Version", winkit10version)
path = []
lib = []
libpath = []
inc = []
add_env(inc, prefix + '/VC/INCLUDE')
add_env(inc, prefix + '/VC/ATLMFC/INCLUDE')
add_env(inc, winkit + '/include') # not used in msvs12
add_env(inc, winkit10 + '/include/{}/ucrt'.format(winkit10version))
add_env(inc, winkit + '/include/shared')
add_env(inc, winkit + '/include/um')
add_env(inc, winkit + '/include/winrt')
set_env_list('INCLUDE',inc)
set_env('Framework40Version','v4.0')
set_env('FrameworkVersion', 'v4.0.30319')
set_env('ExtensionSdkDir',
sdk81 + '/ExtensionSDKs')
set_env('VCINSTALLDIR', prefix + '/VC/')
set_env('VS140COMNTOOLS', prefix + '/Common7/Tools')
set_env('VSINSTALLDIR' , prefix)
set_env('WindowsSdkDir', winkit)
set_env('VisualStudioVersion','14.0')
set_env('WindowsSDK_ExecutablePath_x86',
sdk81a + '/bin/NETFX 4.5.1 Tools/')
if x64_target:
set_env('WindowsSDK_ExecutablePath_x64',
sdk81a +'/bin/NETFX 4.5.1 Tools/x64/')
set_env('FrameworkDir','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkDIR64','c:/WINDOWS/Microsoft.NET/Framework64')
set_env('FrameworkVersion64', 'v4.0.30319')
set_env('Platform','X64')
add_env(lib, prefix + '/VC/LIB/amd64')
add_env(lib, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(lib, winkit10 + '/lib/{}/ucrt/x64'.format(winkit10version))
add_env(lib, winkit + '/lib/winv6.3/um/x64')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.30319')
add_env(libpath, prefix + '/VC/LIB/amd64')
add_env(libpath, prefix + '/VC/ATLMFC/LIB/amd64')
add_env(libpath, winkit + '/References/CommonConfiguration/Neutral')
add_env(libpath, sdk81 + '/ExtensionSDKs/Microsoft.VCLibs/14.0/' +
'References/CommonConfiguration/neutral')
add_env(path, prefix + '/Common7/IDE/CommonExtensions/Microsoft/TestWindow')
add_env(path, prefix + '/VC/BIN/amd64')
add_env(path, 'c:/WINDOWS/Microsoft.NET/Framework64/v4.0.30319')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Program Files (x86)/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools/x64')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, winkit + '/8.1/bin/x64')
add_env(path, winkit + '/8.1/bin/x86')
add_env(path, sdk81a + '/bin/NETFX 4.5.1 Tools/x64')
add_env(path, winkit + '/Windows Performance Toolkit')
else:
set_env('FrameworkDir', 'c:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkDIR32', 'c:/WINDOWS/Microsoft.NET/Framework')
set_env('FrameworkVersion32','v4.0.30319')
add_env(lib, prefix + '/VC/LIB')
add_env(lib, prefix + '/VC/ATLMFC/LIB')
add_env(lib, winkit10 + '/lib/{}/ucrt/x86'.format(winkit10version))
add_env(lib, winkit + '/lib/winv6.3/um/x86')
add_env(libpath, 'c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319')
add_env(libpath, prefix + '/VC/LIB')
add_env(libpath, prefix + '/VC/ATLMFC/LIB')
add_env(libpath, winkit + '/References/CommonConfiguration/Neutral')
add_env(libpath, sdk81 + '/ExtensionSDKs/Microsoft.VCLibs/14.0/' +
'References/CommonConfiguration/neutral')
add_env(path, prefix + '/Common7/IDE/CommonExtensions/Microsoft/TestWindow')
add_env(path, progfi + '/Microsoft SDKs/F#/3.1/Framework/v4.0')
add_env(path, progfi + '/MSBuild/14.0/bin')
add_env(path, prefix + '/Common7/IDE')
add_env(path, prefix + '/VC/BIN')
add_env(path, prefix + '/Common7/Tools')
add_env(path, 'C:/Windows/Microsoft.NET/Framework/v4.0.30319')
add_env(path, prefix + '/VC/VCPackages')
add_env(path, progfi + '/HTML Help Workshop')
add_env(path, prefix + '/Team Tools/Performance Tools')
add_env(path, winkit + '/bin/x86')
add_env(path, sdk81a + '/bin/NETFX 4.5.1 Tools')
add_env(path, winkit + '/Windows Performance Toolkit')
set_env_list('LIBPATH',libpath)
set_env_list('LIB',lib)
add_to_front_list('PATH',path)
return prefix + "/VC"
def _try_to_figure_out_msvs_version(env):
prefixes = [
(14,'C:/Program Files (x86)/Microsoft Visual Studio 14.0'),
(14,'C:/Program Files/Microsoft Visual Studio 14.0'),
(12,'C:/Program Files (x86)/Microsoft Visual Studio 12.0'),
(12,'C:/Program Files/Microsoft Visual Studio 12.0'),
(11,'C:/Program Files (x86)/Microsoft Visual Studio 11.0'),
(11,'C:/Program Files/Microsoft Visual Studio 11.0'),
(10,'C:/Program Files (x86)/Microsoft Visual Studio 10.0'),
(10,'C:/Program Files/Microsoft Visual Studio 10.0'),
(9,'C:/Program Files (x86)/Microsoft Visual Studio 9.0'),
(9,'C:/Program Files/Microsoft Visual Studio 9.0'),
(8, "c:/Program Files (x86)/Microsoft Visual Studio 8"),
(8,"c:/Program Files/Microsoft Visual Studio 8"),
(7, "c:/Program Files/Microsoft Visual Studio .NET 2003"),
(7,"c:/Program Files (x86)/Microsoft Visual Studio .NET 2003")
]
for v,dir in prefixes:
#print dir
if os.path.exists(dir):
#print 'FOUND', dir
return str(v)
return '' # we don't know
def _read_registry(root,key,value):
import _winreg
try:
hkey = _winreg.OpenKey(root, key)
except:
return None
try:
(val, typ) = _winreg.QueryValueEx(hkey, value)
except:
_winreg.CloseKey(hkey)
return None
_winreg.CloseKey(hkey)
return val
def find_msvc(env,version):
import _winreg
vs_ver = str(version) + '.0'
vs_key = 'SOFTWARE\\Microsoft\\VisualStudio\\' + vs_ver + '\\Setup\\VS'
vc_key = 'SOFTWARE\\Microsoft\\VisualStudio\\' + vs_ver + '\\Setup\\VC'
vs_dir = _read_registry(_winreg.HKEY_LOCAL_MACHINE, vs_key, 'ProductDir')
vc_dir = _read_registry(_winreg.HKEY_LOCAL_MACHINE, vc_key, 'ProductDir')
# On a 64-bit host, look for a 32-bit installation
if (not vs_dir or not vc_dir):
vs_key = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\' + \
vs_ver + '\\Setup\\VS'
vc_key = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\' + \
vs_ver + '\\Setup\\VC'
vs_dir = _read_registry(_winreg.HKEY_LOCAL_MACHINE,
vs_key, 'ProductDir')
vc_dir = _read_registry(_winreg.HKEY_LOCAL_MACHINE,
vc_key, 'ProductDir')
return (vs_dir,vc_dir)
def _try_to_figure_out_msvs_version_registry(env):
versions = [14,12,11,10,9,8,7,6]
for v in versions:
(vs_dir,vc_dir) = find_msvc(env,v)
if vs_dir and vc_dir:
return (str(v),vs_dir)
return (None,None)
def set_msvs_env(env):
x64_target=False
if env['host_cpu'] == 'x86-64':
x64_target=True
x64_host = False
if env['build_cpu'] == 'x86-64':
x64_host=True
# "express" compiler is 32b only
vc = None
# Verify validity of chosen msvs_version in registry
if env['msvs_version'] != '' :
v = int(env['msvs_version'])
(vs_dir,vc_dir) = find_msvc(env,v)
if not (vs_dir and vc_dir):
warn("Could no find specified version of MSVS. Looking around...")
env['msvs_version'] = ''
if env['msvs_version'] == '':
# The chosen msvs_version was not valid we need to search for it
env['msvs_version'] = _try_to_figure_out_msvs_version(env)
# FIXME: could add a knob to just use registry..
if env['msvs_version'] == '':
env['msvs_version'], vs_dir = \
_try_to_figure_out_msvs_version_registry(env)
if env['msvs_version'] == None:
die("Did not find MSVS version!")
vs_dir = None
i = int(env['msvs_version'])
if i == 6: # 32b only
vc = _set_msvs_dev6(env,x64_host, x64_target)
elif i == 7: # 32b only
vc = _set_msvs_dev7(env,x64_host, x64_target)
elif i == 8: # 32b or 64b
vc = _set_msvs_dev8(env, x64_host, x64_target, vs_dir)
elif i == 9: # 32b or 64b
vc = _set_msvs_dev9(env, x64_host, x64_target, vs_dir)
elif i == 10: # 32b or 64b
vc = _set_msvs_dev10(env, x64_host, x64_target, vs_dir)
elif i == 11: # 32b or 64b
vc = _set_msvs_dev11(env, x64_host, x64_target, vs_dir)
elif i == 12: # 32b or 64b
vc = _set_msvs_dev12(env, x64_host, x64_target, vs_dir)
# And 12 shall be followed by 14. 13? 13 is Right Out!
elif i == 14: # 32b or 64b
vc = _set_msvs_dev14(env, x64_host, x64_target, vs_dir)
else:
die("Unhandled MSVS version: " + env['msvs_version'])
msgb("FOUND MS VERSION",env['msvs_version'])
return vc

93
mbuild/plan.py Executable file
View File

@@ -0,0 +1,93 @@
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
"""Intermediate data structure produced by builders and sent to the
dependence directed acyclic graph (DAG) that sequences execution.
Users who create their own builders to call python functions should emit
an plan_t object and add it to the DAG.
"""
class plan_t(object):
"""
An object that the builders create and is passed to the DAG L{dag_t} to
order the tasks. This is used exclusively to create
L{command_t}'s.
"""
def __init__(self, command, args=None, env=None, input=None, output=None, name=None):
"""
Create an input record for the L{dag_t} describing a
command. The command can be a string to execute or a python
function or a list of strings and python functions. The python
function will be passed two arguments: args and env. args is
typically a list, but could be anything.
The input and output lists of files are used by the L{dag_t} to
order this command relative to other commands.
When the command is a python function, the python function is
called with two arguments: args and an env of type
L{env_t}. The args can be anything but are typically the
inputs to the python function and any information required to
generate the corresponding outputs. The python functions return
a 2-typle (retcode, stdout).
The input list: When the command is a python function, the
plan_t's input list contains at least the input files names
passed via args variable. The input list can be a superset
containing more stuff that might trigger the command
execution.
If the command does not produce a specific output, you can
specify a dummy file name to allow sequencing relative to
other commands.
@type command: string or python function or a list
@param command: string or python function.
@type args: list
@param args: (optional) arguments to the command if it is a python function
@type env: L{env_t}
@param env: (optional) an environment to pass to the python function
@type input: list
@param input: (optional) files upon which this command depends.
@type output: list
@param output: (optional) files which depend on this command.
@type name: string
@param name: (optional) short name to be used to identify the work/task
"""
self.command = command
self.args = args
self.env = env
self.input = input
self.output = output
self.name = name
def __str__(self):
s = []
if self.name:
s.append('NAME: ' + str(self.name))
s.append('CMD: ' + str(self.command))
s.append('INPUT: ' + str(self.input))
s.append('OUTPUT: ' + str(self.output))
return " ".join(s)

104
mbuild/scanner.py Executable file
View File

@@ -0,0 +1,104 @@
# -*- python -*-
# Mark Charney
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
"""Function for header include scanning"""
import re
import os
import sys
import base
import util
class mbuild_header_record_t:
"""Stores information about headers that we find"""
def __init__(self, fn, found=True):
self.file_name = fn
self.system = False
self.found = found
def __str__(self):
s = ''
s = self.file_name
if self.system:
s += ' system'
if not self.found:
s += ' not-found'
return s
def mbuild_compute_path(hname, search_path):
"""Return the full path of the header hname, if found and None
otherwise. Search the path in order and see if we find the file"""
for p in search_path:
tname = util.join(p,hname)
tname = os.path.realpath(tname)
#mbuild_base.msgb("TESTING", tname)
if os.path.exists(tname):
return tname
return None
# FIXME: ignoring system headers for now.
mbuild_include_pattern = re.compile(r'^[ \t]*#[ \t]*include[ \t]+"(?P<hdr>[^"]+)"')
mbuild_nasm_include_pattern = re.compile(r'^[ \t]*%include[ \t]+"(?P<hdr>[^"]+)"')
def mbuild_scan(fn, search_path):
"""Given a file name fn, and a list of search paths, scan for
headers in fn and return a list of mbuild_header_record_t's. The
header records indicate if the file is a system include based on
<> symbols or if the file was missing. If the file cannot be
found, we assume it is in the assumed_directory."""
global mbuild_include_pattern
global mbuild_nasm_include_pattern
all_names = []
if not os.path.exists(fn):
return all_names
source_path = os.path.dirname(fn)
if source_path == '':
source_path = '.'
aug_search_path = [source_path] + search_path
for line in file(fn).readlines():
#print line
hgroup = mbuild_include_pattern.match(line)
if not hgroup:
hgroup = mbuild_nasm_include_pattern.match(line)
if hgroup:
hname = hgroup.group('hdr')
#print hname
full_name = mbuild_compute_path(hname, aug_search_path)
if full_name:
hr = mbuild_header_record_t(full_name)
else:
hr = mbuild_header_record_t(hname, found=False)
all_names.append(hr)
return all_names
def _test_scan():
paths = ["/home/mjcharne/proj/learn/" ]
all_headers = mbuild_scan("/home/mjcharne/proj/learn/foo.cpp", paths)
for hr in all_headers:
print hr
if __name__ == '__main__':
_test_scan()

1148
mbuild/util.py Executable file

File diff suppressed because it is too large Load Diff

1020
mbuild/work_queue.py Executable file

File diff suppressed because it is too large Load Diff

21
setup.py Normal file
View File

@@ -0,0 +1,21 @@
#
# to build the distribution file:
# python setup.py sdist --formats=gztar,zip
#
# to build an installer for windows:
# python setup.py bdist_wininst
#
# to install the distribution file:
# python setup.py install
from distutils.core import setup
setup(name='mbuild',
version='0.2496',
url='https://github.com/intelxed/mbuild',
description = "mbuild: python based build system",
author = 'Mark Charney',
author_email = 'Mark.Charney@intel.com',
packages = [ 'mbuild']
)

36
templates/find_mbuild.py Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import os
import sys
def find_dir(d):
dir = os.getcwd()
last = ''
while dir != last:
target_dir = os.path.join(dir,d)
if os.path.exists(target_dir):
return target_dir
last = dir
(dir,tail) = os.path.split(dir)
return None
mbuild_path = find_dir('mbuild')
sys.path = [ mbuild_path ] + sys.path
import mbuild

45
tests/1.py Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env python
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import os,sys
sys.path = ['..'] + sys.path
import mbuild
env = mbuild.env_t()
env.parse_args()
env['jobs']=1
work_queue = mbuild.work_queue_t(env['jobs'])
all_cmds = [ '/bin/ls -R ../..' ]
subs = {}
command_list = []
for cmd in all_cmds:
cmd = cmd % (subs)
mbuild.msgb('ADDING', cmd)
command_list.append(cmd)
work_queue.add_sequential(command_list, unbufferred=True)
phase = "BUILD"
okay = work_queue.build()
if not okay:
mbuild.die("[%s] failed. dying..." % phase)
mbuild.msgb(phase, "succeeded")

46
tests/2.py Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import os,sys
sys.path = ['..'] + sys.path
import mbuild
env = mbuild.env_t()
env.parse_args()
env['jobs']=1
work_queue = mbuild.work_queue_t(env['jobs'])
all_cmds = [ '/bin/ls -R ../..' ]
subs = {}
command_list = []
for cmd in all_cmds:
cmd = cmd % (subs)
mbuild.msgb('ADDING', cmd)
c = mbuild.command_t(cmd, output_file_name="foo")
work_queue.add(c)
command_list.append(cmd)
phase = "BUILD"
okay = work_queue.build()
if not okay:
mbuild.die("[%s] failed. dying..." % phase)
mbuild.msgb(phase, "succeeded")

47
tests/3.py Executable file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import os,sys
sys.path = ['..'] + sys.path
import mbuild
env = mbuild.env_t()
env.parse_args()
env['jobs']=8
work_queue = mbuild.work_queue_t(env['jobs'])
if False:
all_cmds = [ '/bin/ls -R ../..' ]
subs = {}
command_list = []
for cmd in all_cmds:
cmd = cmd % (subs)
mbuild.msgb('ADDING', cmd)
c = mbuild.command_t(cmd, output_file_name="foo")
work_queue.add(c)
command_list.append(cmd)
phase = "BUILD"
okay = work_queue.build()
if not okay:
mbuild.die("[%s] failed. dying..." % phase)
mbuild.msgb(phase, "succeeded")

35
tests/VersionInfo.rc Normal file
View File

@@ -0,0 +1,35 @@
#define FOOBARVERSION 23,32
#define STRFOOBARVERSION "23.32\0"
1 VERSIONINFO
FILEVERSION FOOBARVERSION
PRODUCTVERSION FOOBARVERSION
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Foobar Corporation"
VALUE "FileDescription", "Foobar<61> Engine DLL"
VALUE "FileVersion", STRFOOBARVERSION
VALUE "InternalName", "Foobar<61> Engine"
VALUE "LegalCopyright", "Copyright (C) 2014"
VALUE "OriginalFilename", "vcpu_foobar.dll"
VALUE "ProductName", "Foobar<61> Engine"
VALUE "ProductVersion", STRFOOBARVERSION
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

43
tests/a.py Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import sys
import mbuild
env = mbuild.env_t()
env.parse_args()
if 'clean' in env['targets']:
mbuild.remove_tree(env['build_dir'])
sys.exit(0)
mbuild.cmkdir(env['build_dir'])
if not env.on_windows():
env['LINK'] = env['CC'] # not g++ for this program
dep_tracker = mbuild.dag_t()
prog = env.build_dir_join('hello' + env['EXEEXT'])
cmd1 = dep_tracker.add(env, env.cc_compile('hello.c'))
cmd2 = dep_tracker.add(env, env.link(cmd1.targets, prog))
work_queue = mbuild.work_queue_t(env['jobs'])
okay = work_queue.build(dag=dep_tracker)
if not okay:
mbuild.die("build failed")
mbuild.msgb("SUCCESS")

49
tests/b.py Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import sys
import mbuild
env = mbuild.env_t()
env.parse_args()
if 'clean' in env['targets']:
mbuild.remove_tree(env['build_dir'])
sys.exit(0)
mbuild.cmkdir(env['build_dir'])
env['LINK'] = env['CC'] # not g++ for this program
dep_tracker = mbuild.dag_t()
prog = env.build_dir_join('hello' + env['EXEEXT'])
cmd1 = dep_tracker.add(env, env.cc_compile('hello.c'))
# take the nicely created link command and add on the strip command
# sequentially.
plan = env.link(cmd1.targets, prog)
cmds = [plan.command, " strip " + prog]
plan2 = mbuild.plan_t( cmds, env=env,
input=plan.input, output=plan.output)
cmd2 = dep_tracker.add(env, plan2)
work_queue = mbuild.work_queue_t(env['jobs'])
okay = work_queue.build(dag=dep_tracker)
if not okay:
mbuild.die("build failed")
mbuild.msgb("SUCCESS")

41
tests/c.py Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import sys
# find.py is in the tests dir. It finds mbuild and puts it on the
# sys.path.
import find
import mbuild
env = mbuild.env_t(init_verbose=0)
env.parse_args()
#mbuild.build_env.set_env_icl(env)
mbuild.cmkdir(env['build_dir'])
dag = mbuild.dag_t()
res = env.compile(dag,['VersionInfo.rc'])
objs = env.compile(dag,['hello.c'])
cmd = dag.add(env,
env.dynamic_lib(objs + res,
env.build_dir_join('hello.dll')))
work_queue = mbuild.work_queue_t(env['jobs'])
okay = work_queue.build(dag=dag)
if not okay:
mbuild.die("build failed")
mbuild.msgb("SUCCESS")

8
tests/circular-dep/a.h Normal file
View File

@@ -0,0 +1,8 @@
#if !defined(AAA_1)
# define AAA_1
# include "b.h"
#endif

5
tests/circular-dep/b.h Normal file
View File

@@ -0,0 +1,5 @@
#if !defined(BBB_2)
# define BBB_2
# include "c.h"
#endif

5
tests/circular-dep/c.h Normal file
View File

@@ -0,0 +1,5 @@
#if !defined(CCC_1)
# define CCC_1
# include "a.h"
#endif

25
tests/circular-dep/find.py Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env python
# add the right mbuild dir to the sys.path so that we can import mbuild.
import os
import sys
def find_dir(d):
dir = os.getcwd()
last = ''
while dir != last:
target_dir = os.path.join(dir,d)
if os.path.exists(target_dir):
return target_dir
last = dir
(dir,tail) = os.path.split(dir)
return None
# go up an extra level because we are in the mbuild tree.
# otherwise we find the subdir instead of the parent dir.
# normally this last os.path.dirname() would not be required.
mbuild_path = os.path.dirname(find_dir('mbuild'))
sys.path = [ mbuild_path ] + sys.path

4
tests/circular-dep/m.h Normal file
View File

@@ -0,0 +1,4 @@
#if !defined(MMM_1)
# define MMM_1
#endif

View File

@@ -0,0 +1,5 @@
#include "z.h"
int main() {
return 0;
}

31
tests/circular-dep/mfile.py Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- python -*-
import sys
import find
import mbuild
def setup():
env = mbuild.env_t()
env.parse_args()
mbuild.cmkdir(env['build_dir'])
if not env.on_windows():
env['LINK'] = env['CC'] # not g++ for this program
return env
def work(env):
#with then env, the dag hash file is put in the build_dir.
dag = mbuild.dag_t('circular-test',env=env)
work_queue = mbuild.work_queue_t(env['jobs'])
env.compile_and_link(dag, ['main.c'], 'main' + env['EXEEXT'])
okay = work_queue.build(dag=dag)
if not okay:
mbuild.die("build failed")
mbuild.msgb("SUCCESS")
if __name__ == "__main__":
env = setup()
work(env)

7
tests/circular-dep/z.h Normal file
View File

@@ -0,0 +1,7 @@
#if !defined(ZZZ_1)
# define ZZZ_1
# include "a.h"
#endif

25
tests/delay.c Normal file
View File

@@ -0,0 +1,25 @@
/*BEGIN_LEGAL
Copyright (c) 2016 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
END_LEGAL */
int main(int argc, char** argv) {
unsigned int i,j,n;
n = atoi(argv[1]);
for(i=0;i<n;i++)
for(j=0;j<1000*1000;j++)
;
return 0;
}

42
tests/find.py Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env python
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
# add the right mbuild dir to the sys.path so that we can import mbuild.
import os
import sys
def find_dir(d):
dir = os.getcwd()
last = ''
while dir != last:
target_dir = os.path.join(dir,d)
if os.path.exists(target_dir):
return target_dir
last = dir
(dir,tail) = os.path.split(dir)
return None
# go up an extra level because we are in the mbuild tree.
# otherwise we find the subdir instead of the parent dir.
# normally this last os.path.dirname() would not be required.
mbuild_path = os.path.dirname(find_dir('mbuild'))
sys.path = [ mbuild_path ] + sys.path

23
tests/hello.c Normal file
View File

@@ -0,0 +1,23 @@
/*BEGIN_LEGAL
Copyright (c) 2016 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
END_LEGAL */
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0;
}

22
tests/negtime.py Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import find
import mbuild
print mbuild.get_elapsed_time(10,0)

55
tests/nodag.py Executable file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env python
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
# Example of using the connections between commands to enforce
# execution ordering. A dag_t requires that you have files and that
# doesn't help for things that are not file oriented.
import os
import sys
import mbuild
env = mbuild.env_t()
env.parse_args()
work_queue = mbuild.work_queue_t(env['jobs'])
last_command_in_sequence = {}
for i in range(0,99):
cmd = "/bin/echo %d" % (i)
c = mbuild.command_t(cmd)
# break the commmands in to 7 sequences
seq = i % 7
# enforce a dependence between commands in the same sequence
try:
prev = last_command_in_sequence[seq]
prev.add_after_me(c)
except:
pass
last_command_in_sequence[seq]=c
mbuild.msgb('ADDING',i)
# add it to the work queue
work_queue.add(c)
# run the commands. Use --jobs N to set the number of workers to N.
okay = work_queue.build()
if not okay:
mbuild.die("build failed")
mbuild.msgb("SUCCESS")

2
tests/nondep/README.txt Normal file
View File

@@ -0,0 +1,2 @@
this is not a dependence driven build.
it is for testing various msvs environments.

67
tests/nondep/__mbuild Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- python -*-
import sys
import os
import glob
def find_dir(d):
idir = os.getcwd()
last_idir = ''
while idir != last_idir:
mfile = os.path.join(idir,d)
if os.path.exists(mfile):
return mfile
last_idir = idir
idir = os.path.dirname(idir)
print "Could not find %s file, looking upwards"% (mfile)
sys.exit(1)
#sys.path = [find_dir('mbuild')] + sys.path
sys.path.append('../..')
import mbuild
def build(env, phase='BUILD',terminate_on_errors=False):
"""Build everything in the work queue"""
okay = env.work_queue.build(die_on_errors=False)
if not okay:
if terminate_on_errors:
mbuild.die("[%s] failed." % phase)
else:
mbuild.msgb("[%s] failed." % phase)
else:
mbuild.msgb(phase, "succeeded")
def compile_and_link(env,fn):
env['file']=fn
(base,ext) = os.path.splitext(fn)
if ext in ['.cpp','.C']:
env['x_compiler'] = "%(CXX)s"
env['tflags'] = "%(CXXFLAGS)s"
else:
env['x_compiler'] = "%(CC)s"
env['tflags'] = "%(CCFLAGS)s"
env['exe'] = "%s.%s.%s.exe" % (base, env['build_os'],env['host_cpu'])
cmd = "%(x_compiler)s %(tflags)s %(file)s %(EXEOUT)s%(exe)s"
cmd = env.expand_string(cmd)
env.work_queue.add(mbuild.command_t(cmd))
def work():
env = mbuild.env_t()
env.parser.add_option("--build",
dest="build", action="store_true", default=False,
help="Build tests")
env.parse_args()
env.work_queue = mbuild.work_queue_t(env['jobs'])
if env['build']:
for s in glob.glob('*.c'):
compile_and_link(env,s)
build(env)
if __name__ == "__main__":
work()

5
tests/nondep/hello.c Normal file
View File

@@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("hello world\n");
return 0;
}

44
tests/sleep.py Executable file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import os,sys
sys.path = ['..'] + sys.path
import mbuild
env = mbuild.env_t()
env.parse_args()
env['jobs']=4
work_queue = mbuild.work_queue_t(env['jobs'])
all_cmds = 2 * [ './delay 40000' ]
subs = {}
command_list = []
for cmd in all_cmds:
cmd = cmd % (subs)
mbuild.msgb('ADDING', cmd)
command_list.append(cmd)
work_queue.add_sequential(command_list, unbufferred=True)
phase = "BUILD"
okay = work_queue.build(show_progress=True)
if not okay:
mbuild.die("[%s] failed. dying..." % phase)
mbuild.msgb(phase, "succeeded")

4
tests/spew Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env python
for i in range(0,1000*1000*100):
print i

40
tests/stdin.py Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import mbuild
def dump(lines):
if lines:
for line in lines:
line = line.strip()
print "::" + line
else:
print "(EMPTY)"
env = mbuild.env_t(0)
env.parse_args()
infile = file('stdin.py')
retval,output,error = mbuild.run_command('cat', stdin=infile)
print "EXIT STATUS ", str(retval)
print "OUTPUT LINES "
dump(output)
print "ERROR LINES "
dump(error)

31
tests/timed3.py Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import find
import mbuild
env = mbuild.env_t(0)
env.parse_args()
retval, output, error = mbuild.run_command_timed('./spew', seconds=2)
print "RETURN CODE ", retval
print "OUTPUT LINES ", len(output)
print "ERROR LINES ", len(error)
for l in error:
print 'ERROR OUTPUT [{}]'.format(l.strip())

60
tests/timed4.py Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
import find
import mbuild
env = mbuild.env_t(0)
env.parse_args()
work_queue = mbuild.work_queue_t(env['jobs'])
c = mbuild.command_t("/bin/sleep 1", seconds=2, show_output=False)
#work_queue.add(c)
c2 = mbuild.command_t("./spew", seconds=2, show_output=False)
#work_queue.add(c2)
def some_python_fn(a,b):
n = 10
x = 0
for i in range(0,n):
for j in range(0,n):
for k in range(0,n):
x += i*j*k
return (0, [str(x)], [])
c3 = mbuild.command_t(some_python_fn, seconds=2, show_output=False)
work_queue.add(c3)
# run the commands. Use --jobs N to set the number of workers to N.
okay = work_queue.build(die_on_errors=False)
if okay:
mbuild.msgb('BUILD', 'pass')
else:
mbuild.msgb('BUILD', 'failed')
print len(c2.output)
print c2.output[0:10]
print str(c2.stderr)
print str(c3.output)

51
tests/use-icl-win.py Normal file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- python -*-
#BEGIN_LEGAL
#
#Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
# example of using icc (icl) on windows.
# need to set toolchain and compiler and add lib dir to LIB env var
import sys
import mbuild
env = mbuild.env_t()
env.parse_args({ 'toolchain':'C:/icc/win/AVX3/2014-11-21/64/bin/',
'compiler':'icl'
})
icc_lib_dir = 'C:/icc/win/AVX3/2014-11-21/64/lib'
env.osenv_add_to_front('LIB',icc_lib_dir)
if 'clean' in env['targets']:
mbuild.remove_tree(env['build_dir'])
sys.exit(0)
mbuild.cmkdir(env['build_dir'])
if not env.on_windows():
env['LINK'] = env['CC'] # not g++ for this program
dep_tracker = mbuild.dag_t()
base='pcommit'
prog = env.build_dir_join(base + env['EXEEXT'])
cmd1 = dep_tracker.add(env, env.cc_compile(base = '.c'))
cmd2 = dep_tracker.add(env, env.link(cmd1.targets, prog))
work_queue = mbuild.work_queue_t(env['jobs'])
okay = work_queue.build(dag=dep_tracker)
if not okay:
mbuild.die("build failed")
mbuild.msgb("SUCCESS")