bake-toolkit 2.20.4 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile.rb +3 -3
  3. data/bin/bake +46 -46
  4. data/bin/bake-doc +11 -11
  5. data/bin/bakery +179 -179
  6. data/bin/createVSProjects +213 -213
  7. data/documentation/_build/html/_sources/changelog.txt +456 -451
  8. data/documentation/_build/html/_sources/commandline/commandline.txt +107 -107
  9. data/documentation/_build/html/_sources/concepts/build_hierarchy.txt +34 -34
  10. data/documentation/_build/html/_sources/concepts/concepts.txt +14 -14
  11. data/documentation/_build/html/_sources/concepts/inject.txt +65 -65
  12. data/documentation/_build/html/_sources/concepts/link_order.txt +91 -91
  13. data/documentation/_build/html/_sources/concepts/prebuild.txt +56 -56
  14. data/documentation/_build/html/_sources/concepts/the_main_project.txt +45 -45
  15. data/documentation/_build/html/_sources/concepts/the_project_meta_file.txt +72 -72
  16. data/documentation/_build/html/_sources/ide/eclipse/eclipse.txt +25 -25
  17. data/documentation/_build/html/_sources/ide/eclipse/how_to_convert_existing_cdt_workspace.txt +31 -31
  18. data/documentation/_build/html/_sources/ide/eclipse/how_to_create_a_new_project_in_eclipse.txt +18 -18
  19. data/documentation/_build/html/_sources/ide/eclipse/how_to_create_a_workspace_in_eclipse.txt +27 -27
  20. data/documentation/_build/html/_sources/ide/eclipse/how_to_debug_in_eclipse.txt +38 -38
  21. data/documentation/_build/html/_sources/ide/eclipse/how_to_install_eclipse_plugin.txt +44 -44
  22. data/documentation/_build/html/_sources/ide/eclipse/how_to_use_bake_in_eclipse.txt +86 -86
  23. data/documentation/_build/html/_sources/ide/ide_integrations.txt +8 -8
  24. data/documentation/_build/html/_sources/ide/vs/how_to_create_vs_projects.txt +15 -15
  25. data/documentation/_build/html/_sources/ide/vs/how_to_debug_in_vs.txt +35 -35
  26. data/documentation/_build/html/_sources/ide/vs/how_to_used_bake_in_vs.txt +35 -35
  27. data/documentation/_build/html/_sources/ide/vs/vs.txt +10 -10
  28. data/documentation/_build/html/_sources/ide/vs/vs_install.txt +43 -43
  29. data/documentation/_build/html/_sources/index.txt +33 -33
  30. data/documentation/_build/html/_sources/install/install_bake.txt +112 -112
  31. data/documentation/_build/html/_sources/internal.txt +50 -50
  32. data/documentation/_build/html/_sources/known_issues.txt +9 -9
  33. data/documentation/_build/html/_sources/license.txt +4 -4
  34. data/documentation/_build/html/_sources/performance/performance.txt +104 -104
  35. data/documentation/_build/html/_sources/quickstart/quickstart.txt +70 -70
  36. data/documentation/_build/html/_sources/syntax/adapt_configs.txt +143 -143
  37. data/documentation/_build/html/_sources/syntax/auto_adjustment.txt +43 -43
  38. data/documentation/_build/html/_sources/syntax/derive_configs.txt +93 -94
  39. data/documentation/_build/html/_sources/syntax/project_meta_syntax.txt +19 -19
  40. data/documentation/_build/html/_sources/syntax/syntax.txt +11 -11
  41. data/documentation/_build/html/_sources/syntax/variable_substitutions.txt +147 -147
  42. data/documentation/_build/html/_sources/tips_and_tricks/dot.txt +34 -34
  43. data/documentation/_build/html/_sources/tips_and_tricks/how_to_use_bake_with_cygwin.txt +62 -62
  44. data/documentation/_build/html/_sources/tips_and_tricks/static_code_analysis.txt +122 -122
  45. data/documentation/_build/html/_sources/tips_and_tricks/the_bakery.txt +72 -72
  46. data/documentation/_build/html/_sources/tips_and_tricks/the_clang.txt +43 -43
  47. data/documentation/_build/html/_sources/tips_and_tricks/tips_and_tricks.txt +34 -34
  48. data/documentation/_build/html/_sources/why_bake/why_bake.txt +40 -40
  49. data/documentation/_build/html/changelog.html +7 -0
  50. data/documentation/_build/html/commandline/commandline.html +2 -2
  51. data/documentation/_build/html/concepts/link_order.html +2 -2
  52. data/documentation/_build/html/concepts/prebuild.html +2 -2
  53. data/documentation/_build/html/index.html +4 -4
  54. data/documentation/_build/html/performance/performance.html +2 -2
  55. data/documentation/_build/html/searchindex.js +1 -1
  56. data/documentation/_build/html/syntax/adapt_configs.html +2 -2
  57. data/documentation/_build/html/syntax/syntax.html +2 -2
  58. data/documentation/_build/html/tips_and_tricks/the_clang.html +2 -2
  59. data/documentation/_build/html/why_bake/why_bake.html +2 -2
  60. data/lib/adapt/config/loader.rb +112 -112
  61. data/lib/bake/bundle.rb +158 -158
  62. data/lib/bake/cache.rb +179 -180
  63. data/lib/bake/config/checks.rb +68 -68
  64. data/lib/bake/config/loader.rb +363 -363
  65. data/lib/bake/libElement.rb +176 -176
  66. data/lib/bake/mergeConfig.rb +208 -208
  67. data/lib/bake/model/language.rb +45 -45
  68. data/lib/bake/model/loader.rb +99 -99
  69. data/lib/bake/model/metamodel.rb +307 -307
  70. data/lib/bake/model/metamodel_ext.rb +27 -27
  71. data/lib/bake/options/create.rb +95 -95
  72. data/lib/bake/options/options.rb +315 -310
  73. data/lib/bake/options/showDoc.rb +20 -20
  74. data/lib/bake/options/showLicense.rb +9 -9
  75. data/lib/bake/options/showToolchains.rb +38 -38
  76. data/lib/bake/options/usage.rb +79 -68
  77. data/lib/bake/subst.rb +313 -313
  78. data/lib/bake/toolchain/clang.rb +44 -44
  79. data/lib/bake/toolchain/clang_analyze.rb +31 -31
  80. data/lib/bake/toolchain/colorizing_formatter.rb +125 -125
  81. data/lib/bake/toolchain/diab.rb +53 -53
  82. data/lib/bake/toolchain/errorparser/diab_compiler_error_parser.rb +40 -40
  83. data/lib/bake/toolchain/errorparser/diab_linker_error_parser.rb +41 -41
  84. data/lib/bake/toolchain/errorparser/error_parser.rb +71 -71
  85. data/lib/bake/toolchain/errorparser/gcc_compiler_error_parser.rb +35 -35
  86. data/lib/bake/toolchain/errorparser/gcc_linker_error_parser.rb +35 -35
  87. data/lib/bake/toolchain/errorparser/greenhills_compiler_error_parser.rb +32 -32
  88. data/lib/bake/toolchain/errorparser/greenhills_linker_error_parser.rb +44 -44
  89. data/lib/bake/toolchain/errorparser/keil_compiler_error_parser.rb +40 -40
  90. data/lib/bake/toolchain/errorparser/keil_linker_error_parser.rb +30 -30
  91. data/lib/bake/toolchain/errorparser/lint_error_parser.rb +34 -34
  92. data/lib/bake/toolchain/errorparser/msvc_compiler_error_parser.rb +63 -63
  93. data/lib/bake/toolchain/errorparser/msvc_linker_error_parser.rb +42 -42
  94. data/lib/bake/toolchain/errorparser/process_output.rb +2 -2
  95. data/lib/bake/toolchain/errorparser/ti_compiler_error_parser.rb +30 -30
  96. data/lib/bake/toolchain/errorparser/ti_linker_error_parser.rb +30 -30
  97. data/lib/bake/toolchain/gcc.rb +49 -49
  98. data/lib/bake/toolchain/gcc_env.rb +55 -55
  99. data/lib/bake/toolchain/greenhills.rb +52 -52
  100. data/lib/bake/toolchain/keil.rb +53 -53
  101. data/lib/bake/toolchain/lint.rb +20 -20
  102. data/lib/bake/toolchain/msvc.rb +58 -58
  103. data/lib/bake/toolchain/provider.rb +146 -146
  104. data/lib/bake/toolchain/ti.rb +47 -47
  105. data/lib/bake/util.rb +149 -149
  106. data/lib/bakery/buildPattern.rb +24 -24
  107. data/lib/bakery/model/language.rb +22 -22
  108. data/lib/bakery/model/loader.rb +55 -55
  109. data/lib/bakery/model/metamodel.rb +48 -48
  110. data/lib/bakery/options/options.rb +87 -87
  111. data/lib/bakery/toBake.rb +81 -81
  112. data/lib/blocks/block.rb +324 -324
  113. data/lib/blocks/blockBase.rb +204 -204
  114. data/lib/blocks/commandLine.rb +38 -38
  115. data/lib/blocks/compile.rb +529 -528
  116. data/lib/blocks/convert.rb +41 -41
  117. data/lib/blocks/docu.rb +30 -30
  118. data/lib/blocks/executable.rb +174 -174
  119. data/lib/blocks/has_execute_command.rb +31 -31
  120. data/lib/blocks/library.rb +114 -114
  121. data/lib/blocks/lint.rb +56 -56
  122. data/lib/blocks/makefile.rb +100 -100
  123. data/lib/blocks/showIncludes.rb +140 -125
  124. data/lib/common/abortException.rb +4 -4
  125. data/lib/common/cleanup.rb +10 -10
  126. data/lib/common/exit_helper.rb +38 -38
  127. data/lib/common/ext/file.rb +88 -88
  128. data/lib/common/ext/rtext.rb +11 -11
  129. data/lib/common/ext/stdout.rb +45 -45
  130. data/lib/common/ide_interface.rb +194 -194
  131. data/lib/common/options/parser.rb +95 -85
  132. data/lib/common/process.rb +64 -64
  133. data/lib/common/utils.rb +52 -52
  134. data/lib/common/version.rb +31 -23
  135. data/lib/multithread/job.rb +44 -44
  136. data/lib/tocxx.rb +558 -555
  137. data/lib/vs/options.rb +69 -69
  138. data/license.txt +90 -90
  139. metadata +2 -2
