Leopold Schabel | 18b4d65 | 2020-12-14 18:27:07 +0100 | [diff] [blame^] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | // localconfig modifies the project's IntelliJ config to include project-specific settings. This is usually done by |
| 18 | // checking in the .idea directory, but we do not want to do this: it conflicts with the Bazel plugin's way of |
| 19 | // conducting its workspace business, lacks backwards compatibility, and is a common source of spurious Git diffs, |
| 20 | // especially when the IDE/JDK/random plugins are updated and team members run different versions. |
| 21 | // |
| 22 | // Instead, we use the officially supported way of shipping IntelliJ Bazel project configs - a .bazelproject file that |
| 23 | // can be imported using the Bazel project import wizard, with local configs. We then use this tool to mangle the local |
| 24 | // configs to add additional custom configuration beyond run configurations. This avoids merge conflicts and allows us |
| 25 | // to intelligently handle schema changes. |
| 26 | // |
| 27 | package main |
| 28 | |
| 29 | import ( |
| 30 | "log" |
| 31 | "os" |
| 32 | "path" |
| 33 | |
| 34 | "git.monogon.dev/source/nexantic.git/intellij/localconfig/watchers" |
| 35 | ) |
| 36 | |
| 37 | func main() { |
| 38 | if len(os.Args) != 2 { |
| 39 | log.Fatal("usage: localconfig <project dir>") |
| 40 | } |
| 41 | |
| 42 | projectDir := os.Args[1] |
| 43 | if _, err := os.Stat(path.Join(projectDir, ".ijwb")); err != nil { |
| 44 | log.Fatalf("invalid project dir: %v", err) |
| 45 | } |
| 46 | |
| 47 | if err := watchers.RewriteConfig(projectDir); err != nil { |
| 48 | log.Fatal(err) |
| 49 | } |
| 50 | } |