Class: BConv::PathAdapt

Inherits:
Object
  • Object
show all
Defined in:
lib/PathAdapt.rb

Constant Summary collapse

SLASH =
"/"
COLON =
":"

Class Method Summary collapse

Class Method Details

.adapt_outputPath(bhash, outputFile) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/PathAdapt.rb', line 13

def self.adapt_outputPath(bhash,outputFile)
  bhash.each do |key,value|
    if key == "BAKE_PROJECTDIR"
      outputFile.gsub!("$$(BAKE_PROJECTDIR)",value[0])
    end
  end
  
  return outputFile
end

.adapt_path(outputFilePath, bhash, pwd, debugMode) ⇒ Object



23
24
25
26
27
28
29
30
31
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/PathAdapt.rb', line 23

def self.adapt_path(outputFilePath, bhash, pwd, debugMode)
  diffPathLevels, diffPathLevelsDown = 0, 0
  dir, diffUp = "", ""
  diffArr = []
  
  begin
  splitOutputFile = File.expand_path(File.dirname(outputFilePath),File.dirname(pwd)).split("/") 
  #splitOutputFile = File.expand_path(File.dirname(outputFilePath),pwd).split("/")
  splitProjMeta   = bhash['BAKE_PROJECTDIR'][0].split("/") if bhash['BAKE_PROJECTDIR'][0].include?("/") && bhash['BAKE_PROJECTDIR'] != nil
  #raise "Error: BAKE_PROJDIR is missing!" if bhash['BAKE_PROJECTDIR'] == nil
  
  if splitOutputFile.length > splitProjMeta.length
    diffPathLevels = splitOutputFile.length-splitProjMeta.length
    for j in (splitOutputFile.length-diffPathLevels)..(splitOutputFile.length-1)
      diffUp += splitOutputFile[j] + "/"
      diffArr << splitOutputFile[j]
    end
    for i in 0..diffPathLevels-1
      dir += "../"
    end
  elsif splitOutputFile.length < splitProjMeta.length
    diffPathLevelsDown = splitProjMeta.length-splitOutputFile.length
    puts "Warning: this case is not supported!"
    return nil
  else
    return bhash
  end
  
  pathNames = []
  directories = {}

  if File.dirname(outputFilePath).eql? File.dirname(bhash['BAKE_PROJECTDIR'][0])
    #files do not have to be adapted
  else
    bhash.each do |key, value|
      if key == 'BAKE_SOURCES' || key == 'BAKE_INCLUDES'
        value.each do |pathElm|
          if pathElm[0] == SLASH || pathElm[1] == COLON
            pathNames << pathElm #nothing to do - is already absolute
          elsif pathElm[0..diffUp.length-1].eql? diffUp
            pathNames << pathElm.split(/^#{diffUp}/)[-1]
          else 
            tmpElmArr = pathElm.split("/")
            cnt = 0
            dirLoc = ""
            if tmpElmArr[0] != ".." #string does not start with ".."
              for j in (0..diffArr.length-1)
                if diffArr[j] != tmpElmArr[j]
                  cnt = cnt + 1
                  dirLoc << "../"
                end
              end 
              tmpElm = Util.truncateStr(diffUp,pathElm)
              pathNames << (dirLoc + tmpElm)
            else #string starts with ".." -> don't have to cut
              pathNames << (dir + pathElm)
            end
          end
        end
        directories.store(key, pathNames)
        pathNames = []
      else
        directories.store(key, value)
      end
    end
  end
  rescue Exception => e
    puts e.message
    puts e.backtrace.inspect if debugMode == true
    exit(1)
  end
  return directories
end