Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
v0_9_0
-
None
-
Security Level: Public (Viewable by anyone)
-
None
-
Any
Description
I was just looking at the code that decides where gcc is run from (so I can see if I can make it always run from /workspace, so full paths are used), when I noticed you don't handle program arguments properly.
See this code
cmd += " -c " + "-o " + objPath + " " + file + " " + c.cflagsString() + " " + c.includesString()
Command line arguments should be stored as a []string instead of a space-delimited string. Then you don't need to worry about spaces or escaping or anything like that. In other words something like this:
func (c *Compiler) CompileFileCmd(file string, compilerType int) ([]string, error) { objFile := strings.TrimSuffix(file, filepath.Ext(file)) + ".o" objPath := filepath.ToSlash(c.dstDir + "/" + objFile) cmd := make([]string) switch compilerType { case COMPILER_TYPE_C: cmd = cmd.append(c.ccPath) case COMPILER_TYPE_ASM: cmd = cmd.append(c.asPath) default: return nil, util.NewNewtError("Unknown compiler type") } cmd = append(cmd, "-c", "-o", objPath, file) // There will be some special handling for these, depending on what they contain (I'm not sure of the format of these exactly). // c.cflagsString(), c.includesString() return cmd, nil }
And then don't use ShellCommand() to run it. Is there any reason that you're using sh -c rather than just running the command directly? It's going to make porting to Windows a pain. Similarly for code like this:
func CopyFile(srcFile string, destFile string) error { _, err := ShellCommand(fmt.Sprintf("mkdir -p %s", filepath.Dir(destFile))) if err != nil { return err } if _, err := ShellCommand(fmt.Sprintf("cp -Rf %s %s", srcFile, destFile)); err != nil { return err } return nil }
That won't work on Windows and also won't work with files containing spaces. Better to use Go's proper functions for creating directories and copying files. (Unfortunately there isn't a built-in equivalent of cp -Rf but if you google it there is lots of example code.)
Attachments
Issue Links
- mentioned in
-
Page Loading...