@@ -1,125 +1,140 @@
1
- module Bake
2
- module Blocks
3
- class Show
4
-
5
- def self.secureShow
6
- begin
7
- yield
8
- rescue Exception => e
9
- if (not SystemExit === e)
10
- puts e
11
- puts e.backtrace
12
- ExitHelper.exit(1)
13
- else
14
- raise e
15
- end
16
- end
17
- end
18
-
19
- def self.includes
20
- secureShow {
21
- Blocks::ALL_COMPILE_BLOCKS.sort.each do |projName, blocks|
22
- print projName
23
- incs = []
24
- blocks.each do |block|
25
- if Bake.options.consoleOutput_fullnames
26
- incs += block.include_list.map { |i| File.expand_path(i, block.projectDir) }
27
- else
28
- incs += block.include_list
29
- end
30
- end
31
-
32
- incs.uniq.each { |inc| print "##{inc}" }
33
- print "\n"
34
- end
35
- ExitHelper.exit(0) }
36
- end
37
-
38
- def self.readInternalIncludes(mainConfig, mainBlock, mainTcs)
39
- intIncs = []
40
- iinc = mainConfig.defaultToolchain.internalIncludes
41
- Dir.chdir(Bake.options.main_dir) do
42
- if (iinc)
43
-
44
- cppExe = File.which(mainTcs[:COMPILER][:CPP][:COMMAND])
45
- cExe = File.which(mainTcs[:COMPILER][:C][:COMMAND])
46
- asmExe = File.which(mainTcs[:COMPILER][:ASM][:COMMAND])
47
- archiverExe = File.which(mainTcs[:ARCHIVER][:COMMAND])
48
- linkerExe = File.which(mainTcs[:LINKER][:COMMAND])
49
-
50
- iname = mainBlock.convPath(iinc)
51
- if iname != ""
52
- if not File.exists?(iname)
53
- Bake.formatter.printError("InternalIncludes file #{iname} does not exist", iinc)
54
- ExitHelper.exit(1)
55
- end
56
- IO.foreach(iname) do |x|
57
- x.sub!("$(CPPPath)", cppExe)
58
- x.sub!("$(CPath)", cExe)
59
- x.sub!("$(ASMPath)", asmExe)
60
- x.sub!("$(ArchiverPath)", archiverExe)
61
- x.sub!("$(LinkerPath)", linkerExe)
62
- add_line_if_no_comment(intIncs,x)
63
- end
64
- end
65
- end
66
- end
67
- return intIncs
68
- end
69
-
70
- def self.readInternalDefines(mainConfig, mainBlock)
71
- intDefs = {:CPP => [], :C => [], :ASM => []}
72
- Dir.chdir(Bake.options.main_dir) do
73
- mainConfig.defaultToolchain.compiler.each do |c|
74
- if (c.internalDefines)
75
- dname = mainBlock.convPath(c.internalDefines)
76
- if dname != ""
77
- if not File.exists?(dname)
78
- Bake.formatter.printError("InternalDefines file #{dname} does not exist", c.internalDefines)
79
- ExitHelper.exit(1)
80
- end
81
- IO.foreach(dname) {|x| add_line_if_no_comment(intDefs[c.ctype],x) }
82
- end
83
- end
84
- end
85
- end
86
- return intDefs
87
- end
88
-
89
- def self.includesAndDefines(mainConfig, mainTcs)
90
- secureShow {
91
- mainBlock = Blocks::ALL_BLOCKS[Bake.options.main_project_name+","+Bake.options.build_config]
92
-
93
- intIncs = readInternalIncludes(mainConfig, mainBlock, mainTcs)
94
- intDefs = readInternalDefines(mainConfig, mainBlock)
95
-
96
-
97
- Blocks::ALL_COMPILE_BLOCKS.sort.each do |projName, blocks|
98
-
99
- blockIncs = []
100
- blockDefs = {:CPP => [], :C => [], :ASM => []}
101
- blocks.each do |block|
102
- if Bake.options.consoleOutput_fullnames
103
- blockIncs += block.include_list.map { |i| File.expand_path(i, block.projectDir) }
104
- else
105
- blockIncs += block.include_list
106
- end
107
- [:CPP, :C, :ASM].each { |type| blockDefs[type] += block.tcs[:COMPILER][type][:DEFINES] }
108
- end
109
-
110
- puts projName
111
- puts " includes"
112
- (blockIncs + intIncs).uniq.each { |i| puts " #{i}" }
113
- [:CPP, :C, :ASM].each do |type|
114
- puts " #{type} defines"
115
- (blockDefs[type] + intDefs[type]).uniq.each { |d| puts " #{d}" }
116
- end
117
- puts " done"
118
-
119
- end
120
- ExitHelper.exit(0) }
121
- end
122
-
123
- end
124
- end
125
- end
1
+ module Bake
2
+ module Blocks
3
+ class Show
4
+
5
+ def self.secureShow
6
+ begin
7
+ yield
8
+ rescue Exception => e
9
+ if (not SystemExit === e)
10
+ puts e
11
+ puts e.backtrace
12
+ ExitHelper.exit(1)
13
+ else
14
+ raise e
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.includes
20
+ secureShow {
21
+ Blocks::ALL_COMPILE_BLOCKS.sort.each do |projName, blocks|
22
+ print projName
23
+ incs = []
24
+ blocks.each do |block|
25
+ if Bake.options.consoleOutput_fullnames
26
+ incs += block.include_list.map { |i| File.expand_path(i, block.projectDir) }
27
+ else
28
+ incs += block.include_list
29
+ end
30
+ end
31
+
32
+ incs.uniq.each { |inc| print "##{inc}" }
33
+ print "\n"
34
+ end
35
+ ExitHelper.exit(0) }
36
+ end
37
+
38
+ def self.readInternalIncludes(mainConfig, mainBlock, mainTcs)
39
+ intIncs = []
40
+ iinc = mainConfig.defaultToolchain.internalIncludes
41
+ Dir.chdir(Bake.options.main_dir) do
42
+ if (iinc)
43
+
44
+ cppExe = File.which(mainTcs[:COMPILER][:CPP][:COMMAND])
45
+ cExe = File.which(mainTcs[:COMPILER][:C][:COMMAND])
46
+ asmExe = File.which(mainTcs[:COMPILER][:ASM][:COMMAND])
47
+ archiverExe = File.which(mainTcs[:ARCHIVER][:COMMAND])
48
+ linkerExe = File.which(mainTcs[:LINKER][:COMMAND])
49
+
50
+ iname = mainBlock.convPath(iinc)
51
+ if iname != ""
52
+ if not File.exists?(iname)
53
+ Bake.formatter.printError("InternalIncludes file #{iname} does not exist", iinc)
54
+ ExitHelper.exit(1)
55
+ end
56
+ IO.foreach(iname) do |x|
57
+ x.sub!("$(CPPPath)", cppExe)
58
+ x.sub!("$(CPath)", cExe)
59
+ x.sub!("$(ASMPath)", asmExe)
60
+ x.sub!("$(ArchiverPath)", archiverExe)
61
+ x.sub!("$(LinkerPath)", linkerExe)
62
+ add_line_if_no_comment(intIncs,x)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ return intIncs
68
+ end
69
+
70
+ def self.readInternalDefines(mainConfig, mainBlock)
71
+ intDefs = {:CPP => [], :C => [], :ASM => []}
72
+ Dir.chdir(Bake.options.main_dir) do
73
+ mainConfig.defaultToolchain.compiler.each do |c|
74
+ if (c.internalDefines)
75
+ dname = mainBlock.convPath(c.internalDefines)
76
+ if dname != ""
77
+ if not File.exists?(dname)
78
+ Bake.formatter.printError("InternalDefines file #{dname} does not exist", c.internalDefines)
79
+ ExitHelper.exit(1)
80
+ end
81
+ IO.foreach(dname) {|x| add_line_if_no_comment(intDefs[c.ctype],x) }
82
+ end
83
+ end
84
+ end
85
+ end
86
+ return intDefs
87
+ end
88
+
89
+ def self.includesAndDefines(mainConfig, mainTcs)
90
+ json = true
91
+ secureShow {
92
+ mainBlock = Blocks::ALL_BLOCKS[Bake.options.main_project_name+","+Bake.options.build_config]
93
+
94
+ intIncs = readInternalIncludes(mainConfig, mainBlock, mainTcs)
95
+ intDefs = readInternalDefines(mainConfig, mainBlock)
96
+
97
+
98
+ projs = {}
99
+ Blocks::ALL_COMPILE_BLOCKS.sort.each do |projName, blocks|
100
+
101
+ blockIncs = []
102
+ blockDefs = {:CPP => [], :C => [], :ASM => []}
103
+ blocks.each do |block|
104
+ if Bake.options.consoleOutput_fullnames
105
+ blockIncs += block.include_list.map { |i| File.expand_path(i, block.projectDir) }
106
+ else
107
+ blockIncs += block.include_list
108
+ end
109
+ [:CPP, :C, :ASM].each { |type| blockDefs[type] += block.tcs[:COMPILER][type][:DEFINES] }
110
+ end
111
+ if Bake.options.json
112
+ projs[projName] =
113
+ { :includes => (blockIncs + intIncs).uniq,
114
+ :cpp_defines => (blockDefs[:CPP] + intDefs[:CPP]).uniq,
115
+ :c_defines => (blockDefs[:C] + intDefs[:C]).uniq,
116
+ :asm_defines => (blockDefs[:ASM] + intDefs[:ASM]).uniq
117
+ }
118
+ else
119
+ puts projName
120
+ puts " includes"
121
+ (blockIncs + intIncs).uniq.each { |i| puts " #{i}" }
122
+ [:CPP, :C, :ASM].each do |type|
123
+ puts " #{type} defines"
124
+ (blockDefs[type] + intDefs[type]).uniq.each { |d| puts " #{d}" }
125
+ end
126
+ puts " done"
127
+ end
128
+ end
129
+
130
+ if Bake.options.json
131
+ require "json"
132
+ puts JSON.pretty_generate(projs)
133
+ end
134
+
135
+ ExitHelper.exit(0) }
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -1,4 +1,4 @@
1
- module Bake
2
- class AbortException < StandardError
3
- end
4
- end
1
+ module Bake
2
+ class AbortException < StandardError
3
+ end
4
+ end
@@ -1,10 +1,10 @@
1
- module Bake
2
-
3
- def self.cleanup()
4
- Blocks::ALL_BLOCKS.clear
5
- Blocks::ALL_COMPILE_BLOCKS.clear
6
- Blocks::CC2J.clear
7
- Bake::IDEInterface.instance.set_abort(false)
8
- end
9
-
10
- end
1
+ module Bake
2
+
3
+ def self.cleanup()
4
+ Blocks::ALL_BLOCKS.clear
5
+ Blocks::ALL_COMPILE_BLOCKS.clear
6
+ Blocks::CC2J.clear
7
+ Bake::IDEInterface.instance.set_abort(false)
8
+ end
9
+
10
+ end
@@ -1,38 +1,38 @@
1
- module Bake
2
-
3
- class ExitHelper
4
- @@exit_code = 0
5
-
6
- def self.set_exit_code(val)
7
- @@exit_code = val
8
- end
9
-
10
- def self.exit_code()
11
- @@exit_code
12
- end
13
-
14
- def self.reset_exit_code()
15
- @@exit_code = 0
16
- end
17
-
18
- def self.exit(val)
19
- @@exit_code = val
20
- Kernel::exit
21
- end
22
-
23
- end
24
- end
25
-
26
- at_exit do
27
- if Bake::ExitHelper.exit_code != 0
28
- exit(Bake::ExitHelper.exit_code)
29
- elsif not $!.nil?
30
- if $!.respond_to?("success?")
31
- exit($!.success? ? 0 : 1)
32
- else
33
- exit(1)
34
- end
35
- else
36
- exit(0)
37
- end
38
- end
1
+ module Bake
2
+
3
+ class ExitHelper
4
+ @@exit_code = 0
5
+
6
+ def self.set_exit_code(val)
7
+ @@exit_code = val
8
+ end
9
+
10
+ def self.exit_code()
11
+ @@exit_code
12
+ end
13
+
14
+ def self.reset_exit_code()
15
+ @@exit_code = 0
16
+ end
17
+
18
+ def self.exit(val)
19
+ @@exit_code = val
20
+ Kernel::exit
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ at_exit do
27
+ if Bake::ExitHelper.exit_code != 0
28
+ exit(Bake::ExitHelper.exit_code)
29
+ elsif not $!.nil?
30
+ if $!.respond_to?("success?")
31
+ exit($!.success? ? 0 : 1)
32
+ else
33
+ exit(1)
34
+ end
35
+ else
36
+ exit(0)
37
+ end
38
+ end
@@ -1,88 +1,88 @@
1
- require 'common/utils'
2
-
3
- class File
4
-
5
- SLASH = '/'
6
-
7
- def self.is_absolute?(filename)
8
- filename[0] == SLASH or filename[1] == ':'
9
- end
10
-
11
- # seems both are rel or both are abs in all cases
12
- def self.rel_from_to_project(from,to,endWithSlash = true)
13
-
14
- return nil if from.nil? or to.nil?
15
-
16
- toSplitted = to.split('/')
17
- fromSplitted = from.split('/')
18
-
19
- max = [toSplitted.length, fromSplitted.length].min
20
-
21
-
22
- return nil if max < 1
23
-
24
- i = 0
25
-
26
- # path letter in windows may be case different
27
- toIsWindowsAbs = false
28
- if toSplitted[0].length > 1 and fromSplitted[0].length > 1
29
- toIsWindowsAbs = toSplitted[0][1] == ':'
30
- i = 1 if toIsWindowsAbs and fromSplitted[0][1] == ':' and toSplitted[0][0].downcase == fromSplitted[0][0].downcase
31
- end
32
-
33
- if (toIsWindowsAbs and i==0)
34
- res = to
35
- res += "/" if endWithSlash
36
- return res
37
- end
38
-
39
- while i < max
40
- break if toSplitted[i] != fromSplitted[i]
41
- i += 1
42
- end
43
- j = i
44
-
45
- res = []
46
- while i < fromSplitted.length
47
- res << ".."
48
- i += 1
49
- end
50
-
51
- while j < toSplitted.length
52
- res << toSplitted[j]
53
- j += 1
54
- end
55
-
56
- if res.length == 0
57
- return ""
58
- end
59
-
60
- res = res.join('/')
61
- res += "/" if endWithSlash
62
- res
63
- end
64
-
65
-
66
- def self.add_prefix(prefix, file)
67
- if not prefix or is_absolute?(file)
68
- file
69
- else
70
- prefix + file
71
- end
72
- end
73
-
74
- def self.which(cmd)
75
- return "" if not cmd
76
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
77
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
78
- exts.each { |ext|
79
- exe = File.join(path, "#{cmd}#{ext}")
80
- if File.executable?(exe) && !File.directory?(exe)
81
- return File.dirname(exe.gsub(/[\\]/,'/'))
82
- end
83
- }
84
- end
85
- return ""
86
- end
87
-
88
- end
1
+ require 'common/utils'
2
+
3
+ class File
4
+
5
+ SLASH = '/'
6
+
7
+ def self.is_absolute?(filename)
8
+ filename[0] == SLASH or filename[1] == ':'
9
+ end
10
+
11
+ # seems both are rel or both are abs in all cases
12
+ def self.rel_from_to_project(from,to,endWithSlash = true)
13
+
14
+ return nil if from.nil? or to.nil?
15
+
16
+ toSplitted = to.split('/')
17
+ fromSplitted = from.split('/')
18
+
19
+ max = [toSplitted.length, fromSplitted.length].min
20
+
21
+
22
+ return nil if max < 1
23
+
24
+ i = 0
25
+
26
+ # path letter in windows may be case different
27
+ toIsWindowsAbs = false
28
+ if toSplitted[0].length > 1 and fromSplitted[0].length > 1
29
+ toIsWindowsAbs = toSplitted[0][1] == ':'
30
+ i = 1 if toIsWindowsAbs and fromSplitted[0][1] == ':' and toSplitted[0][0].downcase == fromSplitted[0][0].downcase
31
+ end
32
+
33
+ if (toIsWindowsAbs and i==0)
34
+ res = to
35
+ res += "/" if endWithSlash
36
+ return res
37
+ end
38
+
39
+ while i < max
40
+ break if toSplitted[i] != fromSplitted[i]
41
+ i += 1
42
+ end
43
+ j = i
44
+
45
+ res = []
46
+ while i < fromSplitted.length
47
+ res << ".."
48
+ i += 1
49
+ end
50
+
51
+ while j < toSplitted.length
52
+ res << toSplitted[j]
53
+ j += 1
54
+ end
55
+
56
+ if res.length == 0
57
+ return ""
58
+ end
59
+
60
+ res = res.join('/')
61
+ res += "/" if endWithSlash
62
+ res
63
+ end
64
+
65
+
66
+ def self.add_prefix(prefix, file)
67
+ if not prefix or is_absolute?(file)
68
+ file
69
+ else
70
+ prefix + file
71
+ end
72
+ end
73
+
74
+ def self.which(cmd)
75
+ return "" if not cmd
76
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
77
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
78
+ exts.each { |ext|
79
+ exe = File.join(path, "#{cmd}#{ext}")
80
+ if File.executable?(exe) && !File.directory?(exe)
81
+ return File.dirname(exe.gsub(/[\\]/,'/'))
82
+ end
83
+ }
84
+ end
85
+ return ""
86
+ end
87
+
88
+ end