[gnome-ostree/wip/compile-one-js] WIP moving more compile-one bits to JS



commit 862fd4f1f8b569d7e2e692b7bd9c91f4ac9387ab
Author: Colin Walters <walters verbum org>
Date:   Fri Jan 18 18:23:28 2013 -0500

    WIP moving more compile-one bits to JS

 src/ostbuild/js/builtins/build.js     |   67 +++++++++++++++++++-
 src/ostbuild/js/fileutil.js           |   59 +++++++++++++++++
 src/ostbuild/ostree-build-compile-one |  111 +--------------------------------
 3 files changed, 126 insertions(+), 111 deletions(-)
---
diff --git a/src/ostbuild/js/builtins/build.js b/src/ostbuild/js/builtins/build.js
index 70cc2f6..2d53edc 100644
--- a/src/ostbuild/js/builtins/build.js
+++ b/src/ostbuild/js/builtins/build.js
@@ -276,10 +276,69 @@ const Build = new Lang.Class({
         JsonUtil.writeJsonFileAtomic(this._componentBuildCachePath, this._componentBuildCache, cancellable);
         return cachedata['ostree'];
     },
+    
+    _processBuildResults: function(component, buildResultDir, finalResultDir, cancellable) {
+	let runtimePath = finalResultDir.get_child('runtime');
+	GSystem.file_ensure_directory(runtimePath, true, cancellable);
+	let develPath = finalResultDir.get_child('devel');
+	GSystem.file_ensure_directory(develPath, true, cancellable);
+	let docPath = finalResultDir.get_child('doc');
+	GSystem.file_ensure_directory(docPath, true, cancellable);
+
+	// First, remove /var from the install - components are required to
+	// auto-create these directories on demand.
+	let varPath = buildResultDir.get_child('var');
+	GSystem.shutil_rm_rf(varPath, cancellable);
+
+	// Clean up things we don't want
+	FileUtil.walkDir(buildResultDir, { nameRegex: /\.py[co]$/ },
+			 Lang.bind(this, function(filePath, cancellable) {
+			     GSystem.file_unlink(filePath, cancellable);
+			 }), cancellable);
+
+	// Move symbolic links for shared libraries as well
+	// as static libraries.
+	let libdir = buildResultDir.resolve_relative_path('usr/lib');
+	FileUtil.walkDir(libdir, { nameRegex: /\.(so|a)$/ },
+			 Lang.bind(this, function(filePath, cancellable) {
+			     GSystem.file_unlink(filePath, cancellable);
+			 }), cancellable);
+
+            subpath = os.path.join(dirpath, filename)
+            if filename.endswith('.la'):
+                os.unlink(subpath)
+                continue
+            if not ((filename.endswith('.so')
+                     and os.path.islink(filename))
+                    or filename.endswith('.a')):
+                    continue
+            dest = os.path.join(devel_path, libdirname, filename)
+            _install_and_unlink(subpath, dest)
+
+    for dirname in _DEVEL_DIRS:
+        dirpath = os.path.join(tempdir, dirname)
+        if os.path.isdir(dirpath):
+            dest = os.path.join(devel_path, dirname)
+            _install_and_unlink(dirpath, dest)
+
+    for dirname in _DOC_DIRS:
+        dirpath = os.path.join(tempdir, dirname)
+        if os.path.isdir(dirpath):
+            dest = os.path.join(doc_path, dirname)
+            _install_and_unlink(dirpath, dest)
+    
+    for filename in os.listdir(tempdir):
+        src_path = os.path.join(tempdir, filename)
+        dest_path = os.path.join(runtime_path, filename)
+        _install_and_unlink(src_path, dest_path)
+
+	
+    },
 
     _buildOneComponent: function(component, architecture, cancellable) {
         let basename = component['name'];
 
+
 	let prefix = this._snapshot.data['prefix'];
         let buildname = Format.vprintf('%s/%s/%s', [prefix, basename, architecture]);
         let buildRef = 'components/' + buildname;
@@ -432,7 +491,13 @@ const Build = new Lang.Class({
 	    throw new Error("Build failure in component " + buildname + " : " + msg);
 	}
 
-        let recordedMetaPath = componentResultdir.get_child('_ostbuild-meta.json');
+	let finalBuildResultDir = workdir.get_child('post-results');
+	GSystem.shutil_rm_rf(finalBuildResultDir, cancellable);
+        GSystem.file_ensure_directory(finalBuildResultDir, true, cancellable);
+
+	this._processBuildResults(component, componentResultdir, finalBuildResultDir, cancellable);
+
+        let recordedMetaPath = finalBuildResultDir.get_child('_ostbuild-meta.json');
         JsonUtil.writeJsonFileAtomic(recordedMetaPath, expandedComponent, cancellable);
 
         let commitArgs = ['ostree', '--repo=' + this.repo.get_path(),
diff --git a/src/ostbuild/js/fileutil.js b/src/ostbuild/js/fileutil.js
new file mode 100644
index 0000000..175cab3
--- /dev/null
+++ b/src/ostbuild/js/fileutil.js
@@ -0,0 +1,59 @@
+// Copyright (C) 2012,2013 Colin Walters <walters verbum org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
+const Params = imports.params;
+
+function walkDirInternal(dir, matchParams, callback, cancellable, queryStr) {
+    let denum = dir.enumerate_children(queryStr, Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
+				       cancellable);
+    let info;
+    let subdirs = [];
+    while ((info = denum.next_file(cancellable)) != null) {
+	let name = info.get_name();
+	let child = dir.get_child(name);
+	let ftype = info.get_file_type();
+	
+	if (ftype == Gio.FileType.DIRECTORY) {
+	    subdirs.push(child);
+	    continue;
+	}
+
+	if (matchParams.nameRegex && matchParams.nameRegex.exec(name) === null)
+	    continue;
+	if (matchParams.contentType != null && matchParams.contentType != info.get_content_type())
+	    continue;
+	callback(child, cancellable);
+    }
+
+    denum.close(cancellable);
+
+    for (let i = 0; i < subdirs.length; i++) {
+	walkDirInternal(subdirs[i], matchParams, callback, cancellable, queryStr);
+    }
+}
+
+function walkDir(dir, matchParams, callback, cancellable) {
+    matchParams = Params.parse(matchParams, { nameRegex: null,
+					      contentType: null });
+    let queryStr = 'standard::name,standard::type,unix::mode';
+    if (matchParams.contentType)
+	queryStr += ',standard::fast-content-type';
+    walkDirInternal(dir, matchParams, callback, cancellable, queryStr);
+}
diff --git a/src/ostbuild/ostree-build-compile-one b/src/ostbuild/ostree-build-compile-one
index 816921b..08aaf9b 100755
--- a/src/ostbuild/ostree-build-compile-one
+++ b/src/ostbuild/ostree-build-compile-one
@@ -88,8 +88,6 @@ _DEVEL_DIRS = ['usr/include',
                'usr/share/pkgconfig',
                'usr/lib/pkgconfig']
 
-tempfiles = []
-
 def _has_buildapi_configure_variable(name):
     var = '#buildapi-variable-%s' % (name, )
     for line in open('configure'):
@@ -218,119 +216,12 @@ def main(args):
 
     run_sync(args, cwd=builddir)
 
-    tempdir = tempfile.mkdtemp(prefix='ostbuild-destdir-%s' % (metadata['name'].replace('/', '_'), ))
-    tempfiles.append(tempdir)
-    args = ['make', 'install', 'DESTDIR=' + tempdir]
+    args = ['make', 'install', 'DESTDIR=' + ostbuild_resultdir]
     run_sync(args, cwd=builddir)
 
-    runtime_path = os.path.join(ostbuild_resultdir, 'runtime')
-    devel_path = os.path.join(ostbuild_resultdir, 'devel')
-    doc_path = os.path.join(ostbuild_resultdir, 'doc')
-    for artifact_type in ['runtime', 'devel', 'doc']:
-        resultdir = os.path.join(ostbuild_resultdir, artifact_type)
-        if os.path.isdir(resultdir):
-            shutil.rmtree(resultdir)
-        os.makedirs(resultdir)
-
-    # Remove /var from the install - components are required to
-    # auto-create these directories on demand.
-    varpath = os.path.join(tempdir, 'var')
-    if os.path.isdir(varpath):
-        shutil.rmtree(varpath)
-
-    # Move symbolic links for shared libraries as well
-    # as static libraries.  And delete all .la files.
-    libdir = os.path.join(tempdir, 'usr/lib')
-    for dirpath, subdirs, files in os.walk(libdir):
-        for filename in files:
-            subpath = os.path.join(dirpath, filename)
-            if filename.endswith('.la'):
-                os.unlink(subpath)
-                continue
-            if not ((filename.endswith('.so')
-                     and os.path.islink(filename))
-                    or filename.endswith('.a')):
-                    continue
-            dest = os.path.join(devel_path, libdirname, filename)
-            _install_and_unlink(subpath, dest)
-
-    for dirname in _DEVEL_DIRS:
-        dirpath = os.path.join(tempdir, dirname)
-        if os.path.isdir(dirpath):
-            dest = os.path.join(devel_path, dirname)
-            _install_and_unlink(dirpath, dest)
-
-    for dirname in _DOC_DIRS:
-        dirpath = os.path.join(tempdir, dirname)
-        if os.path.isdir(dirpath):
-            dest = os.path.join(doc_path, dirname)
-            _install_and_unlink(dirpath, dest)
-    
-    for filename in os.listdir(tempdir):
-        src_path = os.path.join(tempdir, filename)
-        dest_path = os.path.join(runtime_path, filename)
-        _install_and_unlink(src_path, dest_path)
-
-    for tmpname in tempfiles:
-        assert os.path.isabs(tmpname)
-        if os.path.isdir(tmpname):
-            shutil.rmtree(tmpname)
-        else:
-            try:
-                os.unlink(tmpname)
-            except OSError, e:
-                pass
-
     endtime = time.time()
 
     log("Compilation succeeded; %d seconds elapsed" % (int(endtime - starttime),))
     log("Results placed in %s" % (ostbuild_resultdir, ))
 
-def _install_and_unlink(src, dest):
-    statsrc = os.lstat(src)
-    dirname = os.path.dirname(dest)
-    if not os.path.isdir(dirname):
-        os.makedirs(dirname)
-
-    # Ensure that all installed files are at least rw-rw-r--;
-    # we don't support private/hidden files.
-    # Directories also need u+x, i.e. they're rwxrw-r--
-    if not stat.S_ISLNK(statsrc.st_mode):
-        minimal_mode = (stat.S_IRUSR | stat.S_IWUSR |
-                        stat.S_IRGRP | stat.S_IWGRP |
-                        stat.S_IROTH)
-        if stat.S_ISDIR(statsrc.st_mode):
-            minimal_mode |= stat.S_IXUSR
-        os.chmod(src, statsrc.st_mode | minimal_mode)
-
-    if stat.S_ISDIR(statsrc.st_mode):
-        if not os.path.isdir(dest):
-            os.mkdir(dest)
-        for filename in os.listdir(src):
-            src_child = os.path.join(src, filename)
-            dest_child = os.path.join(dest, filename)
-
-            _install_and_unlink(src_child, dest_child)
-        os.rmdir(src)
-    else:
-        basename = os.path.basename(src)
-        ignored = False
-        for r in _IGNORE_FILENAME_REGEXPS:
-            if r.match(basename):
-                ignored = True
-                break
-        if ignored:
-            log("Not installing %s" % (src, ))
-            os.unlink(src)
-            return
-        try:
-            os.rename(src, dest)
-        except OSError, e:
-            if stat.S_ISLNK(statsrc.st_mode):
-                linkto = os.readlink(src)
-                os.symlink(linkto, dest)
-            else:
-                shutil.copy2(src, dest)
-            os.unlink(src)
-
 main(sys.argv[1:])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]