builddir 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+
2
+ ## 0.1.0 (2014-08-05)
3
+
4
+ Features:
5
+
6
+ - initial release as ruby gem
7
+ - `builddir_cmake` helper in ruby
8
+ - `builddir_configure` helper in ruby
9
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in builddir.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mario Werner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Builddir
2
+
3
+ **builddir** is a little helper tool for C/C++ programmers to manage
4
+ out-of-source build directories. It manages mappings between build directories
5
+ and the associated source directories and allows to switch between them.
6
+
7
+ ## Installation
8
+
9
+ Installation consists out of multiple steps. The first is to install the
10
+ builddir gem:
11
+
12
+ gem install builddir
13
+
14
+ Second, a shell wrapper script (`builddir_source_script`) has to be placed in
15
+ the PATH. The script can either be installed by hand (from `lib/data`) or can
16
+ be generated using the `builddir_generate_source_script` command.
17
+
18
+ builddir_generate_source_script ~/bin/builddir_source_script
19
+
20
+ Third, to make builddir intuitively usable it is recommended to define the
21
+ following bash aliases.
22
+
23
+ alias builddir='source builddir_source_script'
24
+ alias bdir='builddir'
25
+ alias cds='builddir -s'
26
+ alias cdb='builddir -cb'
27
+ alias cmake='builddir_cmake'
28
+ alias configure='builddir_configure'
29
+
30
+ Fourth, define the build directory root by exporting the `DEFAULT_BUILDDIR`
31
+ environment variable. When `DEFAULT_BUILDDIR` is not defined then
32
+ `/tmp/builddir` is used as default.
33
+
34
+ export DEFAULT_BUILDDIR="<path to the builddir>"
35
+
36
+ It is highly recommended to add the alias definitions and the environment
37
+ variable definition to the configuration file
38
+ (`~/.bashrc`, `~/.zshrc.local`, ...) of the used shell to make them permanent.
39
+
40
+ ## Usage
41
+
42
+ TODO: Document the different operations
43
+
44
+ ## TODO:
45
+ * add documentation
46
+ * add unit tests
47
+ * support multiple build directories?
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'builddir'
3
+
4
+ # figure out if the src path is needed
5
+ src_dir = nil
6
+ append_src_dir = true
7
+
8
+ # blacklist all flags where concatination of the src dir is not desired
9
+ append_src_dir = false if ARGV.any? { |val| val =~ /(^-[hH]$)|(^\/\?$)|(^-help$)|(^-usage$)|(^--help)/ }
10
+ append_src_dir = false if ARGV.any? { |val| val =~ /(^\/V$)|(^--?version$)/ }
11
+ append_src_dir = false if ARGV.any? { |val| val =~ /^--copyright$/ }
12
+ append_src_dir = false if ARGV.any? { |val| val =~ /^--system-information$/ }
13
+ append_src_dir = false if ARGV.any? { |val| val =~ /^--build$/ }
14
+ append_src_dir = false if ARGV.any? { |val| val =~ /^-E$/ }
15
+
16
+ if append_src_dir
17
+ # try to find a mapping
18
+ mapping = Builddir.loadMapping()
19
+ mapping ||= []
20
+
21
+ currentDir = Dir.pwd
22
+ entry = Builddir.findExactMapping(mapping,currentDir)
23
+ src_dir = entry[:srcDir] unless entry.nil? || entry[:type] != :BUILD_DIR
24
+ end
25
+
26
+ unless src_dir.nil?
27
+ system 'cmake', *ARGV, src_dir
28
+ else
29
+ system 'cmake', *ARGV
30
+ end
31
+ exit $?.exitstatus
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'builddir'
3
+
4
+ # figure out if the src path is needed
5
+ config_file = nil
6
+
7
+ # try to find a mapping
8
+ mapping = Builddir.loadMapping()
9
+ mapping ||= []
10
+ currentDir = Dir.pwd
11
+ entry = Builddir.findExactMapping(mapping,currentDir)
12
+ config_file = File.join(entry[:srcDir],"configure") unless entry.nil? || entry[:type] != :BUILD_DIR
13
+
14
+ # execute the configure file in the source directory if on exists
15
+ unless config_file.nil? || !File.exists?(config_file)
16
+ system config_file, *ARGV
17
+ else
18
+ system 'configure', *ARGV
19
+ end
20
+ exit $?.exitstatus
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ require 'trollop'
4
+
5
+ require 'builddir'
6
+
7
+ p = Trollop::Parser.new do
8
+ version "#{Builddir::NAME} Version #{Builddir::VERSION}"
9
+ banner <<-EOS
10
+ Generates the script which has to be sourced to change change directories with builddir.
11
+
12
+ Usage:
13
+ #{$0} [options] [TargetFile]
14
+
15
+ where [options] are:
16
+ EOS
17
+ end
18
+
19
+ opts = {}
20
+ Trollop::with_standard_exception_handling p do
21
+ opts = p.parse ARGV
22
+ raise Trollop::HelpNeeded if ARGV.size() > 1 # show help screen
23
+ end
24
+
25
+ file_path = File.join(Builddir.gem_libdir, "data", "builddir_source_script")
26
+
27
+ # write file content to stdout
28
+ if ARGV.size == 0
29
+ puts File.read(file_path)
30
+
31
+ # write file content to another file
32
+ else
33
+ FileUtils.cp(file_path, ARGV[0])
34
+ end
35
+
36
+ exit 0
37
+
data/bin/builddir_impl ADDED
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require 'trollop'
5
+
6
+ require 'builddir'
7
+
8
+ def createBuildDirPath(baseDir,baseName)
9
+ basePath = Pathname.new("#{baseDir}/#{baseName}")
10
+ return basePath.to_s unless File.exists?(basePath)
11
+ i = 1
12
+ while File.exists?(basePath.to_s + i.to_s) do i += 1 end
13
+ return basePath.to_s + i.to_s
14
+ end
15
+
16
+ # redirect stdout to stderr
17
+ $stdout = $stderr
18
+
19
+ p = Trollop::Parser.new do
20
+ version "#{Builddir::NAME} Version #{Builddir::VERSION}"
21
+ banner <<-EOS
22
+ Usage:
23
+ builddir [options] [baseName]
24
+ where [options] are:
25
+ EOS
26
+ opt :build, "Get the build directory"
27
+ opt :create, "Create build directory if necessary"
28
+ opt :delete, "remove + delete the build directory."
29
+ opt :help, "Display this help message"
30
+ opt :purge, "Delete all abandoned build directories without mapping"
31
+ opt :remove, "Remove connection between the src and the build directory"
32
+ opt :source, "Get the source directory"
33
+ opt :verbose, "Verbose mode for debugging", :short => "V"
34
+ end
35
+
36
+ opts = {}
37
+ Trollop::with_standard_exception_handling p do
38
+ opts = p.parse ARGV
39
+ raise Trollop::HelpNeeded if ARGV.size() > 1 # show help screen
40
+ end
41
+ currentDir = Dir.pwd
42
+
43
+ mappingsFile = Builddir.getMappingsFilePath()
44
+ buildBaseDir = Builddir.getBuildBasePath()
45
+ baseName = File.basename(currentDir)
46
+ baseName = File.basename(ARGV[0]) unless ARGV.empty?
47
+
48
+ if opts[:verbose]
49
+ puts "Current Directory : #{currentDir}"
50
+ puts "Build Base Directory: #{buildBaseDir}"
51
+ puts "Mappings File : #{mappingsFile}"
52
+ puts "Basename : #{baseName}"
53
+ puts ""
54
+ end
55
+
56
+ if opts[:build] && opts[:source]
57
+ puts "ERROR! Can not switch to source and build simultaneously."
58
+ exit -1
59
+ end
60
+
61
+ if (opts[:create] || opts[:build] || opts[:source]) && (opts[:delete] || opts[:remove])
62
+ puts "ERROR! This combination of options is not allowed!"
63
+ exit -1
64
+ end
65
+
66
+ mapping = Builddir.loadMapping(mappingsFile)
67
+ puts "WARNING! Mappings could not be loaded." if mapping == nil && opts[:verbose]
68
+ mapping ||= []
69
+
70
+ entry = Builddir.findMapping(mapping, currentDir)
71
+ if opts[:purge]
72
+ buildDirs = Dir[File.join(buildBaseDir, "*")].select{|file| File.directory?(file)}
73
+ buildDirs.each do |directory|
74
+ entry = Builddir.findMapping(mapping, directory)
75
+ if entry == nil
76
+ puts "Deleting: #{directory}"
77
+ FileUtils.rm_rf(directory)
78
+ end
79
+ end
80
+ exit 0
81
+ elsif entry == nil && !opts[:create]
82
+ puts "ERROR! No SrcDir <-> BuildDir mapping could be found."
83
+ exit -1
84
+ elsif opts[:delete] || opts[:remove]
85
+ puts "Removing mapping: #{entry[:srcDir]} <-> #{entry[:buildDir]}"
86
+ mapping.delete_at(entry[:index])
87
+ Builddir.saveMapping(mapping,mappingsFile)
88
+ if opts[:delete] && File.exists?(entry[:buildDir])
89
+ puts "Deleting build directory: #{entry[:buildDir]}"
90
+ FileUtils.rm_rf(entry[:buildDir])
91
+ end
92
+ exit 0
93
+ elsif entry == nil
94
+ buildDir = createBuildDirPath(buildBaseDir,baseName)
95
+ mapping << [ currentDir, buildDir ]
96
+ puts "New Mapping: #{currentDir} <-> #{buildDir}" if opts[:verbose]
97
+ entry = { :srcDir => currentDir, :buildDir => buildDir, :index => mapping.size-1, :type => :SRC_DIR }
98
+ Builddir.saveMapping(mapping,mappingsFile)
99
+ elsif opts[:verbose]
100
+ puts "Mapping Found: #{entry[:srcDir]} <-> #{entry[:buildDir]}"
101
+ end
102
+
103
+ # create the directory when needed
104
+ unless File.exists?(entry[:buildDir])
105
+ puts "Creating build directory" if opts[:verbose]
106
+ FileUtils.mkdir_p(entry[:buildDir])
107
+ end
108
+
109
+ dstDir = entry[:srcDir]
110
+ if opts[:build] || (!opts[:build] && !opts[:source] && entry[:type] == :SRC_DIR)
111
+ dstDir = entry[:buildDir]
112
+ end
113
+ puts "Change directory to: #{dstDir}" if opts[:verbose]
114
+ STDOUT.puts dstDir
115
+ exit 0
data/builddir.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'builddir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = Builddir::NAME
8
+ spec.version = Builddir::VERSION
9
+ spec.authors = ["Mario Werner"]
10
+ spec.email = ["mario.werner@iaik.tugraz.at"]
11
+ spec.summary = %q{builddir is a little helper tool for C/C++ programmers to manage out-of-source build directories.}
12
+ spec.description = %q{builddir manages mappings between build directories and the associated source directories.}
13
+ spec.homepage = "https://github.com/niosHD/builddir.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.bindir = "bin"
21
+
22
+ spec.post_install_message = "Thank you for installing builddir.\n\nPlease follow the remaining installation steps from the README (#{spec.homepage}) to finish the installation.\n\n"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_runtime_dependency "trollop", "~> 2.0"
27
+ end
@@ -0,0 +1,19 @@
1
+ #!/bin/bash
2
+
3
+ COMMAND="builddir_impl"
4
+
5
+ # Script from:
6
+ # http://stackoverflow.com/questions/11027679/bash-store-stdout-and-stderr-in-different-variables
7
+ unset t_std t_err t_ret
8
+ eval "$( $COMMAND $@ 2> >(t_err="$(cat)"; typeset -p t_err) > >(t_std="$(cat)"; typeset -p t_std); t_ret=$?; typeset -p t_ret )"
9
+
10
+ # print the stderr stream of the command
11
+ echo "${t_err}"
12
+
13
+ # change directory if there is no error
14
+ if [ $t_ret -eq 0 ]; then
15
+ cd "${t_std}"
16
+ fi
17
+
18
+ # set the retun code
19
+ (exit $t_ret)
@@ -0,0 +1,16 @@
1
+ require_relative 'version'
2
+
3
+ module Builddir
4
+
5
+ # Return the directory with the project libraries
6
+ # http://stackoverflow.com/a/5805783
7
+ #
8
+ # @return [String] path to the library directory
9
+ def Builddir.gem_libdir
10
+ t = ["#{File.dirname(File.expand_path($0))}/../lib/#{NAME}",
11
+ "#{Gem.dir}/gems/#{NAME}-#{VERSION}/lib/#{NAME}"]
12
+ t.each {|i| return i if File.readable?(i) }
13
+ raise "both paths are invalid: #{t}"
14
+ end
15
+
16
+ end
@@ -0,0 +1,4 @@
1
+ module Builddir
2
+ NAME = 'builddir'
3
+ VERSION = "0.1.0"
4
+ end
data/lib/builddir.rb ADDED
@@ -0,0 +1,74 @@
1
+ require "builddir/version"
2
+ require "builddir/utils"
3
+
4
+ require 'pathname'
5
+ require 'yaml'
6
+
7
+ module Builddir
8
+
9
+ # Loads the BuildDir <-> SourceDir mapping from the file
10
+ #
11
+ # @param file [String] path of the mapping file
12
+ # @return [nil, Array<Array(String, String)>] The loaded mapping. nil on error
13
+ def Builddir.loadMapping(file = nil)
14
+ file = getMappingsFilePath() if file.nil?
15
+ begin
16
+ mapping = YAML::load_file(file)
17
+ rescue
18
+ mapping = nil
19
+ end
20
+ return mapping
21
+ end
22
+
23
+ # Saves the BuildDir <-> SourceDir mapping to a file
24
+ #
25
+ # @param mapping [Array<Array(String, String)>] the mapping which should be saved
26
+ # @param file [String] path of the mapping file
27
+ def saveMapping(mapping, file)
28
+ File.open(file, 'w') do |f|
29
+ f.write mapping.to_yaml
30
+ end
31
+ end
32
+
33
+ # Searches through the mapping for a direct path match
34
+ #
35
+ # @param mapping [Array<Array(String, String)>] the mapping which should checked
36
+ # @param path [String] path of the searched directory
37
+ # @return [nil, { Symbol => String,Symbol}] the found mapping. nil on error
38
+ def Builddir.findExactMapping(mapping,path)
39
+ mapping.each_with_index do |entry,index|
40
+ if entry[0] == path
41
+ return { :srcDir => entry[0], :buildDir => entry[1], :index => index, :type => :SRC_DIR }
42
+ elsif entry[1] == path
43
+ return { :srcDir => entry[0], :buildDir => entry[1], :index => index, :type => :BUILD_DIR }
44
+ end
45
+ end
46
+ return nil
47
+ end
48
+
49
+ # Searches through the mapping for a path match.
50
+ # Parent directories are considered for the matching as well.
51
+ #
52
+ # @param mapping [Array<Array(String, String)>] the mapping which should checked
53
+ # @param path [String] path of the searched directory
54
+ # @return [nil, { Symbol => String,Symbol}] the found mapping. nil on error
55
+ def Builddir.findMapping(mapping,path)
56
+ lastpn = nil
57
+ pn = Pathname.new(path)
58
+ while pn != lastpn do
59
+ entry = findExactMapping(mapping,pn.to_s)
60
+ return entry if entry
61
+ lastpn = pn
62
+ pn = pn.parent()
63
+ end
64
+ return nil
65
+ end
66
+
67
+ def Builddir.getBuildBasePath()
68
+ return ENV['DEFAULT_BUILDDIR'] || "/tmp/builddir"
69
+ end
70
+
71
+ def Builddir.getMappingsFilePath()
72
+ return File.join(getBuildBasePath(),"builddir_mapping.yml")
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: builddir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mario Werner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: trollop
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ description: builddir manages mappings between build directories and the associated
63
+ source directories.
64
+ email:
65
+ - mario.werner@iaik.tugraz.at
66
+ executables:
67
+ - builddir_cmake
68
+ - builddir_configure
69
+ - builddir_generate_source_script
70
+ - builddir_impl
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - .gitignore
75
+ - CHANGELOG.md
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bin/builddir_cmake
81
+ - bin/builddir_configure
82
+ - bin/builddir_generate_source_script
83
+ - bin/builddir_impl
84
+ - builddir.gemspec
85
+ - lib/builddir.rb
86
+ - lib/builddir/data/builddir_source_script
87
+ - lib/builddir/utils.rb
88
+ - lib/builddir/version.rb
89
+ homepage: https://github.com/niosHD/builddir.git
90
+ licenses:
91
+ - MIT
92
+ post_install_message: ! 'Thank you for installing builddir.
93
+
94
+
95
+ Please follow the remaining installation steps from the README (https://github.com/niosHD/builddir.git)
96
+ to finish the installation.
97
+
98
+
99
+ '
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.23
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: builddir is a little helper tool for C/C++ programmers to manage out-of-source
121
+ build directories.
122
+ test_files: []