github.com/zhangbo2008/go_cherry_room@v0.0.0-20200225122943-fc7e48f14105/src/Forgefile.hsl (about) 1 # 2 # Copyright (C) 2015 by Rafael Santiago 3 # 4 # This is a free software. You can redistribute it and/or modify under 5 # the terms of the GNU General Public License version 2. 6 # 7 # 8 include ~/toolsets/go/go.hsl 9 10 var src type list; 11 var dep type string; 12 13 project cherry : toolset "go": dependencies $dep: $src; 14 15 function bincp() : result type int { 16 var oldcwd type string; 17 $oldcwd = hefesto.sys.pwd(); 18 hefesto.sys.cd(".."); 19 if (hefesto.sys.cd("bin") == 0) { 20 hefesto.sys.mkdir("bin"); 21 if (hefesto.sys.cd("bin") == 0) { 22 hefesto.sys.echo("ERROR: could not move to bin subdirectory."); 23 hefesto.sys.cd($oldcwd); 24 result 0; 25 } 26 } 27 var cp_res type int; 28 var appname type string; 29 var src_path type string; 30 $appname = "cherry"; 31 if (hefesto.sys.os_name() == "windows") { 32 $appname = $appname + ".exe"; 33 } 34 $src_path = hefesto.sys.make_path("../src", $appname); 35 $cp_res = hefesto.sys.cp($src_path, $appname); 36 hefesto.sys.rm($src_path); 37 hefesto.sys.cd($oldcwd); 38 result ($cp_res == 1); 39 } 40 41 function str_contains(haystack type string, needle type string) : result type int { 42 var n type int; 43 var REedle type string; 44 $n = 0; 45 while ($n < $needle.len()) { 46 if ($needle.at($n) == "\\" || $needle.at($n) == ".") { 47 $REedle = $REedle + "\\"; 48 } 49 $REedle = $REedle + $needle.at($n); 50 $n = $n + 1; 51 } 52 result ($haystack.match($REedle) > 0); 53 } 54 55 function setup_gopath() : result type none { 56 var gopath type string; 57 $gopath = hefesto.sys.env("GOPATH"); 58 var cherry_gopath_entry type string; 59 var old_cwd type string; 60 $old_cwd = hefesto.sys.pwd(); 61 hefesto.sys.cd(".."); 62 $cherry_gopath_entry = hefesto.sys.pwd(); 63 hefesto.sys.cd($old_cwd); 64 if (str_contains($gopath, $cherry_gopath_entry)) { 65 hefesto.sys.echo("INFO: Nice! GOPATH is configured :)\n"); 66 } else { 67 hefesto.sys.echo("WARN: GOPATH is not configured so I will do it for you on this build task. " + 68 "However, note that currently you are not able to run \"go build\" or \"go run\" commands " + 69 "by yourself for this project. In order to do this, please add \"" + $cherry_gopath_entry + "\" to your GOPATH.\n"); 70 if (hefesto.sys.os_name() != "windows") { 71 $gopath = $gopath + ":"; 72 } else { 73 $gopath = $gopath + ";"; 74 } 75 $gopath = $gopath + $cherry_gopath_entry; 76 hefesto.sys.setenv("GOPATH", $cherry_gopath_entry); 77 } 78 } 79 80 cherry.prologue() { 81 setup_gopath(); 82 $src.ls(".*\\.go$"); 83 } 84 85 cherry.epilogue() { 86 if (hefesto.sys.last_forge_result() == 0) { 87 if (bincp() == 0) { 88 hefesto.sys.echo("ERROR: could not transfer cherry binary to ../bin subdirectory.\n"); 89 hefesto.sys.exit(1); 90 } else { 91 hefesto.sys.echo("INFO: cherry binary is under ../bin subdirectory.\n"); 92 } 93 } 94 }