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

Forward preprocessor definitions to the remote compiler. #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions cmd/llamacc/arg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ func TestParseCompile(t *testing.T) {
PreprocessedLanguage: "cpp-output",
Input: "platform/linux/linux_ptrace.c",
Output: "platform/linux/linux_ptrace.o",
UnknownArgs: []string{"-Wall", "-Werror", "-g"},
LocalArgs: []string{"-MD", "-Wall", "-Werror", "-D_GNU_SOURCE", "-g", "-MF", "platform/linux/linux_ptrace.d"},
RemoteArgs: []string{"-Wall", "-Werror", "-g", "-c"},
RemoteArgs: []string{"-Wall", "-Werror", "-D_GNU_SOURCE", "-g", "-c"},
Flag: Flags{
MD: true,
C: true,
Expand Down Expand Up @@ -89,9 +88,8 @@ func TestParseCompile(t *testing.T) {
PreprocessedLanguage: "assembler",
Input: "/home/nelhage/code/boringssl/build/crypto/chacha/chacha-x86_64.S",
Output: "CMakeFiles/crypto.dir/chacha/chacha-x86_64.S.o",
UnknownArgs: []string{"-Wa,--noexecstack", "-Wa,-g"},
LocalArgs: []string{"-DBORINGSSL_DISPATCH_TEST", "-DBORINGSSL_HAVE_LIBUNWIND", "-DBORINGSSL_IMPLEMENTATION", "-I/home/nelhage/code/boringssl/third_party/googletest/include", "-I/home/nelhage/code/boringssl/crypto/../include", "-Wa,--noexecstack", "-Wa,-g"},
RemoteArgs: []string{"-Wa,--noexecstack", "-Wa,-g", "-c"},
RemoteArgs: []string{"-DBORINGSSL_DISPATCH_TEST", "-DBORINGSSL_HAVE_LIBUNWIND", "-DBORINGSSL_IMPLEMENTATION", "-Wa,--noexecstack", "-Wa,-g", "-c"},
Flag: Flags{
C: true,
},
Expand Down
15 changes: 9 additions & 6 deletions cmd/llamacc/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type Compilation struct {
PreprocessedLanguage string
Input string
Output string
UnknownArgs []string
LocalArgs []string
RemoteArgs []string
Flag Flags
Expand Down Expand Up @@ -117,7 +116,11 @@ func smellsLikeInput(arg string) bool {
type filterWhere int

const (
filterLocal = 1 << 0
// filterLocal means that we should filter this argument out of
// local compilations.
filterLocal = 1 << 0
// filterRemote means that we should filter this argument out of
// remote compilations.
filterRemote = 1 << 1
filterBoth = filterLocal | filterRemote
)
Expand Down Expand Up @@ -167,11 +170,11 @@ var argSpecs = []argSpec{
}, false},
{"-D", func(c *Compilation, arg string) (filterWhere, error) {
c.Defs = append(c.Defs, Def{"-D", arg})
return filterRemote, nil
return 0, nil
}, true},
{"-U", func(c *Compilation, arg string) (filterWhere, error) {
c.Defs = append(c.Defs, Def{"-U", arg})
return filterRemote, nil
return 0, nil
}, true},
{"-c", func(c *Compilation, arg string) (filterWhere, error) {
c.Flag.C = true
Expand Down Expand Up @@ -311,7 +314,8 @@ func ParseCompile(cfg *Config, argv []string) (Compilation, error) {
break
}
if !found {
out.UnknownArgs = append(out.UnknownArgs, arg)
// Preserve any arguments that don't have a
// matching spec.
out.LocalArgs = append(out.LocalArgs, arg)
out.RemoteArgs = append(out.RemoteArgs, arg)
}
Expand All @@ -321,7 +325,6 @@ func ParseCompile(cfg *Config, argv []string) (Compilation, error) {
}
out.Input = arg
} else {
out.UnknownArgs = append(out.UnknownArgs, arg)
out.LocalArgs = append(out.LocalArgs, arg)
out.RemoteArgs = append(out.RemoteArgs, arg)
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/llamacc/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ func detectDependencies(ctx context.Context, client *daemon.Client, cfg *Config,
}
preprocessor.Path = ccpath
preprocessor.Args = []string{comp.LocalCompiler(cfg)}
preprocessor.Args = append(preprocessor.Args, comp.UnknownArgs...)
for _, opt := range comp.Defs {
preprocessor.Args = append(preprocessor.Args, opt.Opt)
preprocessor.Args = append(preprocessor.Args, opt.Def)
}
preprocessor.Args = append(preprocessor.Args, comp.LocalArgs...)
for _, opt := range comp.Includes {
preprocessor.Args = append(preprocessor.Args, opt.Opt)
preprocessor.Args = append(preprocessor.Args, opt.Path)
Expand Down
6 changes: 2 additions & 4 deletions cmd/llamacc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ func constructRemotePreprocessInvoke(ctx context.Context, client *daemon.Client,
}

args.Args = []string{comp.RemoteCompiler(cfg)}
args.Args = append(args.Args, comp.RemoteArgs...)

args.Args = append(args.Args, "-I", toRemote(".", wd))
for _, inc := range comp.Includes {
args.Args = append(args.Args, inc.Opt, toRemote(inc.Path, wd))
}
for _, def := range comp.Defs {
args.Args = append(args.Args, def.Opt, def.Def)
}

args.Args = append(args.Args, "-c")
args.Args = append(args.Args, "-o", toRemote(comp.Output, wd))
args.Args = append(args.Args, toRemote(comp.Input, wd))
Expand All @@ -171,7 +170,6 @@ func constructRemotePreprocessInvoke(ctx context.Context, client *daemon.Client,
if comp.Flag.MF != "" {
args.Args = append(args.Args, "-MF", toRemote(comp.Flag.MF+".tmp", wd))
}
args.Args = append(args.Args, comp.UnknownArgs...)
if cfg.Verbose {
log.Printf("[llamacc] compiling remotely: %#v", args)
}
Expand Down