Ejemplo n.º 1
0
    def computeModuleFolders(self, cx, module):
        buildBase = self.getBuildFolder(cx)
        buildPath = os.path.join(cx.buildPath, buildBase)

        if module.context.sourceFolder == '' and cx.sourceFolder == '':
            # Special degenerate case that fails os.path.relpath().
            subfolder = ''
        elif paths.IsSubPath(module.context.sourceFolder, cx.sourceFolder):
            # If this module is a subpath of the original context, we use the difference.
            subfolder = os.path.relpath(module.context.sourceFolder,
                                        cx.sourceFolder)
            if subfolder == '.':
                subfolder = ''
        else:
            # Otherwise... do our best approximation and use a replica of the source
            # folder path. This is not ideal since we could have a collision, if for
            # example we compile:
            #   toplevel/module1/crab.cc -> toplevel/toplevel.so/module1/crab.o
            #   module1/crab.cc          -> toplevel/toplevel.so/module1/crab.o
            #
            # This is bad organization on the project's part, so hopefully we don't
            # have to make a workaround for it.
            subfolder = module.context.sourceFolder

        # Local is relative to the context of the module. buildFolder is relative
        # to the build root.
        localFolder = os.path.normpath(
            os.path.join(self.localFolder, subfolder))
        buildFolder = os.path.normpath(os.path.join(buildBase, subfolder))
        buildPath = os.path.normpath(os.path.join(buildPath, subfolder))
        return localFolder, buildFolder, buildPath
Ejemplo n.º 2
0
    def runBuildScriptImpl(self, parent, path, vars):
        assert isinstance(path, util.StringType())

        if parent is not self.contextStack_[-1]:
            raise Exception(
                'Can only create child build contexts of the currently active context'
            )

        sourceFolder, buildFolder, scriptFile = self.computeScriptPaths(
            parent, path)

        # Get the absolute script path.
        scriptPath = os.path.join(self.sourcePath, scriptFile)
        self.generator.addConfigureFile(parent, scriptPath)

        # Make the new context. We allow top-level contexts in the root build
        # and otherwise for absolute paths.
        if isinstance(parent, RootBuildContext) or \
           (isinstance(parent, TopLevelBuildContext) and path.startswith('/')):
            constructor = TopLevelBuildContext
        else:
            if not paths.IsSubPath(sourceFolder, parent.sourceFolder):
                raise Exception(
                    "Nested build contexts must be within the same folder structure"
                )
            constructor = BuildContext

        cx = constructor(cm=self,
                         parent=parent,
                         vars=vars,
                         script=scriptPath,
                         sourceFolder=sourceFolder,
                         buildFolder=buildFolder)

        scriptGlobals = self.execContext(cx)
        return scriptGlobals.get('rvalue', None)
Ejemplo n.º 3
0
 def runTest(self):
     self.assertEqual(paths.IsSubPath("/a/b/c", "/a"), True)
     self.assertEqual(paths.IsSubPath("/t/b/c", "/a"), False)
     self.assertEqual(paths.IsSubPath("t", "./"), True)
     self.assertEqual(paths.IsSubPath(r"C:\blah", "C:\\", ntpath), True)
     self.assertEqual(paths.IsSubPath(r"C:\blah", "D:\\", ntpath), False)