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 | |
Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame^] | 17 | // localconfig modifies the project's IntelliJ config to include project-specific |
| 18 | // settings. This is usually done by checking in the .idea directory, but we do not |
| 19 | // want to do this: it conflicts with the Bazel plugin's way of conducting its |
| 20 | // workspace business, lacks backwards compatibility, and is a common source of |
| 21 | // spurious Git diffs, especially when the IDE/JDK/random plugins are updated and |
| 22 | // team members run different versions. |
Leopold Schabel | 18b4d65 | 2020-12-14 18:27:07 +0100 | [diff] [blame] | 23 | // |
Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame^] | 24 | // Instead, we use the officially supported way of shipping IntelliJ Bazel project |
| 25 | // configs - a .bazelproject file that can be imported using the Bazel project |
| 26 | // import wizard, with local configs. We then use this tool to mangle the local |
| 27 | // configs to add additional custom configuration beyond run configurations. This |
| 28 | // avoids merge conflicts and allows us to intelligently handle schema changes. |
Leopold Schabel | 18b4d65 | 2020-12-14 18:27:07 +0100 | [diff] [blame] | 29 | package main |
| 30 | |
| 31 | import ( |
| 32 | "log" |
| 33 | "os" |
| 34 | "path" |
| 35 | |
Serge Bazanski | 31370b0 | 2021-01-07 16:31:14 +0100 | [diff] [blame] | 36 | "source.monogon.dev/intellij/localconfig/watchers" |
Leopold Schabel | 18b4d65 | 2020-12-14 18:27:07 +0100 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | func main() { |
| 40 | if len(os.Args) != 2 { |
| 41 | log.Fatal("usage: localconfig <project dir>") |
| 42 | } |
| 43 | |
| 44 | projectDir := os.Args[1] |
| 45 | if _, err := os.Stat(path.Join(projectDir, ".ijwb")); err != nil { |
| 46 | log.Fatalf("invalid project dir: %v", err) |
| 47 | } |
| 48 | |
| 49 | if err := watchers.RewriteConfig(projectDir); err != nil { |
| 50 | log.Fatal(err) |
| 51 | } |
| 52 | } |