Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative paths if commandline is too long #249

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/arduino.cc/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ func ExecRecipe(properties properties.Map, recipe string, removeUnsetProperties
return bytes, i18n.WrapError(err)
}

const COMMANDLINE_LIMIT = 32000

func PrepareCommandForRecipe(buildProperties properties.Map, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
pattern := buildProperties[recipe]
if pattern == constants.EMPTY_STRING {
Expand All @@ -390,7 +392,13 @@ func PrepareCommandForRecipe(buildProperties properties.Map, recipe string, remo
}
}

command, err := utils.PrepareCommand(commandLine, logger)
relativePath := ""

if len(commandLine) > COMMANDLINE_LIMIT {
relativePath = buildProperties[constants.BUILD_PROPERTIES_BUILD_PATH]
}

command, err := utils.PrepareCommand(commandLine, logger, relativePath)
if err != nil {
return nil, i18n.WrapError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/ctags_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *CTagsRunner) Run(ctx *types.Context) error {
}

commandLine := properties.ExpandPropsInString(pattern)
command, err := utils.PrepareCommand(commandLine, logger)
command, err := utils.PrepareCommand(commandLine, logger, "")
if err != nil {
return i18n.WrapError(err)
}
Expand Down
25 changes: 21 additions & 4 deletions src/arduino.cc/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func TrimSpace(value string) string {

type argFilterFunc func(int, string, []string) bool

func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger) (*exec.Cmd, error) {
func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18n.Logger, relativePath string) (*exec.Cmd, error) {
parts, err := ParseCommandLine(pattern, logger)
if err != nil {
return nil, i18n.WrapError(err)
Expand All @@ -239,19 +239,36 @@ func PrepareCommandFilteredArgs(pattern string, filter argFilterFunc, logger i18
var args []string
for idx, part := range parts {
if filter(idx, part, parts) {
// if relativePath is specified, the overall commandline is too long for the platform
// try reducing the length by making the filenames relative
// and changing working directory to build.path
if relativePath != "" {
if _, err := os.Stat(part); !os.IsNotExist(err) {
tmp, err := filepath.Rel(relativePath, part)
if err == nil {
part = tmp
}
}
}
args = append(args, part)
}
}

return exec.Command(command, args...), nil
cmd := exec.Command(command, args...)

if relativePath != "" {
cmd.Dir = relativePath
}

return cmd, nil
}

func filterEmptyArg(_ int, arg string, _ []string) bool {
return arg != constants.EMPTY_STRING
}

func PrepareCommand(pattern string, logger i18n.Logger) (*exec.Cmd, error) {
return PrepareCommandFilteredArgs(pattern, filterEmptyArg, logger)
func PrepareCommand(pattern string, logger i18n.Logger, relativePath string) (*exec.Cmd, error) {
return PrepareCommandFilteredArgs(pattern, filterEmptyArg, logger, relativePath)
}

func MapHas(aMap map[string]interface{}, key string) bool {
Expand Down