Sha256: 18a81f53dce02227504e40a549e3c5c5b8ab69f0c9fb0484711622df20f39641

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

require "autobuild/environment"

module Autoproj
    module Ops
        def self.cached_env_path(root_dir)
            File.join(root_dir, ".autoproj", "env.yml")
        end

        def self.load_cached_env(root_dir)
            path = cached_env_path(root_dir)
            if File.file?(path)
                env = YAML.safe_load(File.read(path))
                Autobuild::Environment::ExportedEnvironment.new(
                    env["set"], env["unset"], env["update"]
                )
            end
        end

        def self.save_cached_env(root_dir, env)
            env = env.exported_environment
            path = cached_env_path(root_dir)
            existing =
                begin
                    YAML.safe_load(File.read(path))
                rescue Exception
                end

            env = Hash["set" => env.set, "unset" => env.unset, "update" => env.update]
            if env != existing
                Ops.atomic_write(path) do |io|
                    io.write YAML.dump(env)
                end
                true
            end
        end
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
autoproj-2.17.0 lib/autoproj/ops/cached_env.rb
autoproj-2.16.0 lib/autoproj/ops/cached_env.rb
autoproj-2.15.3 lib/autoproj/ops/cached_env.rb
autoproj-2.15.2 lib/autoproj/ops/cached_env.rb
autoproj-2.15.1 lib/autoproj/ops/cached_env.rb
autoproj-2.15.0 lib/autoproj/ops/cached_env.rb