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



commit 45d6fb28f09db6ea7fbffcd036fa73d1336948f7
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/fileutil.js           |   62 +++++++++++++++++
 src/ostbuild/js/tasks/task-build.js   |   69 +++++++++++++++++++-
 src/ostbuild/ostree-build-compile-one |  117 +--------------------------------
 3 files changed, 131 insertions(+), 117 deletions(-)
---
diff --git a/src/ostbuild/js/fileutil.js b/src/ostbuild/js/fileutil.js
new file mode 100644
index 0000000..fee9ecc
--- /dev/null
+++ b/src/ostbuild/js/fileutil.js
@@ -0,0 +1,62 @@
+// 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.fileType !== null && matchParams.fileType != info.get_file_type())
+	    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,
+					      fileType: 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/js/tasks/task-build.js b/src/ostbuild/js/tasks/task-build.js
index c03fd96..722f936 100644
--- a/src/ostbuild/js/tasks/task-build.js
+++ b/src/ostbuild/js/tasks/task-build.js
@@ -280,6 +280,66 @@ const TaskBuild = 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])|(la)$/ },
+			 Lang.bind(this, function(filePath, cancellable) {
+			     GSystem.file_unlink(filePath, cancellable);
+			 }), cancellable);
+
+	// Move symbolic links for shared libraries to devel
+	let libdir = buildResultDir.resolve_relative_path('usr/lib');
+	FileUtil.walkDir(libdir, { nameRegex: /\.so$/,
+				   fileType: Gio.FileType.SYMBOLIC_LINK },
+			 Lang.bind(this, function(filePath, cancellable) {
+			     let relpath = buildResultDir.get_relative_path(filePath);
+			     let target = develPath.resolve_relative_path(relpath);
+			     GSystem.file_rename(filePath, target, 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)
+
+	
+    },
 
     _onBuildComplete: function(taskset, success, msg, loop) {
 	this._currentBuildSucceded = success;
@@ -290,6 +350,7 @@ const TaskBuild = new Lang.Class({
     _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 unixBuildname = buildname.replace(/\//g, '_');
@@ -428,7 +489,13 @@ const TaskBuild = new Lang.Class({
 	print("Started child process " + context.argv.map(GLib.shell_quote).join(' '));
 	proc.wait_sync_check(cancellable);
 
-        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/ostree-build-compile-one b/src/ostbuild/ostree-build-compile-one
index 7651171..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,125 +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)
-
-    # Delete all .la files.  See:
-    # https://bugzilla.gnome.org/show_bug.cgi?id=654013
-    libdir = os.path.join(tempdir, 'usr/lib')
-    for dirpath, subdirs, files in os.walk(libdir):
-        for filename in files:
-            path = os.path.join(dirpath, filename)
-            if filename.endswith('.la'):
-                os.unlink(path)
-
-    # Move symbolic links for shared libraries as well
-    # as static libraries into /devel.
-    if os.path.exists(libdir):
-        for filename in os.listdir(libdir):
-            path = os.path.join(libdir, filename)
-            stbuf = os.lstat(path)
-            if not ((filename.endswith('.so')
-                     and stat.S_ISLNK(stbuf.st_mode))
-                    or filename.endswith('.a')):
-                    continue
-            dest = os.path.join(devel_path, 'usr/lib', filename)
-            _install_and_unlink(path, 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]