Browse Source

fix: Pack can now run under Windows / adjusted example scripts

Matthias Ladkau 3 years ago
parent
commit
6f243399ea
5 changed files with 18 additions and 5 deletions
  1. 2 1
      .gitignore
  2. 7 4
      cli/tool/pack.go
  3. 5 0
      examples/fib/pack.bat
  4. 2 0
      examples/fib/run.bat
  5. 2 0
      examples/game_of_life/run.bat

+ 2 - 1
.gitignore

@@ -1,4 +1,5 @@
-ecal
+/ecal
+/ecal.exe
 /.cache
 /.cover
 /.ecal_console_history

+ 7 - 4
cli/tool/pack.go

@@ -17,6 +17,7 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
+	"path"
 	"path/filepath"
 	"strings"
 	"unicode"
@@ -175,18 +176,20 @@ func (p *CLIPacker) packFiles(w *zip.Writer, filePath string, zipPath string) er
 		for _, file := range files {
 			if !file.IsDir() {
 				var data []byte
-				if data, err = ioutil.ReadFile(filepath.Join(filePath, file.Name())); err == nil {
+				diskfile := filepath.Join(filePath, file.Name())
+				if data, err = ioutil.ReadFile(diskfile); err == nil {
 					var f io.Writer
-					if f, err = w.Create(filepath.Join(zipPath, file.Name())); err == nil {
+					if f, err = w.Create(path.Join(zipPath, file.Name())); err == nil {
 						if bytes, err = f.Write(data); err == nil {
 							fmt.Fprintln(p.LogOut, fmt.Sprintf("Writing %v bytes for %v",
-								bytes, filepath.Join(filePath, file.Name())))
+								bytes, diskfile))
 						}
 					}
 				}
 			} else if file.IsDir() {
+				// Path separator in zipfile is always '/'
 				p.packFiles(w, filepath.Join(filePath, file.Name()),
-					filepath.Join(zipPath, file.Name()))
+					path.Join(zipPath, file.Name()))
 			}
 		}
 	}

+ 5 - 0
examples/fib/pack.bat

@@ -0,0 +1,5 @@
+@echo off
+mkdir pack
+copy fib.ecal pack
+robocopy lib pack\lib
+..\..\ecal.exe pack -dir pack -target out.exe fib.ecal

+ 2 - 0
examples/fib/run.bat

@@ -0,0 +1,2 @@
+@echo off
+..\..\ecal.exe run fib.ecal

+ 2 - 0
examples/game_of_life/run.bat

@@ -0,0 +1,2 @@
+#!/bin/sh
+..\..\ecal.exe run game_of_life.ecal