Module: FalkorLib::Bootstrap::Link

Defined in:
lib/falkorlib/bootstrap/link.rb

Class Method Summary collapse

Class Method Details

.makefile(dir = Dir.pwd, options = {}) ⇒ Object

makefile ###### Create a symlink to the one of Falkor’s Makefile, typically bring as a Git submodule Supported options:

* :force    [boolean] force action
* :latex    [boolean] Makefile to compile LaTeX documents
* :gnuplot  [boolean] Makefile to compile GnuPlot scripts
* :markdown [boolean] Makefile to convert Markdown files to HTML
* :refdir   [string]  Path to Falkor's Makefile repository
* :src      [boolean] Path to latex_src


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/falkorlib/bootstrap/link.rb', line 32

def makefile(dir = Dir.pwd, options = {})
    path   = normalized_path(dir)
    rootdir = FalkorLib::Git.rootdir(path)
    info "Create a symlink to one of Falkor's Makefile"
    # Add Falkor's Makefiles
    submodules = FalkorLib.config[:git][:submodules]
    submodules['Makefiles'] = {
        :url   => 'https://github.com/Falkor/Makefiles.git',
        :branch => 'devel'
    } if submodules['Makefiles'].nil?
    FalkorLib::Git.submodule_init(rootdir, submodules)
    FalkorLib::Bootstrap::Link.root(dir)
    refdir = File.join(FalkorLib.config[:git][:submodulesdir], 'Makefiles')
    refdir = options[:refdir] unless options[:refdir].nil?
    dst        = File.join('.root', refdir)
    makefile_d = '.makefile.d'
    unless File.exists?(File.join(path, makefile_d))
        Dir.chdir( path ) do
            run %{ ln -s #{dst} #{makefile_d} }
            FalkorLib::Git.add(File.join(path, makefile_d), "Add symlink '#{makefile_d}' to Falkor's Makefile directory")
        end
    end
    #ap options
    makefile = 'Makefile'
    type     = 'latex'
    # recall to place the default option (--latex) at the last position
    [ :gnuplot, :images, :generic, :markdown] .each do |e|
        if options[e.to_sym]
            type = e.to_s
            break
        end
    end
    type = 'latex_src' if options[:src]
    makefile = 'Makefile.insubdir' if options[:generic]
    makefile = 'Makefile.to_html'  if options[:markdown]
    dst = File.join(makefile_d, type, makefile)
    unless File.exists?( File.join(path, 'Makefile'))
        info "Bootstrapping #{type.capitalize} Makefile (as symlink to Falkor's Makefile)"
        really_continue?
        Dir.chdir( path ) do
            run %{ ln -s #{dst} Makefile }
        end
        #ap File.join(path, 'Makefile')
        FalkorLib::Git.add(File.join(path, 'Makefile'), "Add symlink to the #{type.capitalize} Makefile")
    else
        puts "  ... Makefile already setup"
    end
end

.root(dir = Dir.pwd, options = {}) ⇒ Object

rootlink ###### Create a symlink ‘.root’ targeting the relative path to the git root directory Supported options:

* :name [string] name of the symlink ('.root' by default)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/falkorlib/bootstrap/link.rb', line 86

def root(dir = Dir.pwd, options = {})
    raise FalkorLib::ExecError "Not used in a Git repository" unless FalkorLib::Git.init?
    path  = normalized_path(dir)
    relative_path_to_root = (Pathname.new( FalkorLib::Git.rootdir(dir) ).relative_path_from Pathname.new( File.realpath(path)))
    if "#{relative_path_to_root}" == "."
        FalkorLib::Common.warning "Already at the root directory of the Git repository"
        FalkorLib::Common.really_continue?
    end
    target = options[:name] ? options[:name] : '.root'
    puts "Entering '#{relative_path_to_root}'"
    unless File.exists?( File.join(path, target))
        warning "creating the symboling link '#{target}' which points to '#{relative_path_to_root}'" if options[:verbose]
        # Format: ln_s(old, new, options = {}) -- Creates a symbolic link new which points to old.
        #FileUtils.ln_s "#{relative_path_to_root}", "#{target}"
        Dir.chdir( path ) do
            run %{ ln -s #{relative_path_to_root} #{target} }
        end
        FalkorLib::Git.add(File.join(path, target), "Add symlink to the root directory as .root")
    else
        puts "  ... the symbolic link '#{target}' already exists"
    end
end